تم الحل ✓
categoryعلوم الحاسوب وتقنية المعلومات
schoolبكالوريوس
event_available2026-07-13
السؤال
Transcribed Image Text:
Problem #1
(a) Show the result (only the array representation) of converting the array given below into
a min-heap.
15
10
13
9
6
7
8
17
8
5
(b) Show the resulting heap (only the array representation) after the deleteMin operation
is performed on the following min-heap.
15
17
19 20
35
20
25
27
21
37 36
(c) Consider an initially empty max-heap, where the following keys are to be inserted one
at a time: 11, 19, 23, 12, 13, 17, 13, 14, 18, and 33. Draw the tree that results after
building this max-heap.
(d) Write a method replaceKey in the BinaryHeap class with the following signature:
public void replaceKey(Integer oldKey, Integer newKey)
The method will replace the first occurrence of old Key with the newKey, and restore
the Min-Heap property after the change. If the old Key does not exist in the heap, the
method prints an appropriate message and returns without changing the heap. Suppose
our binary heap object (bh) has the following keys:
5 10 9
Then the method call: bh.replaceKey (new Integer (10), new Integer(3)) should
change the keys to:
11 15 10 12 13 14 16 18
3
5 9
11 15 10 12 13
14
16
18
Note: You can assume that the methods perlocateUp and perlocate Down are already
implemented in your BinaryHeap class.
check_circle الجواب — حل مفصل خطوة بخطوة
hourglass_top
🔒
الحل الكامل متاح للمشتركين
اشترك في أرشيف الأسئلة لعرض هذا الحل وآلاف الحلول المفصلة خطوة بخطوة من معلمين معتمدين.