Ch2: Getting Started Flashcards

1
Q

Pseudocode for InsertionSort(A)

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

How do you prove pseudocode is correct? (in general)

A

Formulate a predicate that shows the algorithm is correct. The predicate must be related to the pseudocode and reflect the pseudocode’s inputs.

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

Predicate

A

The statement we wish to prove

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

Loop invariant

A

A condition that is true immediately before each iteration of a loop.

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

What 3 things must we show about a loop invariant in proving an algorithm?

A

Initialization, Maintenance, and Termination

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

Initialization (Loop invariant)

A

Loop Invariant is true prior to the first iteration of the loop

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

Maintenance (Loop Invariant)

A

If the Loop Invariant is true before an iteration of the loop, it remains true before the next iteration

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

Termination (Loop Invariant)

A

When the loop terminates, the invariant gives us a useful property that helps show that the algorithm is correct

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

Input size of an algorithm

A

Usually the number of items in the input (sorting), or sometimes the number of bits needed to represent the input (integer multiplication)

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

Running time of an algorithm

A

The number of primitive operations or steps executed

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

Incremental design technique

A

Assuming a solution to the problem with a given input size exists (j-1), solve the problem for a slightly larger input (j). Thus you can start with an empty input and keep applying the solution until the problem is solved for the entire input of size n.

e.g. For insertion sort, we assume we have the sorted subarray A[1..j-1], and simply insert the single element A[j].

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

Recursive algorithms typically use this design approach

A

Divide-and-Conquer

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

3 steps of the divide-and-conquer design approach

A

Divide, Conquer, and Combine

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

Divide step

A

Divide the problem into a number of subproblems that are smaller instances of the same problem

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

Conquer step

A

Conquer the subproblems by solving them recursively. However if the subproblem sizes are small enough, just solve them in a straightforward manner.

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

Combine step

A

Combine the solutions to the subproblems into the solution for the original problem