heapsort example - university of cambridge...heapify(6) qwerty[u]iopasdfg q w r i o t p a e y s d u...
TRANSCRIPT
![Page 1: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/1.jpg)
Heapsort example
Andrej Ivaskovic
University of Cambridge
February 1, 2015
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 1 / 25
![Page 2: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/2.jpg)
InputInitial state of the heap
We are given an array that needs to be sorted:
QWERTYUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 2 / 25
![Page 3: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/3.jpg)
Making the array satisfy the max-heap propertyheapify(6)
QWERTY[U]IOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 3 / 25
![Page 4: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/4.jpg)
Making the array satisfy the max-heap propertyheapify(6)
QWERTY[U]IOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 3 / 25
![Page 5: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/5.jpg)
Making the array satisfy the max-heap propertyheapify(5)
QWERT[Y]UIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 4 / 25
![Page 6: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/6.jpg)
Making the array satisfy the max-heap propertyheapify(5)
QWERT[Y]UIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 4 / 25
![Page 7: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/7.jpg)
Making the array satisfy the max-heap propertyheapify(4)
QWER[T]YUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 5 / 25
![Page 8: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/8.jpg)
Making the array satisfy the max-heap propertyheapify(4)
QWER[T]YUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 5 / 25
![Page 9: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/9.jpg)
Making the array satisfy the max-heap propertyheapify(3)
QWE[R]TYUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 6 / 25
![Page 10: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/10.jpg)
Making the array satisfy the max-heap propertyheapify(3)
QWE[R]TYUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 6 / 25
![Page 11: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/11.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[E]RTYUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 12: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/12.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[E]RTYUIOPASDFG
Q
W
R
I O
T
P A
E
Y
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 13: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/13.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[Y]RTEUIOPASDFG
Q
W
R
I O
T
P A
Y
E
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 14: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/14.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[Y]RTEUIOPASDFG
Q
W
R
I O
T
P A
Y
E
S D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 15: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/15.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[Y]RTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 16: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/16.jpg)
Making the array satisfy the max-heap propertyheapify(2)
QW[Y]RTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 7 / 25
![Page 17: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/17.jpg)
Making the array satisfy the max-heap propertyheapify(1)
Q[W]YRTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 8 / 25
![Page 18: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/18.jpg)
Making the array satisfy the max-heap propertyheapify(1)
Q[W]YRTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 8 / 25
![Page 19: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/19.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Q]WYRTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 20: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/20.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Q]WYRTSUIOPAEDFG
Q
W
R
I O
T
P A
Y
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 21: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/21.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Y]WQRTSUIOPAEDFG
Y
W
R
I O
T
P A
Q
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 22: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/22.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Y]WQRTSUIOPAEDFG
Y
W
R
I O
T
P A
Q
S
E D
U
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 23: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/23.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Y]WURTSQIOPAEDFG
Y
W
R
I O
T
P A
U
S
E D
Q
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 24: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/24.jpg)
Making the array satisfy the max-heap propertyheapify(0)
[Y]WURTSQIOPAEDFG
Y
W
R
I O
T
P A
U
S
E D
Q
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 9 / 25
![Page 25: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/25.jpg)
End of step 1We have a heap!
Now the array satisfies the binary max-heap property:
YWURTSQIOPAEDFG
Y
W
R
I O
T
P A
U
S
E D
Q
F G
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 10 / 25
![Page 26: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/26.jpg)
Removal of elements from the heapWe have the 14th element!
[G]WURTSQIOPAEDFY
G
W
R
I O
T
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 27: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/27.jpg)
Removal of elements from the heapWe have the 14th element!
GWURTSQIOPAEDFY
G
W
R
I O
T
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 28: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/28.jpg)
Removal of elements from the heapWe have the 14th element!
WGURTSQIOPAEDFY
W
G
R
I O
T
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 29: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/29.jpg)
Removal of elements from the heapWe have the 14th element!
WGURTSQIOPAEDFY
W
G
R
I O
T
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 30: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/30.jpg)
Removal of elements from the heapWe have the 14th element!
WTURGSQIOPAEDFY
W
T
R
I O
G
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 31: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/31.jpg)
Removal of elements from the heapWe have the 14th element!
WTURGSQIOPAEDFY
W
T
R
I O
G
P A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 32: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/32.jpg)
Removal of elements from the heapWe have the 14th element!
WTURPSQIOGAEDFY
W
T
R
I O
P
G A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 33: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/33.jpg)
Removal of elements from the heapWe have the 14th element!
WTURPSQIOGAEDFY
W
T
R
I O
P
G A
U
S
E D
Q
F Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 11 / 25
![Page 34: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/34.jpg)
Removal of elements from the heapWe have the 13th element!
[F]TURPSQIOGAEDWY
F
T
R
I O
P
G A
U
S
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 35: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/35.jpg)
Removal of elements from the heapWe have the 13th element!
FTURPSQIOGAEDWY
F
T
R
I O
P
G A
U
S
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 36: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/36.jpg)
Removal of elements from the heapWe have the 13th element!
UTFRPSQIOGAEDWY
U
T
R
I O
P
G A
F
S
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 37: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/37.jpg)
Removal of elements from the heapWe have the 13th element!
UTFRPSQIOGAEDWY
U
T
R
I O
P
G A
F
S
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 38: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/38.jpg)
Removal of elements from the heapWe have the 13th element!
UTSRPFQIOGAEDWY
U
T
R
I O
P
G A
S
F
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 39: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/39.jpg)
Removal of elements from the heapWe have the 13th element!
UTSRPFQIOGAEDWY
U
T
R
I O
P
G A
S
F
E D
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 12 / 25
![Page 40: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/40.jpg)
Removal of elements from the heapWe have the 12th element!
[D]TSRPFQIOGAEUWY
D
T
R
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 41: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/41.jpg)
Removal of elements from the heapWe have the 12th element!
DTSRPFQIOGAEUWY
D
T
R
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 42: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/42.jpg)
Removal of elements from the heapWe have the 12th element!
TDSRPFQIOGAEUWY
T
D
R
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 43: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/43.jpg)
Removal of elements from the heapWe have the 12th element!
TDSRPFQIOGAEUWY
T
D
R
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 44: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/44.jpg)
Removal of elements from the heapWe have the 12th element!
TRSDPFQIOGAEUWY
T
R
D
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 45: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/45.jpg)
Removal of elements from the heapWe have the 12th element!
TRSDPFQIOGAEUWY
T
R
D
I O
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 46: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/46.jpg)
Removal of elements from the heapWe have the 12th element!
TRSOPFQIDGAEUWY
T
R
O
I D
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 47: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/47.jpg)
Removal of elements from the heapWe have the 12th element!
TRSOPFQIDGAEUWY
T
R
O
I D
P
G A
S
F
E U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 13 / 25
![Page 48: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/48.jpg)
Removal of elements from the heapWe have the 11th element!
[E]RSOPFQIDGATUWY
E
R
O
I D
P
G A
S
F
T U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 49: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/49.jpg)
Removal of elements from the heapWe have the 11th element!
ERSOPFQIDGATUWY
E
R
O
I D
P
G A
S
F
T U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 50: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/50.jpg)
Removal of elements from the heapWe have the 11th element!
SREOPFQIDGATUWY
S
R
O
I D
P
G A
E
F
T U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 51: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/51.jpg)
Removal of elements from the heapWe have the 11th element!
SREOPFQIDGATUWY
S
R
O
I D
P
G A
E
F
T U
Q
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 52: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/52.jpg)
Removal of elements from the heapWe have the 11th element!
SRQOPFEIDGATUWY
S
R
O
I D
P
G A
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 53: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/53.jpg)
Removal of elements from the heapWe have the 11th element!
SRQOPFEIDGATUWY
S
R
O
I D
P
G A
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 14 / 25
![Page 54: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/54.jpg)
Removal of elements from the heapWe have the 10th element!
[A]RQOPFEIDGSTUWY
A
R
O
I D
P
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 55: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/55.jpg)
Removal of elements from the heapWe have the 10th element!
ARQOPFEIDGSTUWY
A
R
O
I D
P
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 56: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/56.jpg)
Removal of elements from the heapWe have the 10th element!
RAQOPFEIDGSTUWY
R
A
O
I D
P
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 57: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/57.jpg)
Removal of elements from the heapWe have the 10th element!
RAQOPFEIDGSTUWY
R
A
O
I D
P
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 58: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/58.jpg)
Removal of elements from the heapWe have the 10th element!
RPQOAFEIDGSTUWY
R
P
O
I D
A
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 59: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/59.jpg)
Removal of elements from the heapWe have the 10th element!
RPQOAFEIDGSTUWY
R
P
O
I D
A
G S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 60: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/60.jpg)
Removal of elements from the heapWe have the 10th element!
RPQOGFEIDASTUWY
R
P
O
I D
G
A S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 61: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/61.jpg)
Removal of elements from the heapWe have the 10th element!
RPQOGFEIDASTUWY
R
P
O
I D
G
A S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 15 / 25
![Page 62: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/62.jpg)
Removal of elements from the heapWe have the 9th element!
[A]PQOGFEIDRSTUWY
A
P
O
I D
G
R S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 63: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/63.jpg)
Removal of elements from the heapWe have the 9th element!
APQOGFEIDRSTUWY
A
P
O
I D
G
R S
Q
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 64: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/64.jpg)
Removal of elements from the heapWe have the 9th element!
QPAOGFEIDRSTUWY
Q
P
O
I D
G
R S
A
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 65: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/65.jpg)
Removal of elements from the heapWe have the 9th element!
QPAOGFEIDRSTUWY
Q
P
O
I D
G
R S
A
F
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 66: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/66.jpg)
Removal of elements from the heapWe have the 9th element!
QPFOGAEIDRSTUWY
Q
P
O
I D
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 67: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/67.jpg)
Removal of elements from the heapWe have the 9th element!
QPFOGAEIDRSTUWY
Q
P
O
I D
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 16 / 25
![Page 68: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/68.jpg)
Removal of elements from the heapWe have the 8th element!
[D]PFOGAEIQRSTUWY
D
P
O
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 69: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/69.jpg)
Removal of elements from the heapWe have the 8th element!
DPFOGAEIQRSTUWY
D
P
O
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 70: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/70.jpg)
Removal of elements from the heapWe have the 8th element!
PDFOGAEIQRSTUWY
P
D
O
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 71: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/71.jpg)
Removal of elements from the heapWe have the 8th element!
PDFOGAEIQRSTUWY
P
D
O
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 72: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/72.jpg)
Removal of elements from the heapWe have the 8th element!
POFDGAEIQRSTUWY
P
O
D
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 73: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/73.jpg)
Removal of elements from the heapWe have the 8th element!
POFDGAEIQRSTUWY
P
O
D
I Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 74: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/74.jpg)
Removal of elements from the heapWe have the 8th element!
POFIGAEDQRSTUWY
P
O
I
D Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 75: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/75.jpg)
Removal of elements from the heapWe have the 8th element!
POFIGAEDQRSTUWY
P
O
I
D Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 17 / 25
![Page 76: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/76.jpg)
Removal of elements from the heapWe have the 7th element!
[D]OFIGAEPQRSTUWY
D
O
I
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 77: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/77.jpg)
Removal of elements from the heapWe have the 7th element!
DOFIGAEPQRSTUWY
D
O
I
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 78: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/78.jpg)
Removal of elements from the heapWe have the 7th element!
ODFIGAEPQRSTUWY
O
D
I
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 79: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/79.jpg)
Removal of elements from the heapWe have the 7th element!
ODFIGAEPQRSTUWY
O
D
I
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 80: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/80.jpg)
Removal of elements from the heapWe have the 7th element!
OIFDGAEPQRSTUWY
O
I
D
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 81: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/81.jpg)
Removal of elements from the heapWe have the 7th element!
OIFDGAEPQRSTUWY
O
I
D
P Q
G
R S
F
A
T U
E
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 18 / 25
![Page 82: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/82.jpg)
Removal of elements from the heapWe have the 6th element!
[E]IFDGAOPQRSTUWY
E
I
D
P Q
G
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 83: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/83.jpg)
Removal of elements from the heapWe have the 6th element!
EIFDGAOPQRSTUWY
E
I
D
P Q
G
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 84: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/84.jpg)
Removal of elements from the heapWe have the 6th element!
IEFDGAOPQRSTUWY
I
E
D
P Q
G
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 85: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/85.jpg)
Removal of elements from the heapWe have the 6th element!
IEFDGAOPQRSTUWY
I
E
D
P Q
G
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 86: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/86.jpg)
Removal of elements from the heapWe have the 6th element!
IGFDEAOPQRSTUWY
I
G
D
P Q
E
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 87: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/87.jpg)
Removal of elements from the heapWe have the 6th element!
IGFDEAOPQRSTUWY
I
G
D
P Q
E
R S
F
A
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 19 / 25
![Page 88: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/88.jpg)
Removal of elements from the heapWe have the 5th element!
[A]GFDEIOPQRSTUWY
A
G
D
P Q
E
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 89: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/89.jpg)
Removal of elements from the heapWe have the 5th element!
AGFDEIOPQRSTUWY
A
G
D
P Q
E
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 90: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/90.jpg)
Removal of elements from the heapWe have the 5th element!
GAFDEIOPQRSTUWY
G
A
D
P Q
E
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 91: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/91.jpg)
Removal of elements from the heapWe have the 5th element!
GAFDEIOPQRSTUWY
G
A
D
P Q
E
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 92: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/92.jpg)
Removal of elements from the heapWe have the 5th element!
GEFDAIOPQRSTUWY
G
E
D
P Q
A
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 93: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/93.jpg)
Removal of elements from the heapWe have the 5th element!
GEFDAIOPQRSTUWY
G
E
D
P Q
A
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 20 / 25
![Page 94: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/94.jpg)
Removal of elements from the heapWe have the 4th element!
[A]EFDGIOPQRSTUWY
A
E
D
P Q
G
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 21 / 25
![Page 95: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/95.jpg)
Removal of elements from the heapWe have the 4th element!
AEFDGIOPQRSTUWY
A
E
D
P Q
G
R S
F
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 21 / 25
![Page 96: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/96.jpg)
Removal of elements from the heapWe have the 4th element!
FEADGIOPQRSTUWY
F
E
D
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 21 / 25
![Page 97: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/97.jpg)
Removal of elements from the heapWe have the 4th element!
FEADGIOPQRSTUWY
F
E
D
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 21 / 25
![Page 98: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/98.jpg)
Removal of elements from the heapWe have the 3rd element!
[D]EAFGIOPQRSTUWY
D
E
F
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 22 / 25
![Page 99: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/99.jpg)
Removal of elements from the heapWe have the 3rd element!
DEAFGIOPQRSTUWY
D
E
F
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 22 / 25
![Page 100: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/100.jpg)
Removal of elements from the heapWe have the 3rd element!
EDAFGIOPQRSTUWY
E
D
F
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 22 / 25
![Page 101: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/101.jpg)
Removal of elements from the heapWe have the 3rd element!
EDAFGIOPQRSTUWY
E
D
F
P Q
G
R S
A
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 22 / 25
![Page 102: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/102.jpg)
Removal of elements from the heapWe have the 2nd element!
[A]DEFGIOPQRSTUWY
A
D
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 23 / 25
![Page 103: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/103.jpg)
Removal of elements from the heapWe have the 2nd element!
ADEFGIOPQRSTUWY
A
D
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 23 / 25
![Page 104: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/104.jpg)
Removal of elements from the heapWe have the 2nd element!
DAEFGIOPQRSTUWY
D
A
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 23 / 25
![Page 105: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/105.jpg)
Removal of elements from the heapWe have the 2nd element!
DAEFGIOPQRSTUWY
D
A
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 23 / 25
![Page 106: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/106.jpg)
Removal of elements from the heapWe have the 1st element!
[A]DEFGIOPQRSTUWY
A
D
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 24 / 25
![Page 107: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/107.jpg)
Removal of elements from the heapWe have the 1st element!
ADEFGIOPQRSTUWY
A
D
F
P Q
G
R S
E
I
T U
O
W Y
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 24 / 25
![Page 108: Heapsort example - University of Cambridge...heapify(6) QWERTY[U]IOPASDFG Q W R I O T P A E Y S D U F G Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015](https://reader033.vdocuments.net/reader033/viewer/2022050103/5f41df9108b7f562c07f6790/html5/thumbnails/108.jpg)
We are done!
What we get in the end is sorted:
ADEFGIOPQRSTUWY
Andrej Ivaskovic (University of Cambridge) Heapsort example February 1, 2015 25 / 25