Data Structures, Algorithms, Java, Big O Notation, Searching And Sorting.
Initialize largest as root int l = 2 * i + 1; // left = 2*i + 1 int r = 2 * i + 2; // right = 2*i + 2 // If left child is larger than root if (l < size && arr[l] > arr[largest]) largest = l; // If right child is larger than largest so far if (r < size && arr[r] > arr[largest]) largest = r; // If