Ch. 7 Flashcards

(11 cards)

1
Q

Space-for-time algorithms

A
  1. Input enhancement - store extra information to be used later in problem solving i.e. counting sorts and string search
  2. Prestructuring - make accessing elements easier i.e. hashing or B-trees
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Sorting by Counting

A

For each item, count how many items are less than the item, and that will be its final position.
O(n^2)

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

Distribution Counting Sort

A
  1. Count # of items of each value
  2. Count the # of items ≤ each value
  3. Move all items to their exact final position
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Horspool’s Algorithm

A

Search for a string pattern within a text:
- Preprocess the pattern to generate a shift table that determines how much to shift the pattern when a mismatch occurs.
- Always makes a shift based on the text’s character c aligned with the last character in the pattern.

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

Boyer-Moore Algorithm

A

Search for a string pattern within a text:
- Create a bad-symbol table for how much to shift upon a mismatch
- Create a good-suffix table for how much to shift based on the matched part of the pattern.

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

Hashing

A

Very efficient method for implementing a dictionary. Map keys of a given file of size n into a table of size m using a predefined hash function.

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

Collisions

A

Two different keys have the same hash address.

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

Open Hashing

A

Each cell is a header of a linked list of all keys hashed to it.

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

Closed hashing

A
  • One key per cell
  • In case of collision, find another cell by linear probing or double hashing
  • Only works if table size m ≥ number of keys n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Linear probing

A

Occupy the next available cell, and wrap back to the beginning of the table when the end is reached.

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

B-tree

A

Similar to 2-3 tree, but each node may have up to m children in an m-way tree.
1. Number of keys in each non-leaf node is one less than the number of its children.
2. All non-leaf nodes except root have at least ⌈m/2⌉ children
3. Root is a leaf or has anywhere from two to m children.
4. Leaf node has no more than m-1 keys.
5. m must be odd.

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