HEAP SORT | Sorting Algorithms | DSA | GeeksforGeeks

HEAP SORT | Sorting Algorithms | DSA | GeeksforGeeks

GeeksforGeeks

7 лет назад

1,614,024 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Rukesh kumar J
Rukesh kumar J - 05.09.2023 16:14

GFG please use Green color for Thumbnails . It easy for us figure out GFG videos from others😇

Ответить
Iamfalafel
Iamfalafel - 01.08.2023 03:11

Basically bubble sort on a binary tree, which is why you get complexity log n instead of n since you sift up a tree instead of through the entire array

Ответить
Amitav Mozumder
Amitav Mozumder - 13.07.2023 17:34

what's worse than a thick accent? the answer is a loud obnoxious backgrounds music.

Ответить
Anusmita Kundu
Anusmita Kundu - 12.07.2023 08:15

why the for loop is starting from n/2 -1 ?

Ответить
aldoalf
aldoalf - 06.07.2023 06:54

I could promote my sort algorithm but the comment will be deleted as always, so I won't 😿

Ответить
מעוז דניאל
מעוז דניאל - 28.06.2023 10:08

comment

Ответить
Andrew Titus
Andrew Titus - 21.04.2023 21:21

if 4 is greater than 3, why isnt 3 at the bottom?

Ответить
Lone Wolf
Lone Wolf - 07.04.2023 09:16

great animation

Ответить
Sri Ram Om
Sri Ram Om - 27.03.2023 09:59

very helpful

Ответить
Dipesh
Dipesh - 17.03.2023 18:03

wow

Ответить
hero_of_winds
hero_of_winds - 01.03.2023 02:42

I thought a max heap was greatest to smallest. Is this not a min heap?

Ответить
Carolina Díaz
Carolina Díaz - 23.02.2023 17:37

It took me several views to understand. It might be good to emphasize the fact that when you are going to change the top biggest node with the last node from the heap (not the smallest).

Ответить
Altay Turan
Altay Turan - 11.01.2023 13:49

Software Elfs!

Ответить
jooooyeonkim
jooooyeonkim - 10.12.2022 10:53

thank you

Ответить
Priyanka Vasam
Priyanka Vasam - 10.12.2022 04:17

understood how heap algo works clearly..thanks Arjun Tyagi and GFG

Ответить
O R
O R - 08.11.2022 18:58

Really hating the white on bright green.

Ответить
Om Mahajan
Om Mahajan - 01.11.2022 12:26

Great in 2 minutes it's GREAT VIDEO !!!!

Ответить
Mr. Anonymous
Mr. Anonymous - 11.10.2022 17:57

Thanks for these shorts it helps us build up basics in mind or whenever we have to just revise our concepts

Ответить
Suravi Ghosal
Suravi Ghosal - 11.06.2022 11:01

Thanks!

Ответить
Rana Khan
Rana Khan - 05.06.2022 21:02

😭😭😭😭thank you so much you never disappoint

Ответить
Phi Hồ
Phi Hồ - 23.04.2022 23:54

Bubble Sort
Selection Sort
Insertion Sort
Quick Sort
Merge Sort
Shell Sort

Ответить
Lucky
Lucky - 15.04.2022 11:43

import java.util.Random;

public class HeapSort {

public void Heapsort(int A[]) {
BuildHeap(A);

for (int i = A.length - 1; i > 0; i--) {

int temp = A[0];
A[0] = A[i];
A[i] = temp;

Heapify(A, i, 0);
}
}

public void BuildHeap(int[] A) {
int heapsize = A.length;

for (int i = heapsize / 2 - 1; i >= 0; i--)
Heapify(A, heapsize, i);
}

void Heapify(int arr[], int heapsize, int i) {
int largest = i;
int l = 2 * i + 1;
int r = 2 * i + 2;

if (l < heapsize && arr[l] > arr[largest])
largest = l;

if (r < heapsize && arr[r] > arr[largest])
largest = r;

if (largest != i) {
int swap = arr[i];
arr[i] = arr[largest];
arr[largest] = swap;

Heapify(arr, heapsize, largest);
}
}

public void printArray(int arr[]) {
int n = arr.length;
for (int i = 0; i < n; ++i)
System.out.print(arr[i] + " ");
System.out.println();
}

public static void main(String args[]) {
int A[]= new int[20];

HeapSort hs = new HeapSort();
Random ran = new Random();

for (int i = 0; i < 20; i++) {
A[i] = ran.nextInt(100);
}

System.out.println("Before sorted Array A");
hs.printArray(A);

hs.Heapsort(A);

System.out.println("After sorted Array A");
hs.printArray(A);
}
}
Here is a java code with 20 random variables

