



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Prof. Chandrashekar Baag delivered this lecture at Amrita Vishwa Vidyapeetham. This lecture is part of lecture series on Data Structures and Representation course. It includes: Heap, Sort, Queues, Priority, Heaps, Implement, Binary, Tree, Nodes, Parent, Child, Siblings
Typology: Slides
1 / 7
This page cannot be seen from the preview
Don't miss anything!




In many situations, simple queues are inadequate, since first in/first out scheduling has to be overruled using some priority criteria. EE.g. in a sequence of processes, process P i f P 2 may need to bed t b executed before process P 1 for the proper functioning of a system, even though P 1 was put on the queue of waiting processes before PP 2 2 .. Banks managing customer information Often will remove or get the information about the customer with the minimum bank account balance Shared Printer queue list of print jobs, must get next job with highest priority , and higher-priority jobs always print before lower-priority jobs IIn situations like these, a modified queue or it ti lik th difi d priority queue,i it iis needed. In priority queues, elements are dequeued according to their priority and their current queue positionspriority and their current queue positions.
The problem with a priority queue is in finding an efficient implementation which allows relatively fast enqueuing and dequeuingenqueuing and dequeuing Since elements may arrive randomly to the queue, there is no guarantee that the front elements will be the most likely to be dequeued and that the elementsthe most likely to be dequeued and that the elements put at the end will be the last candidates for dequeuing. ThThe situation is complicated because a wide spectrum it ti i li t d b id t of possible priority criteria can be used in different cases.
All levels are complete except the lowest oneAll levels are complete except the lowest one (According to book complete and almost complete Binary tree is same but this is a mistake in most of the books, so plz concentrate only Lecture slides.)
k
2k 2k 1 G
D 2k 2k+ 7 8 9 10 11 H I J K L
N b i f t ’ d f t i A B C D E F G H I J K L
Numbering of a tree’s nodes for storage in an array
Numbering of a tree’s nodes for storage in an array
(^304880)
21 10 25 30 14
(^10 ) (^1424)
50 30 (^10 1710 )
33 30 35
50
7 3
(^10 1710 ) 28 18 9 11
22
To enqueue an element, the element is added at the end of the heap as the last leaf. Restoring the heap property in the case of enqueuingRestoring the heap property in the case of enqueuing is achievied by moving from the last leaf toward the root. ThThe algorithm for enqueuing is as follows l ith f i i f ll heapEnqueue(el) put el at the end of heap;put el at the end of heap; while el is not in the root and el > parent(el) swap el with its parent
Enqueuing an element to a heap
Enqueuing an element to a heap
20
Dequeuing an element from heap
Dequeuing an element from heap
Dequeuing an element from heap d 20
dequeue
Dequeuing an element from heap
Mohammad Ikramulhaq FAST Data stData structures and algorithm in C++ , 2nd Edition, ct es and algo ithm in C++ 2nd Edition By Adam Drozdek (second edition), Brooks / Cole, Thomson Learning Inc. Introduction to Data Structures and Algorithms with C++ By Glenn W. Rowe, Prentice-Hall, India Data structures and algorithm analysis in C++, ByData structures and algorithm analysis in C , By Mark Allen Weiss, Benjamin/Cummings Publishing Company, Inc. Data structures and Program Design in CData structures and Program Design in C, By RobertBy Robert L. Kruse ….. \juweb\jinnah\Dr.A Qadir\CS2114 Summer