Join Raghavendra Dixit for an in-depth discussion in this video Heap sort, part of Introduction to Data Structures & Algorithms in Java.
- [Instructor] Now we'll look at the heap sort algorithm,…which is another n-log-n algorithm.…Let's say we have some data…in the form of a heap data structure,…and we want to sort it.…On the right-hand side,…we will display the array presentation of the heap.…We know that the root is the largest element in the heap,…and we would like to sort the data in the array…in the ascending order.…What we can do is to exchange the root element…with the last element of the array.…
Because 20, which is the largest number,…has reached the last index of the array,…we can consider that part as sorted.…After doing this exchange, the heap needs to be fixed,…which is just like the case of deleting the root node.…So the node 10 has to be bubbled down…until the second heap property is met.…So now again, we have the largest number at the root,…and we exchange this with the element…at the second last index of the array,…which is the second last element of the heap.…
So now the last two elements are sorted.…We again fix the heap.…We keep doing these steps repeatedly,…
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.