Searching, Sorting, and Complexity Analysis Flashcards

1
Q

Things to desire in a program

A

Correctness, Robustness, Maintainability, Efficiency

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

Two ways to measure efficiency

A

Empirical and Analytical

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

What is empirical measurement?

A

Using a clock to get actual running times for different inputs

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

Empirical problems

A

Different machines have different running times

Some running times are so long that it is impractical to check them

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

What is analytical measurement?

A

Using pencil and paper to determine the abstract amount of work that a program does for different inputs

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

Analytical advantages

A

Machine independent

Can predict running times of programs that are impractical to run

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

What is complexity analysis?

A

Pick an instruction that will run most often in the code

Determine the number of times this instruction will be executed as a function of the size of the input data

Focus on abstract units of work, not actual running time

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

Searching for the minimum

A

Most often instruction: assignment (=)

For a list of length n, n assignments: O(n)

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

What is Big-O notation?

A

Big-O notation expresses the amount of work a program does as a function of the size of the input

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

What does O(N) stand for?

A

O(N) stands for order of magnitude N, or order of N for short

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

Common orders of magnitude

A

Constant: O(k)

Logarithmic: O(log2(n))

Linear: O(n)

Quadratic: O(n^2)

Exponential: O(k^n)

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

Examples of approximation

A

N + K goes to N

N/K and N*K go to N

Use the highest degree term in a polynomial and drop the others: (N^2 - N)/2 goes to N^2

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

Sequential search vs. Binary search

A

O(n) vs. O(log2(n))

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

Selection sort

A

Withing minInRange, a loop runs n - i times

minInRange runs n times

(n^2 - n)/2 goes to O(n^2)

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

Regular fib(n)

A
fib(n) = 1, when n = 1 or n = 2
fib(n) = fib(n -1) + fib(n - 2) otherwise

Somewhere between 1^n and 2^n

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