Stack, Queue and Heaps Part - 1


Posted August 17, 2019 by outsources

outsource ecommerce software, outsource nodejs developer, outsource, outsource your project, outsource ruby developer

 
Stacks are dynamic data structures that follow the Last Out (LIFO) principle. The last item to be inserted a stack is the first one to be deleted from it.
For example, you have a stack of trays on a table. The tray at the top of the stack is the first item to be moved if you require a tray from that stack.
Inserting and deleting elements
have restrictions on the insertion and deletion of elements. Elements can be inserted or deleted only from one end of the stack i.e. the top. The element at the top is called the top element. The operations of inserting and deleting elements are called push) and pop) respectively.
When the top element of a stack is deleted, if the stack remains non-empty, then the element just below the previous top element becomes the new top element of the stack.
For example, in the stack of trays, if you take the tray on the top and do not replace it, then the second tray automatically becomes the top element (tray) of that stack.
Queue
Queues are data structures that follow the First In First Out (FIFO) i.e. first element that is added to the queue is the first one to be removed.
Elements are always added to the back and removed from the front. Think of it as a line of people waiting for a bus. The person who is at the beginning of the line is the first one to enter the bus.
Variables used
• : Array in which queue is simulated
• : Maximum number of elements that can be stored in a queue]
• : Points at the index where the next deletion will be performed
• : Points at the index where the next insertion will be performed
Functions supported
Queues support the following fundamental functions:
Enqueue
function adds an element to the back of the queue.
Dequeue
function removes the element from the front of the queue.
Heaps
is a special case of balanced binary tree data structure where the root-node key is compared with its children and arranged accordingly. If α has child node β then −
key(α) ≥ key(β)
As the value of parent is greater than that of , this property generates Max Heap. Based on this criteria, a heap can be of two types −
For Input → 35 33 42 10 14 19 27 44 26 31
Hash Table:
Hash Table is a data structure which stores data in an associative manner. In a hash table, data is stored in an array format, where each data value has its own unique index value. Access of data becomes very fast if we know the index of the desired data.
Thus, it becomes a data structure in which insertion and search operations are very fast irrespective of the size of the data. Hash Table uses an array as a storage medium and uses to generate an index where an element is to be inserted or is to be located from.
Hashing is a technique to convert a range of key values into a range of indexes of an array. We’re going to use to get a range of key values. Consider an example of of size 20, and the following items are to be stored. Item in the (keyvalue) format.
For more details on our products and services, please feel free to visit us at outsource ecommerce software, outsource nodejs developer, outsource, outsource your project, outsource ruby developer
-- END ---
Share Facebook Twitter
Print Friendly and PDF DisclaimerReport Abuse
Contact Email [email protected]
Issued By outsource
Country United States
Categories Business
Last Updated August 17, 2019