Ch2 ppt Fundamentals of Analysis of Algorithm Efficiency Flashcards

1
Q

The time required by the algorithm

A

Time efficiency/ complexity

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

The time required by the algorithm

A

space efficiency/complexity

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

Analyzing the running time efficiency of algorithms
What to analyze?

A

The size of the input is the main consideration for analyzing the
running time,

Count the number of times each of the algorithm’s operations (of
loops/recursions) is executed

The running time of algorithms can be different. Best case of the
running time is of little interest, average case is difficult to
calculate (not apparent what constitutes an “average” input for a
problem, worst case representing the running time, that is, the
longest running time for any input size, n.

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

The eight most important functions, f(n), used in the
analysis of algorithms

A

– The Constant Function (1)
– The Logarithm2
Function (log2n)
– The Linear Function (n)
– The N-Log2
-N Function (nlog2n)
– The Quadratic Function (n2)
– The Cubic Function and Other Polynomials (n3)
– The Exponential Functions (2n)
– The Factorial Functions (n!)

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

the constant function

A

f(n) = c for some fixed constant c where n is the input
size.

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

The logarithm function

A

f(n) = log2n = x if and only if 2
x = n where 2 is the
base and n represents the input size.
– By definition, log{2}1 = 0

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

the linear function

A

f(n) = log2n = x if and only if 2
x = n where 2 is the
base and n represents the input size.
– By definition, log21 = 0

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

the N-log{2}-N function

A

f(n) = n log2 n where n is the input size.

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

The quadratic function

A

f(n) = n^2 where n is the input size.

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

the cubic function and other polynomials

A

f(n) = n^3 where n is the input size.

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

the exponential function

A

f(n) = 2^n, 3^n , …, or n^n where n represents the
input size.

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

factorial function

A

f(n) = n! where n represents the input size.

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

Notations used to describe the
running time of algorithms

A

asymptotic notation

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

O-notation (upper bound)

A

Let f(n) and g(n) be functions that f(n) is bounded above
by some constant multiple of g(n)

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

Omega notation (lower bound)

A

Let f(n) and g(n) be functions that f(n) is bounded
below by some constant multiple of g(n)

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

theta notation (average bound)

A

Let f(n) and g(n) be functions that f(n) is bounded both
above and below by some constant multiple of g(n)

16
Q

General plan for analyzing the time-efficiency of
nonrecursive algorithms

A

– Determine the input size, n
– Identify the algorithm’s loops
– Count the number of times the loops is executed using
frequency count method depending on the worst-case or
best-case efficiency
– Sep up a sum expressing the number of times the
algorithm’s loops is executed
– Find its order of growth

17
Q

many algorithms are recursive in nature.
A ____ _____ is used to describe the overall running
time of recursive algorithms on inputs of sizes.

A

recurrence relation

18
Q

in ____ _____, to sort a given array, we divide it in two
halves and recursively repeat the process for the two halves. Finally
we merge the results. The recurrence relation of the running time of
Merge Sort can be written as T(n) = 2T(n/2) + cn.

A

Merge Sort

19
Q

Plan for analyzing the time-efficiency of recursive algorithms

A

– Determine the input size, n
– Identify the algorithm’s recursions
– Count the number of times the recursions is executed
depending on the worst-case or best-case efficiency
– Sep up a recurrence relation expressing the number of
times the algorithm’s recursions is executed
– Solve the recurrence

20
Q

recursive algorithm substitution method:
Forward substitution method

A

we solve the recurrence relation
for n = 0, 1, 2, … until we see a pattern. Then we make a
guesswork, predict the running time, and verify the guesswork is
correct by using the induction.

21
Q

recursive algorithm substitution method:
Backward substitution method

A

we solve the recurrence relation
for n = n, n-1, n-2, … or n = n, n/2, n/4, … until we see a pattern.
Then we make a guesswork, predict the running time, and verify
the guesswork is correct by using the induction.

22
Q

forward substitution method

A

Compute the factorial function f(n) = n! for an arbitrary
nonnegative integer n >= 1.

23
Q

Draw a recurrence tree and
calculate the time taken by every level of tree. Finally, sum
the work done at all levels. To draw the recurrence tree,
start from the given recurrence and keep drawing till find a
pattern among levels. The pattern is typically a arithmetic
or geometric series

A

recurrence tree method

24
Q

steps to solve the recurrence
relation using recursion tree method.

A

– Create a recursion tree from the recurrence relation
– Calculate the work done in each node of the tree
– Calculate the work done in each level of the tree (this can
be done by adding the work done in each node
corresponding to that level).
– The sum over the work done in each level to get the
solution.

25
Q

The running time is equal to the running time
of the two recursive calls plus the linear time
spent in the partition.
T(N) = T(i) + T(N-i-1) + cN
where T(0) = T(1) = 0 and
i = the number of elements in one partition

A

Quick-sort

26
Q
A