Hansung Flashcards

1
Q

What is a heap?

A

A binary tree with two constraints
- It is complete
- Each child has a value “greater than or equal to” it sparent

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do you add to a heap?

A
  • add the element to the next available space in the tree
  • Percolate the value up the tree to maintain the correct ordering
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What data structures use heaps?

A

Priority Queues

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does removeMin work on priority queues?

A
  • Pop the root
  • Replace it with the last element in the heap
  • Percolate this element down to the bottom of the heap choosing the minimum child
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How do we navigate a heap?

A
  • The root of the tree is at array location 0
  • The last element is size()-1
  • The parent of a node k is at floor((k-1)/2)
  • The children of node k are at array locations 2k + 1 and 2k + 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the time complexity of perlocating in a heap?

A

Ɵ(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the time complexity of the height of the tree?

A

Ɵ(log(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the time complexity of add/removeMin on a heap?

A

Ɵ(log(n)) in worst case
Ɵ(1) normally

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the worst case time complexity of Heap sort?

A

O(n log(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the space complexity of heap sort?

A

O(1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a B-tree?

A

Balanced multiway trees made for fast search, finding successors/predecessors, insert, delete, maximum, minimum

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are M-way trees?

A

Trees where each non-leaf node has M children

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the access time of a M-way tree?

A

Logm(n) = Log2(n)/Log2(m)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What makes B+ trees different to B-Trees

A
  • Only leaf nodes contain data pointers, while internal nodes contain keys only
  • Sequential access is possible like a linked list
  • Searching is faster
  • Insertion and Deletion are easier and faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What makes B-Trees different to B+ Trees?

A
  • All internal nodes and leaf nodes contain data pointers along with keys
  • Sequential access of nodes is not possible
  • Searching is slower
  • Insertion and Deletion take more time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What values should you use for M in B+ trees?

A

Odd numbers

15
Q

What is a Trie?

A

A multiway tree often used for storing large sets of words

16
Q

How do tries work?

A
  • They are trees with a possible branch for every letter of an alphabet
  • All words end with a special letter “$”
  • They compactify the edges in the tree in order to remove: internal and external one-way branching
17
Q

What are the uses of Tries?

A
  • Way of implementing sets
  • Provide quick insertion, deletion and find
  • Good for spell checkers, completion, algorithm
18
Q

What are the disadvantages of Tries?

A
  • Waste large amounts of memory
19
Q

How are Binary Tries different from Normal Tries?

A

They speeds up finds but loses the advantage of multiway trees by reducing the depth

20
Q

Why use Tries?

A
  • Classic memory, time complexity trade-off
  • Specialist
  • Not too complicated to implement