Join Raghavendra Dixit for an in-depth discussion in this video Heaps as priority queues, part of Introduction to Data Structures & Algorithms in Java.
- [Male Narrator] Because the largest element is always…at the root node in a heap,…the heap data structure may be used as a priority queue.…Let's say that the keys at each node represent the priority…of an item or a node to be processed.…Then the root element will always have the highest priority,…isn't it?…And once we are done processing the root node,…we can delete it from the heap.…And after we fix the heap,…the node with the next higher priority will come…to the root, right?…So now, that node may be processed.…
So using heaps as priority queues…is really easy and straightforward.…We don't need to do anything special.…But sometimes in a priority queue,…we change the priority of an item.…That is, let's say that we change the key…of an item or node.…Let's consider this node 13.…If you want to change the priority of this node…to say, 25, we can update the node value.…But then, we will need to fix the heap…because 25 may be greater than its parent.…
So we may need to bubble this node up…until it reaches the right place.…
Note: This course was created by Packt Publishing. We are pleased to host this training in our library.
- Why study data structures and algorithms?
- How to calculate the time complexity
- Using Big O notation
- Using basic sorting and search algorithms
- Searching elements in unordered arrays and ordered arrays
- Implementing a linked list in Java
- Implementing stacks using arrays
- Queues using arrays
- Binary search trees
- Representing heaps using arrays
Skill Level Intermediate
1. Introduction to Algorithms
2. Analysis of Algorithms
3. Basic Sorting and Search Algorithms
4. Linked Lists
5. Stacks and Queues
7. Binary Search Trees
8. More Sorting Algorithms
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.