Name: Netid:: All Parts Are Due March 10, 2024 at 11:00 PM, Paris Time

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

All parts are due March 10, 2024 at 11:00 pm, Paris time.

Please submit a typed or neatly handwritten scan of your responses with a


single PDF file to Brightspace.

These problems are meant to be done individually. If you want to discuss these
problems with a partner or group, make sure that you are writing your answers
individually later on.

Aim for concise solutions; convoluted and obtuse descriptions might receive
low marks, even when they are correct.

Name: NETID:
1. Heap Practice
For each array below, draw it as a complete binary tree and state whether the tree is a max-
heap, a min-heap, or neither. If the tree is neither, turn the tree into a min-heap by repeatedly
swapping items that are adjacent in the tree. Communicate your swaps by drawing a sequence
of trees, marking on each tree the pair that was swapped.

(a) [4, 12, 8, 21, 14, 9, 17]


(b) [701, 253, 24, 229, 17, 22]
(c) [2, 9, 13, 8, 0, 2]
(d) [1, 3, 6, 5, 4, 9, 7]
2. Hashing
The keys 12,18,13,2,3,23,5 and15 are inserted into an initially empty hash table of length 10
using open addressing with hash function h(k) = k mod 10 and linear probing. What is the
resultant hash table?

3. AVL tree
Based on the requirements, keep this tree as the AVL tree after insertion. Please indicate the
steps.

(a) Insert node with value 7

(b) Insert node with value 15


4. Red-Black Tree
Based on the condition, keep this tree as the Red-Black Tree after the deletion and indicate the
steps.
(a) Delete node 8 in red-black tree

(b) Delete node 11

5. Detect Cycle in an undirected graph by DFS


Please give the strategy and coding in Python.
6. Find a path in a directed graph by DFS
Please give the strategy and coding in Python.

You might also like