Professional Documents
Culture Documents
If a fn 𝑓 𝑛 is 𝑂 𝑔 𝑛 then ∃ a const 𝐶 ∋ 𝑓 𝑛 ≤ 𝐶 ∗ 𝑔 𝑛 ∀ 𝑛 ≥ 𝑛0
If a fn 𝑓 𝑛 is 𝛺 𝑔 𝑛 then ∃ a const 𝐶 ∋ 𝑓 𝑛 ≥ 𝐶 ∗ 𝑔 𝑛 ∀ 𝑛 ≥ 𝑛0
Problem: How much extra memory is needed by the linked list in comparison with an array for
storing the same amount of data? Show your calculations.
A linked list only stores the address of the next contiguous block.
A doubly linked list stores both, the address of the next contiguous block and the address of
the previous contiguous block.
Problem: Show by means of an example the advantage of using a doubly linked list.
A circular doubly linked list is a combination of circular and doubly linked lists.
We will learn about representing rooted trees with linked data structures
➢ Rooted binary trees
➢ Rooted trees in which each node can have an arbitrary # of children
However there is a smart way of achieving this which takes 𝑂 𝑁 memory only. It is called left-
child, right-sibling representation for a rooted tree with unbounded branching:
Each node 𝑥 has only 2 pointers instead of pointers for each of its children.
𝑥. 𝑙𝑒𝑓𝑡 − 𝑐ℎ𝑖𝑙𝑑 points to the leftmost child of node 𝑥
𝑥. 𝑟𝑖𝑔ℎ𝑡 − 𝑠𝑖𝑏𝑙𝑖𝑛𝑔 points to the sibling of 𝑥 immediately to its right
If a node 𝑥 does not have any child then 𝑥. 𝑙𝑒𝑓𝑡 − 𝑐ℎ𝑖𝑙𝑑 = 𝑁𝐼𝐿.
If a node 𝑥 is the rightmost child of its parent then 𝑥. 𝑟𝑖𝑔ℎ𝑡 − 𝑠𝑖𝑏𝑙𝑖𝑛𝑔 = 𝑁𝐼𝐿.
In the worst case, searching for an element in the hash table takes the same time as that in a
linked list, Θ 𝑛 , under some reasonable assumptions, it takes, on an average, only 𝑂 1 .
Deletion takes 𝑂 1 time if the list is a doubly-linked list. If it were a singly-linked list then it
𝑛
will take 𝑂 time.
𝑚
Problem: If array length is 𝑚 and key hashes are independent then what is the probability that
2 distinct keys collide?
Solution: A priori, a key 𝑘𝑒𝑦1 goes into any of the 𝑚 cells.
Similarly, key 𝑘𝑒𝑦2 goes into to any of the 𝑚 cells (and, so on).
For a collision to happen, 𝑘𝑒𝑦2 must go into the same sell as 𝑘𝑒𝑦1 was already in. The
1
probability of this is as 𝑘𝑒𝑦2 could have gone into any of the 𝑚 cells.
𝑚
𝑛
For each cell, 𝑗, the length of list is T 𝑗 is 𝑛𝑗 . 𝑈 = 𝑛0 + 𝑛1 + ⋯ +𝑛𝑚−1 = 𝑛. E 𝑛𝑗 = 𝛼 = .
𝑚
Successor & Predecessor: the successor of a node is the next node visited in an inorder tree
walk. The structure of a binary search tree allows you to determine the successor of a node
without comparing keys.