Join Raghavendra Dixit for an in-depth discussion in this video Representing heaps using arrays, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Now, how to we implement a heap?…Of course, we can create a node object,…and then just create a binary tree-like structure,…just making sure that the heap properties are maintained.…All right?…But there is another way.…We can use an array as an underlying data structure.…And why does that work?…Well, because if you look at a heap,…the order in which the nodes are inserted…can be marked as this.…Inserted.…
I mean considering that zero is for the first node,…one for the second and so on.…This is because we need to maintain the first heap property,…which means that the heap should be complete.…Now, if you look at any node and its immediate children,…you can see a relationship.…So, if the parent is marked as i,…its left child will be marked 2i+1,…and its right child will be marked 2i+2.…
Right?…Now interestingly the array indices also start from zero,…and we can just represent the various nodes of the heap…as elements of the array.…For example, the root node may be held…at index zero of the array.…Its left child at index one,…
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.