Answers part 1:
Base: For N=1N=1 the proof is simple, we can see that the number of leaves =1=1 and the numberof internal vertices =0=0, 0 + 1 = 1 thus the assumption is correct for the base case.
Assume: We'll assume that for N∈NN∈N the number of leaves is greater by one than the numberof internal vertices, and prove for N+2N+2 (since N+1N+1 will make the tree non-full).
Proof: Let TT be a full binary tree over N+2N+2 leaves. We'll arbitrary choose an internal vertice
and trim it's leaves, now we have TʹTʹ a tree on NN leaves and according to the assumption we
know that the number of leaves is larger by 11 than the number of internal vertices. If we let n
ʹ1n1ʹ be the number of leaves in TʹTʹ and nʹ2n2ʹ be the number of internal vertices in TʹTʹ we get
that nʹ1=nʹ2+1n1ʹ=n2ʹ+1 from the assumption. Now if we recover the trimmed leaves we get that:
And since the proportions are kept, we know that n1=n2+1
20: AVL is said to be balanced because the difference in height between the left and the right
subtree of a node is at most 1
Redblack trees are said to be balanced because at any time the length of the longest path from rootto leaf is at most twice the length of the shortest path.
1. -Initially, root node is black
2. Leaves are black and contain the null value
3. Both children of a red node are blak nodes
4. Each path from root to leaf contains the same amount of black nodes
Min-heap is a tree-based data structure, in which the key of a node is always greater than or equalto the key of the node's father. Heap is the most efficient implementation of the priority queuestructure, and is usually implemented as a binary tree whose root is the smallest value. There is noimplied ordering between sibling nodes and no implied order for a traversal.
Since the minimum value is stored in the root of a minheap, to delete the minimum value the root
must be deleted. Then, the last value in the array is copied to the root, and it is taken to its place
with a sifting procedure:
1. if it has no children, sifting is over
2. if it has one child, check if the heap property is broken and if it is swap its position withi its
child's, and sift down the child.
3. If it has two children, choose the smallest and swap-sift if the heap property is broken
To find the max value in a minheap, I would insert the value with inverted sign. This would allowme to find the maximum as I would have found the minimum and this would maintain the sametime complexity for the insert-delete-retrieval operations.
Navigate the tree knowing that each level can be a min or a max level
the goal of a good hash function is to map a set of values in a smaller set avoiding as much as
possible to have different values mapped into the same key.
Open addressing (probing): finding the closest empty bucket in case of conflicts
Chaining: consists of an array in which each slot contains the link to a single linked list containingkey-value pairs with the same hash. When a new value with the same hash is inserted, it isappended at the end of the corresponding list
if (heap_size<= 0)
if (heap_size == 1)
// Store the minimum value, and remove it from heap
introot = heap_data;
heap_data  = heap_data[heap_size-1];
// A recursive method to heapify a subtree with root at given index
intl = left(i);
intr = right(i);
intsmallest = i;