Ch. 6 Flashcards

(27 cards)

1
Q

Transform and Conquer

A

Solve a problem by transformation via
1. Instance Simplification
2. Representation Change
3. Problem Reduction

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

Instance Simplification

A

Transform to a simpler/more convenient instance of the same problem.
- Presorting

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

Representation Change

A

Transform to a different representation of the same instance.

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

Problem Reduction

A

Transform to a different problem for which an algorithm is already available.

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

Presorting

A

Instance simplification method to solving complex tasks like searching, computing median, element uniqueness, etc.

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

Presorting for searching

A
  1. Sort the array by an efficient sorting algo
  2. Apply binary search
    O(nlogn) more efficient in the long-term
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Presorting for element uniqueness

A
  1. Sort the array by an efficient sorting algo
  2. Scan array for pairs of adjacent elements
    O(nlogn) better than O(n^2)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Binary Search Tree

A

A binary tree in which the key of an internal node is greater than the keys in its left subtree and less than or equal to the keys in its right subtree.

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

Dictionary Operations on BST

A

Searching
Insertion - search and insert where search terminated
Deletion - delete leaf, delete node w/ one child, delete node w/ 2 children.

Worst cases: O(n)
Average cases: O(logn)

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

Pre-order traversal

A

Root, left, right

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

In-order traversal

A

Left, root, right
Produces a sorted list

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

Post-order traversal

A

Left, right, root

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

AVL tree

A

A BST in which, for every node, the balance factor is at most 1.

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

Balance factor

A

The difference between the heights of a node’s left and right subtrees.

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

Single R rotation

A

Performed after a new key is inserted into the left subtree of the left child of a tree whose root had the balance of +1 before its insertion.

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

Single L rotation

A

Performed after a new key is inserted into the right subtree of the right child of a tree whose root had the balance of -1 before its insertion.

17
Q

Double LR rotation

A

Performed after a new key is inserted into the right subtree of the left child of a tree whose root had the balance of +1 before its insertion. Perform the L rotation of the left subtree followed by the
R rotation of the root.

18
Q

How to perform tree rotations

A

Rotate the edge connecting the root and its (left or right) child.

19
Q

Double RL rotation

A

Performed after a new key is inserted into the left subtree of the right child of a tree whose root had the balance of -1 before its insertion. Perform the R rotation of the right subtree followed by the L rotation of the root.

20
Q

2-3 trees

A

May have 2 nodes and 3 nodes, and all leaves are on the same level.

21
Q

Heap

A

A binary tree with keys at its nodes such that it is near-complete (only the rightmost nodes at the bottom level are missing)
Every key is greater than the keys of its children

22
Q

Heap array representation

A

Root node at position 1
A node at position j has its left child at 2j, right child at 2j+1, and parent at ⌊j/2⌋

23
Q

Priority Queue

A

Ordered set with operations:
find element with highest priority
delete element with highest priority
insert element with assigned priority
Heaps can implement them

24
Q

Heap construction

A

Bottom-up: put everything in then fix
Top-down: successively insert elements into an initially empty heap

25
Bottom-up
0. Initialize the structure with keys in the order given. 1. Starting with rightmost parental node, fix the heap rooted at it and keep exchanging with largest child until heap condition holds. 2. Repeat step 1 for preceding parental node. O(n)
26
Top-down
1. Insert element at last position in heap 2. Compare with parent and exchange if it violates heap condition 3. Continue comparing the new element with nodes up the tree until the heap condition is satisfied O(nlogn)
27
Heapsort
1. Build heap 2. Remove root by exchanging with rightmost leaf 3. Fix up heap excluding the last leaf. O(nlogn)