| preferred AP College board partner for AP classes
easy Solved by 16 students
Tracing Array Element Swaps
< Prev
Next >

What is the printed output of the heap array (excluding index 0) after executing HeapTest?

public class HeapTest {
    public static void main(String[] args) {
        int[] heap = {Integer.MIN_VALUE, 10, 20, 30, 40, 50}; // 1-indexed heap; index 0 is unused
        
        // Swap elements at indices 2 and 5
        int temp = heap[2];
        heap[2] = heap[5];
        heap[5] = temp;
        
        // Swap elements at indices 3 and 4
        temp = heap[3];
        heap[3] = heap[4];
        heap[4] = temp;
        
        for(int i = 1; i < heap.length; i++){
            System.out.print(heap[i] + " ");
        }
    }
}
A

10 50 40 30 20

B

10 40 50 30 20

C

10 20 40 30 50

D

10 50 30 40 20

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1varunrajaram111 0m 00s 100
#2leftoverjluck11 0m 50s 50
#3patrickmeijer00913 0m 32s 48
#4kshiva2009m11 1m 09s 31
#510818526511 1m 25s 15
#6701704611 2m 40s -60
#7lsj0803092211 3m 25s -105
#8y.seong202701 1m 59s -129
#9songqiuhui201225 11m 08s -498
#10psak1211 1h 36m -5,716
APFIVE © 2020.
Email: [email protected]|Privacy Policy