DSA Project
DSA Project
DSA Project:
Queue & Algorithms
Done By Sara S. Ali, Karar Abood,
And Zubaida Manhal
Supervised By Dr. Dunia H. Hameed
—-----------------------------------------------------------
1
Introduction to Queues
2
Table of Contents
Introduction to Queues
1. Algorithm “Insert”
1. Pseudocode
2. Python Implementation
2. Algorithm “Delete”
1. Pseudocode
2. Python Implementation
3. Algorithm “Display”
1. Pseudocode
2. Python Implementation
4. Algorithm “Counting Even Numbers”
1. Pseudocode
2. Python Implementation
5. Algorithm “Finding Negative Values”
2. Pseudocode
2. Python Implementation
3
1. Algorithm “Insert”
1. Pseudocode
[Given Queue (Q) of size (N), Rear (R) and Front (F) are two
pointers variables. This algorithm is to insert a new value
(X) to the queue]
I. [Check overflow] If (R >= N) print "overflow message",
exit.
II. [Increment R] R ← R+1.
III. [insert a new value] Q[R] ← X.
IV. [Check Front] If (F=0) Set F←1.
V. [Finished] exit.
2. Python Implementation
4
2. Algorithm “Delete”
1. Pseudocode
[Given Queue (Q) of size (N), Rear (R) and Front (F) are two
pointers variables. This
algorithm is to delete an element from the queue and store
it in a variable called (T)]
I. [Check underflow]
If (F<= 0) print "underflow message", return.
II. [Delete element]
T ← Q[F].
III. [Is Queue Empty?]
if (R=F) Set R=F=0.
else F←F+1.
IV. [Finished] return T.
2. Python Implementation
5
3. Algorithm “Display”
1. Pseudocode
I. [Check if the Queue is Empty]
If F >= R, print "Queue is empty", return.
II. [Display the Elements]
For i ← F to R-1 do:
print Q[i]
III. [Finished]
2. Python Implementation
6
4. Algorithm “Counting Even Numbers”
1. Pseudocode
I. [Initialize E]
E ← 0
II. [check underflow]
If F<=0 print underflow message and exit
III. If Q[F]%2==0 set E ← E+1
F ← F+1
else
F ← F+1
IV. Is Queue Empty?
If R=F
set R=F=0 and return E
else Repeat Step 2
V. [Finished] Return E
7
2. Python Implementation
8
5. Algorithm “Finding Negative Values”
2. Pseudocode
9
2. Python Implementation
10