In: Computer Science
Q1
A- What are stack and queue? What are the differences between stack and queue?
B- What is the priority queue? What are the differences between queue and priority queue
(A)
Stack is a linear data structure which follows LIFO (Last In First Out) order.
Queue is a linear data structure which follows FIFO( First In First Out) order.
Differences between Stack and Queue are,
Insertion and Removal of elements takes place only one end in stack whereas, Insertion takes place from back and removal from front of the queue.
Inserting of new elements into stack is called push and Removal of elements is called pop,where as in queue insertion is called enqueue and deletion is called dequeue.
Generally in recursive problems we use stacks and for sequential ordering problems where order is important we use queues.
(B)
Priority queue is a data structure where each element is given some priority and during dequeue elements are removed in the highest priority first when there is a tie we follow FIFO order.
Difference between Queue and Priority Queue,
In Queue insertion happens at one end and deletion on the other whereas, in priority queue there are no ends like that here insertion happens in any order but removal depends on priority.
In Queue elements doesn't have any priority value associated with it but in Priority Queue each element is associated with priority.