Heaps 3 TrickleUp

  Рет қаралды 19,082

RobEdwards

RobEdwards

Күн бұрын

Пікірлер
@sharpEarth
@sharpEarth 3 ай бұрын
Amazing thank you Dr. 🙂
@TZCoder
@TZCoder 5 жыл бұрын
At 12:22 its array[parent] not array.parrent
@tohtorizorro
@tohtorizorro 6 жыл бұрын
A method displaying the heap in proper triangle form for debugging: //////////// DISPLAY HEAP BY ROWS public void displayTree() { // These variables are used to keep track when a new row starts int currentRow; int previousRow = 1; // These variables are used for the horizontal alignment. // numRows is needed since the initial indentation depends // on how high the heap is. int numRows = (int) (Math.log(size + 1) / Math.log(2)); int indent = 0; int padding = 0; // THIS OFFSET VARIABLE HAS TO BE THE SAME AS THE AMOUNT OF LEADING ZEROS // IN THE PRINTF STATEMENT BELOW!!! int offset = 2; // Calculate the indent of first row: // - indent doubles by every row. // - offset = length of the actual printed values for (int i = 0; i < numRows; i++) { indent = (indent * 2) + offset; } // Print the indent for the first row for (int i = 0; i < indent; i++) { System.out.print(" "); } // Begin the main loop for (int index = 0; index < size; index++) { // Calculate currentRow based on the current index. // Original formula from professor Rob... // ... division by log(2) makes the logarithm base2 no matter // what original base is.. That's just a mathematical fact // which you should remember without googling! currentRow = 1 + (int) (Math.log(index + 1) / Math.log(2)); // Change row if (currentRow > previousRow) { System.out.println(); previousRow = currentRow; // Calculate new indentation and padding padding = indent; indent = (indent - offset) / 2; // print indentation for (int i = 0; i < indent; i++) { System.out.print(" "); } } // Print the actual value, leading zero helps with alignment. // THE OFFSET VARIABLE ABOVE HAS TO BE THE SAME AS // THE AMOUNT OF LEADING ZEROS IN THE PRINTF STATEMENT. System.out.printf("%02d", array[index]); // Print padding between values, padding is same as indentation of the previous row. // Had to fight the urge to ninja the padding variable out and use (indentation * 2) + offset // as the loop conditional. for (int i = 0; i < padding; i++) { System.out.print(" "); } } System.out.println(" "); }
@tohtorizorro
@tohtorizorro 6 жыл бұрын
Works with Integer values 0 - 99
@gyatso_fam
@gyatso_fam 5 жыл бұрын
use of clone jutsu in real life. amazing..
@davidgeismar6531
@davidgeismar6531 5 жыл бұрын
in trickle_up parent is not a method available on the array instance, it is an indice, it's meant to be called with brackets I think
@bouzidhamza3494
@bouzidhamza3494 4 жыл бұрын
doesn't it miss a line for updating the position? especially for the case where we are testing at the root
@0Megaman0
@0Megaman0 Жыл бұрын
if we are incrementing the position before adding the object to our array, wouldn't array[parent] == null when using comparator on root node? since there is nothing stored at array[0]? Math.floor(position(1) - 1.0) / 2.0)) gives us 0.
@davidgeismar6531
@davidgeismar6531 5 жыл бұрын
Is Math.floor((position - 1)/ 2) the sam as Math.ceil((position/2)-1) ?
@usa-ca
@usa-ca 6 жыл бұрын
If value of node#1 was 27, it would cause heap violation after 25 "trickles up" to root node. how is that handled? just one more "trickle down" op on the left side?
@TZCoder
@TZCoder 5 жыл бұрын
It would not trickle up if root was 27 because its bigger than 25, it only trickles up if parent is smaller.
@yagzyalcntas553
@yagzyalcntas553 6 жыл бұрын
You can do cool simultanious videos playing and making one of them wither away but still cant handle those black screens...
Heaps 4 TrickleDown
10:59
RobEdwards
Рет қаралды 14 М.
Hashes 1 Introduction
15:36
RobEdwards
Рет қаралды 40 М.
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН
She wanted to set me up #shorts by Tsuriki Show
0:56
Tsuriki Show
Рет қаралды 8 МЛН
Lecture 4: Heaps and Heap Sort
52:32
MIT OpenCourseWare
Рет қаралды 873 М.
AVL 1 Introduction
11:14
RobEdwards
Рет қаралды 95 М.
Heaps 1 Introduction and Tree levels
5:44
RobEdwards
Рет қаралды 25 М.
Heaps 2 Add Remove
5:57
RobEdwards
Рет қаралды 21 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
What Is Mathematical Optimization?
11:35
Visually Explained
Рет қаралды 144 М.
Hashes 9  Chaining
9:41
RobEdwards
Рет қаралды 17 М.
2.6.3 Heap - Heap Sort - Heapify - Priority Queues
51:08
Abdul Bari
Рет қаралды 2,3 МЛН
Trees 9 Introduction to rotations
8:32
RobEdwards
Рет қаралды 45 М.
Heaps 5 HeapSort
8:43
RobEdwards
Рет қаралды 68 М.
진짜✅ 아님 가짜❌???
0:21
승비니 Seungbini
Рет қаралды 10 МЛН