Algorithm Insertion and Deletion in a Queue (using pointers) Assignment Help

Assignment Help: >> Queues >> Algorithm Insertion and Deletion in a Queue (using pointers)

Algorithm insertion and deletion in a queue (using pointers)

                Implementing queue (and stacks) using pointers the disadvantage is that a node in a linked representation (using pointers) occupies more memory space then a corresponding element in the array representation since there are at least two field in each node one the data field and the other to store the address of nest node. Whereas in a linked representation only data field is there. But note that the memory space occupied by a node in linked representation is not exactly twice the space used by a element of array representation. Moreover a linked representation makes an effective utilization of memory. Another advantage of linked representation becomes apparent when it is needed to insert or delete an element in the middle of a group of other elements. Suppose we wish to insert an element between the second and third element in the array a of size 10 which already contains eight elements (a [0] to a [7]). This require us to shift one place, all the elements from third onwards a (a[2] to a [7]) so that a solt should be made empty to insert new element. It means we have to shift five elements if the array is of large size say 1000 or 2000 element, it would be equivalent of doing a bulk of work and gaining no special results. Similarly when an in between element is deleted it requires all the element beyond the deleted element to be shifted so as the fill the gap created by deletion of element. On the other hand linked representation allows us to stress on our primary aim (.e. addition or deletion) and not on the overheads related to these processes. In other words the amount of work required is independent of the size of the list.

            Addition of a new node in between a queue in a linked representation requires creating a new node inserting it in the require position by adjusting two pointers. Whereas to delete a node from the queue all we require is to adjust pointers to point the node to be deleted, and then free that node, an individual node and queue in linked representation is shown in the figure.

2451_Inseration-Deletion-In-Queue - Pointer.png

Algorithm for adding a node in a queue     

         Let Queue be a structure whose declaration looks like follows:

         Struct queue_node

         {

         Int no;

         Queue_node *next;

         } * start = null

Then the algorithms for addition and deletion will look like.

Data Structure & Algorithms Assignment Help, Live Experts 

Struggling with data structure problems? Data structure subject is quite tough to learn? Need quick assistance in data structure questions? ExpertsMind.com is right place for you where your search ends, We at ExpertsMind offer online data structure assignment help, data structure homework help and data structure and algorithms question's answers by best online support by qualified tutors.

ExpertsMind.com - Insertion and Deletion Assignment Help, Insertion and Deletion Homework Help, Insertion and Deletion Assignment Tutors, Insertion and Deletion Solutions, Insertion and Deletion Answers, Queues Assignment Tutors

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd