Docsity

Cos tutorial question, Summaries of Engineering

Toggle sidebar
bg1
COS212 (Data Structures and Algorithms)
Tutorial 6: Exercise
2026/04/06
Question 1 Heaps........................................................................ (5 marks)
1.1 Assume the following max-heap is stored using the array representation:
[51,40,30,29,31,28,27,11,15,6,7,10,12,4]
a) [2 points] Give the final array after 39 is enqueued to the heap.
b) [2 points] Use Floyd’s heapifying algorithm to convert the original heap into a min-heap.
c) [1 point] What is the easiest way to find the minimum value in a max-heap?
Question 2 Leftist and Skew Heaps.......................................................(7 marks)
2.1 Given the following heap:
4
12
13 45
60
15
33 25
a) [4 points] Assume the heap is a leftist heap. Give the final heap after the minimum value
is dequeued. Indicate the NPL values for each node in brackets.
b) [3 points] Assume the heap is a skew heap. Give the final heap after 30 is enqueued.
Page 1 of 2
pf2

Partial preview of the text

Download Cos tutorial question and more Summaries Engineering in PDF only on Docsity!

COS212 (Data Structures and Algorithms)

Tutorial 6: Exercise

Question 1 Heaps........................................................................ (5 marks)

1.1 Assume the following max-heap is stored using the array representation: [51, 40 , 30 , 29 , 31 , 28 , 27 , 11 , 15 , 6 , 7 , 10 , 12 , 4] a) [2 points] Give the final array after 39 is enqueued to the heap. b) [2 points] Use Floyd’s heapifying algorithm to convert the original heap into a min-heap. c) [1 point] What is the easiest way to find the minimum value in a max-heap?

Question 2 Leftist and Skew Heaps...................................................... .(7 marks)

2.1 Given the following heap: 4 12 13 45 60

a) [4 points] Assume the heap is a leftist heap. Give the final heap after the minimum valueis dequeued. Indicate the NPL values for each node in brackets. b) [3 points] Assume the heap is a skew heap. Give the final heap after 30 is enqueued.

Page 1 of 2

COS 212: Tutorial 6: Exercise: 2026/04/

Question 3 Treaps....................................................................... (4 marks)

3.1 Assume that the following tree and array are used to store a treap: 0 1 3 4

N^0 B^1 P^2 A^3 C^4

a) [2 points] Give the final tree and array after G is inserted with a priority of 1. b) [2 points] Give the final tree and array after N is deleted from the treap.

Page 2 of 2