📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    Consider a min-heap represented as an array: [1, 3, 5,

    7, 9]. If the element 2 is inserted into this min-heap, what will be the state of the heap array after the insertion and heapify-up operation?
    A [1, 2, 5, 7, 9, 3] Correct Answer Incorrect Answer
    B [1, 3, 2, 7, 9, 5] Correct Answer Incorrect Answer
    C [1, 2, 3, 7, 9, 5] Correct Answer Incorrect Answer
    D [2, 1, 5, 7, 9, 3] Correct Answer Incorrect Answer
    E [1, 3, 5, 7, 9, 2] Correct Answer Incorrect Answer

    Solution

    Correct Answer: C (Initial: [1, 3, 5, 7, 9]. Insert 2: [1, 3, 5, 7, 9, 2]. Heapify-up: 2 is smaller than its parent 5, swap: [1, 3, 2, 7, 9, 5]. 2 is smaller than its parent 3, swap: [1, 2, 3, 7, 9, 5]. 2 is not smaller than 1, stop.)

    Practice Next
    ask-question