17 05 2024 DSA With Python For Student
17 05 2024 DSA With Python For Student
Python
(DSA - Data Structure and
Algoithms)
CSD203
Stacks
A stack is a data structure that can hold many
elements.
Think of a stack like a pile of pancakes.
In a pile of pancakes, the pancakes are both added and removed from
the top. So when removing a pancake, it will always be the last pancake
you added. This way of organizing elements is called LIFO: Last In First
Out.
push: Adds a pop: Removes peek: Returns the isEmpty: Checks size: Finds the
new element on and returns the top element on if the stack is number of
the stack. top element from the stack. empty. elements in the
the stack. stack.
enqueue: Adds a dequeue Remov peek: Returns the isEmpty: Checks size: Finds the
new element to es and the first first element in if the queue is number of
the queue. (front) element the queue. empty. elements in the
from the queue. queue.
- Queues can be used to implement job scheduling for an office printer, order processing for e-tickets, or to create algorithms for
breadth-first search in graphs.
- Queues are often mentioned together with Stacks.
Queue
Implementatio
n using Arrays
OUTPU
T
Queue
Implementation using
Arrays - Create a queue
class
Queue
Implementatio
n using Linked
Lists
- Create a
queue class
Deque
A deque is a data structure that can hold many
elements.
Deque or Double Ended
Queue is a type of queue in
which insertion and removal
of elements can either be
performed from the front or
the rear. Thus, it does not
follow FIFO rule (First In First
Out).
1 2 3 4 5 6
Basic operations we can do
on a stack are:
addFront: add addRear: adds removeFront: removeRear: isEmpty: Che Size: Find the
s an element an element to deletes an deletes an cks if the number of
at the front. the rear. element from element from deque is elements in
the front. the rear. empty. the deque.
OUTPU
T
Priority Queue Implementation using Linked
List
Priority Queue Implementation using Linked
List
Priority Queue Implementation using Linked
List
OUTPU
T