Stacks and Queues Flashcards

NO PRIORITY

You may prefer our related Brainscape-certified flashcards:
1
Q

Stack

A

Description: A stack is a Last-In-First-Out (LIFO) data structure, where the last element added is the first one to be removed. Think of it like a stack of plates where you can only remove the top plate.

Implementation: In C#, you can implement a stack using the Stack<T> class in the System.Collections.Generic namespace. It supports operations like Push (adds an item), Pop (removes and returns the top item), Peek (returns the top item without removing it), and Count (returns the number of elements).</T>

Applications:

Expression evaluation: Used in evaluating expressions involving parentheses, like checking if parentheses are balanced.
Function call management: Stacks are used to manage function calls in most programming languages (the call stack).
Undo mechanisms: Commonly used in applications to implement undo functionality.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Queue

A

Description:

A queue is a First-In-First-Out (FIFO) data structure, where the first element added is the first one to be removed. Imagine it like a line in a cafeteria where the first person in line gets served first.

Implementation:

In C#, you can use the Queue<T> class from the System.Collections.Generic namespace. It supports operations like Enqueue (adds an item to the end of the queue), Dequeue (removes and returns the item at the beginning of the queue), Peek (returns the item at the beginning without removing it), and Count (returns the number of elements).</T>

Applications:

Breadth-First Search (BFS): Used in graph traversal algorithms where nodes are processed in layers or levels.
Job scheduling: Queues are used to manage tasks or jobs that need to be processed in the order they were received.
Buffering: Queues are also used in buffering scenarios where data or requests are queued up and processed sequentially.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly