← 回題庫

卷別

資料結構與演算法

計算

國立中興大學 2025 · 考試 · 第 25 題

(10%) Consider a binary min-heap represented by the array [1,3,2,10,7,6,9][1, 3, 2, 10, 7, 6, 9], where the element 1 is at the root. Suppose you need to insert a new element, 4, into this min-heap. Describe the complete insertion process step-by-step. Your answer should include:

  • Indicating where the new element is initially placed in the array.
  • Explaining the heapify-up (or bubble-up) process in detail, showing each intermediate state of the heap after any necessary swaps.
  • Presenting the final min-heap array once the insertion is complete.

Make sure to clearly justify the steps taken and the reasoning behind each comparison and swap, based on the fundamental properties of a min-heap.

標準解析

AI 已複查