

Heap is a nonlinear data structure which means it hierarchically arranges data. It can be implemented using an array or better, linked list. When data is inserted into a queue it is called enqueue and when data is deleted from the queue it is called dequeue.Ī queue can be used to implement cache, breadth-first search, or first come first serve (FCFS) algorithms. Thus one must use a queue when you want to get things out in the order that you put them in. An example of this is when we stand in line for getting a bus ticket here, the person who first enters the line is the first to leave the queue as well. This means they follow the first in first out principle (FIFO). The items in a queue are removed from the list in the same order in which they were added to it. The queue is an abstract data type that is a simple data structure which uses pointers to represent dynamic sets.


Since the number of operations on a stack are limited it is considered to be a restricted data structure.Ī stack can easily be implemented by an array or using a linked list. PUSH operations are often used to add items to a stack while the delete operation is understood as POP.Īlong with these we can also use peek (to return the item at the top of the stack) and isEmpty (to check whether the stack contains items). There are two basic operations performed on a stack i.e. Various functions, parsers, expression evaluations, recursive algorithms, or backtracking algorithms can be executed using this data structure. The lowest elements or the elements inserted at the very first are in the stack the longest. Thus one must use a stack when you want to get things out in the reverse order than you put them in. Only one end of the stack is accessible to us to perform operations on(ie. This means it follows the last in first out principle (LIFO). The last book we put on the top is the one that is the first to be removed from the stack. To explain in a simple way this data structure works like stacking books one on top of the other. Useful for heapsort (best performance), selection algorithmsĪ stack is a linear, dynamic data set which limits data in the way that it can only be added to or removed from the top. There is wastage of memory space as two-pointer is used No wastage of memory space as only one pointer is used Memory is allocated in a continuous, sequential manner We maintain two pointers to access the list Insert operation is called enqueue operation.ĭelete operation is called pop operation.ĭelete operation is called dequeue operation. Insert operation is called push operation. Insertion and deletion in queues takes place from the opposite ends of the listīinary tree structure where nodes are compared during insertion and deletion

Insertion and deletion takes place from one end It is important to understand their properties and how they differ from each other so as to be able to implement them appropriately.ĭifference between Stack and Queue and Heap Stack Stack and Queue both allow us to linearly, dynamically store and retrieve data items in two very alternative ways while heap allows us to manage data hierarchically. They are the oldest data structures introduced in our computer and are both commonly used. The data structures commonly used are Stack, Queue and Heap. From storing possible moves in a game to storing our usual burger choices at the cafe, data structures are needed everywhere. Wise choices of data structures lead to better performance of computer programs.ĭata structures are used every day and everywhere by us. They are used by programmers to solve an algorithm in an orderly and effective method. Data structure helps in understanding the nature of the problem at a deeper level and thus providing a better understanding.
