Searching and Tables Flashcards

1
Q

What are common names for data structures that allow for efficient searching?

A
  • Associative array
  • Map
  • Dictionary
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are data structures in the table ADT?

A
  • Associative array
  • Dictionary
  • Map
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are basic operations of table ADTs?

A
  1. construct (initialize) a table
  2. search and retrieve for an entry
  3. update record (doesn’t change key)
  4. insert and delete (dynamic operations)
  5. enumerate all (usually unsorted)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Binary search example

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

Basic table ADT operations and worst case running times on a table of n elements are:

A
  1. Construct (initialize) a table; requires sorting Θ(n lg n)
  2. Search and retrieve an entry; binary search Θ(lg n)
  3. Update record (doesn’t change key); binary search Θ(lg n)
  4. Insert and delete (dynamic operations); shift array Θ(n)
  5. Enumerate all (here it will be sorted); scan array Θ(n)

we can improve running of number 4 to O(lg n) by using a different data structure i.e. binary tree or hash table

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

What is a BST?

A

A binary search tree (BST) is a binary tree that satisfies the following ordering relation: for every node ν in the tree, the values of all the keys in the left subtree are smaller than (or equal, if duplicates allowed) to the key in ν and the values of all the keys in the right subtree are greater than the key in ν.

Left subtree has smaller valued nodes then right subtree

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

Searching and Inserting example

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

Illustrating Removal of Nodes in a BST

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

The search, retrieval, update, insert and remove operations in a BST all take what time?

A

O(h) in the worst case, where h is the height of the tree

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

The search, retrieval, update, insert and remove operations in a well-balanced BST

A

Θ(lg n)

dynamic operations of insertion and deletions may destroy balance, degrading performance to Ω(n)

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

What technique is used to make sure worst case does not occur in BST?

A

balancing

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

Left and right rotation of BST

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

What is an AVL tree?

A

An AVL tree is a binary search tree with the additional balance property that the tree is balanced

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

What is the height of an AVL tree with n nodes?

A

Θ(log n)

(AVL trees are more rigidly balanced than red-black trees so good for applications with more prominent search-only operations)

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

What is a red-black tree?

A

A red-black tree is a binary search tree such that every node is colored either red or black and every non-leaf node has two children. In addition, it satisfies the following properties:

  • the root is black;
  • all children of a red node must be black;
  • every path from the root node to a leaf must contain the same number of black nodes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

If every path from the root to a leaf contains b black nodes then how many black nodes are in the tree?

A

at least 2b − 1 black nodes

17
Q

What is the max height of a red-black and thus the search time?

A

height: 2lg n

search time: O(log n)

18
Q

Red-black tree example

A
19
Q

What is a B-Tree?

A

A B-tree of order m is an m-ary tree such that:

  • the root is either a leaf or it has between 2 and m children;
  • each nonleaf node (except possibly the root) has between dm/2e and m children inclusive;
  • each nonleaf node with µ children has µ − 1 keys;
  • all leaves are at the same depth; • data items are stored in le
20
Q

What are B-Trees used for?

A

• A B-tree implements the table API but used for external/slow devices such as disks (or cloud)

21
Q

2-4 B-Tree example

A