Ответить
Ashar Zafar
Ashar Zafar - 06.04.2022 18:45

To the point video! Good job!

Ответить
Adrian Agus Setiawan
Adrian Agus Setiawan - 05.03.2022 05:12

I am just amazed that once in history, somebody, somehow had a time and energy to think about this HeapSort algorithm. I appreciate it though. It's brilliant.

Ответить
Davide Barbieri
Davide Barbieri - 07.02.2022 16:59

Always a great intuitive video. Well done! However I'm actually asking myself wether or not in 2022 knowing the internals of heapsort (as a software developer) would benefit me. I know costs, and where to apply it. It seems to me like knowledge simply for its own sake.

Ответить
haris butt
haris butt - 01.01.2022 21:43

Ответить
B Y
B Y - 23.12.2021 00:46

if anyone here still studying at school let me advice you something don't forget those or you need to come here again to learn again for job interview exams

Ответить
Erik Truong
Erik Truong - 09.12.2021 01:29

What is the name of the song?

Ответить
Kanza Naveed
Kanza Naveed - 21.11.2021 19:56

I am adding in a comment to let you know that I appreciate your love of spreading ease around the world, too. Thank you so much from the depth of heart!!!!!!!!!

Ответить
Jaya Bharathi
Jaya Bharathi - 13.11.2021 08:17

I understood clearly after watching 5times thanks....

Ответить
Unhearted
Unhearted - 09.11.2021 07:52

I was really confused on wether or not you could do the heapsort from the top to the bottom, or it was necessary to do it from bottom level to top, since the first method would increase number of operations, but I look at your video, where you basically do them both.

Ответить
Raton
Raton - 06.11.2021 15:16

Thank you so much for this video, i finnaly understood it !!!! I've been reading so many definitions of what heapsort is, and I couldn't wrap my head around it, now it finally makes sense :D

Ответить
Anil kumar Sharma
Anil kumar Sharma - 30.10.2021 11:48

Maximum volume by various surface area
Like triangle🔺 🔲squares rectangle rhombus etc

Ответить
Philcob Suzuki
Philcob Suzuki - 22.09.2021 08:13

What if there are 6 or more indexes. How to do?

Ответить
likhithamayu
likhithamayu - 12.07.2021 08:05

For min heap sort also can you please upload a vedio :)

Ответить
Mohammed Najl
Mohammed Najl - 02.07.2021 13:45

Interesting! Understood it, but seems like hell to implement in code...

Ответить
Võ Minh Trí Nguyễn
Võ Minh Trí Nguyễn - 01.07.2021 07:44

Great! Thank you

Ответить
Kevin Wu
Kevin Wu - 30.06.2021 08:34

Why not use a min heap? In this way you don't even need to swap the first and the last

Ответить
Soumyadwip Chanda
Soumyadwip Chanda - 29.06.2021 23:19

Maza aa gya

Ответить
Aman Verma
Aman Verma - 24.06.2021 15:00

Best ever illustrated

Ответить
Ome123
Ome123 - 15.06.2021 10:40

No nuisance only concept best vdo💪

Ответить
jjhassy
jjhassy - 08.05.2021 00:45

Online Bookstore

Ответить
Anushka Bhatnagar
Anushka Bhatnagar - 07.05.2021 15:06

Well explained!

Ответить
Diana Dev
Diana Dev - 17.04.2021 12:51

it is so complicated

Ответить
Álvaro Abad de Donesteve
Álvaro Abad de Donesteve - 07.04.2021 13:37

bootom-up heapsort?

Ответить
Balaji Ganesh
Balaji Ganesh - 27.03.2021 08:11

if both child nodes are greater than the parent node,which of the two should swapped to make a max heap?

Ответить
PawlsToTheWall
PawlsToTheWall - 24.03.2021 07:52

What do you use to produce these videos? I am a tutor and would like to produce instructional videos for my students.

Ответить