Join Raghavendra Dixit for an in-depth discussion in this video Building a heap, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Let's see how to arrange some given numbers…in a heap data structure.…Let's say we are given this array of numbers.…And we would like to store them…in another array of the same size,…such that this new array represents a heap.…So let's just start with the first element.…The first element should become the root.…So it should be placed at index 0.…
So we place 8 at the root of the heap…and move to the next number.…Where should it be placed?…Well, we first want to make the binary tree complete…for it to be a heap.…So we place this as the left child of the current root node.…So this element will go to the index 1 of the array…and then we fix the heap.…But because 3 is smaller than 8,…the second heap properties satisfy it…so we don't need to do anything in this case.…
Then we move to the next number, 5.…Where should we add it?…To keep the tree complete,…it should be added as the right child of the root node.…So this would be added at index 2.…So the idea of building the heap this way…is that we keep putting the new numbers in the array…
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.