Join Raghavendra Dixit for an in-depth discussion in this video Inserting an item in a heap, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's see how to insert a new item…or a new node into a heap.…So keeping to the first heap property,…that the heap should be complete,…the only place that we can insert this node…is to insert it as a left-child of node three, isn't it?…Because the level at node three is completely full.…But if we do that, it may break the second heap property,…which is that each parent node…should be greater than its children.…
So we need to bubble this new node upwards as long…as its value is greater than the parent node, alright?…Let's have another node.…This time, we insert it as the right-child of node 10.…Keeping the completeness property in mind.…And then bubble this node,…because its value is greater than its parent.…And we keep doing that…until the second heap property's satisfied.…
So in this case, node 20 will go up…and become the root of the heap, okay?…We call this process of bubbling the new node as…fixing the heap, alright?…And what is the time complexity of fixing the heap?…You already know that the number of layers in a binary tree…
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.