(6) Hash Tables and Trees Flashcards

1
Q

Definition Hash Table

A

A hash table is composed of a key and a bucket of unfixed size for elements:

  • realised as list with the key and lists
  • every element in a bucket is associated with the respective key
  • the hash function determines the mapping key
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are advantages of hash tables?

A
  • Adding elements is efficient O(1): Compute hash value and add element to the corresponding bucket
  • Retrieving elements is easy (O(n) worst case): Compute has value, find corresponding key and look into the bucket
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Why is it important to choose a good hash function and how does it look like?

A
  • a good hash function should distribute the data evenly among the buckets
  • clusters increase the worst case search time
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the basic concept of trees?

A
  • order data in a hierarchical manner
  • elements can be easily inserted at the end (leafs) (more effort to insert anywhere)
  • Elements can be removed
  • Searching is efficient
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Definition Node

A

Any element of the tree

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

Definition Root

A

Topmost node of the tree

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

Definition Parent

A

Node that has one or more children

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

Definition Child

A

Node that has a connected node above it

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

Definition Leaf

A

Node that does not have any children

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

Definition Subtree

A

Parent and all the node below it

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

What is a binary search tree?

A
  • Tree in which every parent node has at most two children
  • Every node holds a value and a total order is defined
  • The left child value (and all values in the left subtree) are always smaller than the right child value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a balanced tree?

A

One part of the tree has a height that is at most 1 larger than the height of the other part of the tree.

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

What is the advantage of a binary search tree?

A

Allows to look up elements efficiently

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

What is the height of a tree?

A

The length of the longest path starting from the root and ending at a leaf (count edges)

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

How fast is searching a binary tree?

A

Balanced Tree: O(log n) given height h

Unbalanced Tree: O(n)

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

What is a disadvantage of trees?

A

Not all data can be stored in a hierarchical manner (e.g. connections between cities).