ANALYSIS OF ALGORITHMS Flashcards

1
Q

What is an algorithm?

A

An algorithmis a step-by-step procedure for solving a problem in a finite amount of time.

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

What does analyzing an algorithm entail

A

• Developing a formula for predicting how fast an algorithm is, based
on the size of the input (time complexity), and/or • Developing a formula for predicting how much memory an algorithm requires, based on the size of the input (space complexity)

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

What does “size of the input” mean?

A

• We choose the “size” to be the parameter that most
influences the actual time/space required• It is usually obvious what this parameter is
• Sometimes we need two or more parameters

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

Why is it better to use worst case for analysis?

A

• Average case time is often difficult to determine. (is not well defined eg sorting an array How out of order is the “average” unsorted array? )
• Easier to analyze
• Crucial to applications such as
games, finance and robotics

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

What are the two ways of Analyzing Time Efficiency of an Algorithm

A
  • Experimental study

* Theoretical analysis

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

Describe the experimental studies approach to analysis of time complexity

A

• Write a program implementing the algorithm
• Run the program with inputs of varying size and composition
• Use a method like
System.currentTimeMillis() to get an accurate measure of the actual running time
• Plot the results

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

What are the limitations of using the experimental studies approach to analysis of time complexity

A
  • It is necessary to implement the algorithm, which may be difficult
  • Results may not be indicative of the running time on other inputs not included in the experiment.
  • In order to compare two algorithms, the same hardware and software environments must be used
  • Must run on many data sets to see effects of scaling
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Describe the theoretical analysis approach to evaluating time efficiency

A

• Uses a high-level description of the algorithm instead of an
implementation
• Characterizes running time as a function of the input size, n. • Allows us to evaluate the speed of an algorithm
independent of the hardware/software environment

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

How is the Theoretical Analysis of Time Efficiency done. Include the formulae

A

Time efficiency is analyzed by determining the number of
repetitions of the primitive operation as a function of input size

T(n) = cop C(n)
where:
n- input size
T-running time
cop- execution time for basic operation
C- number of times basic operation is executed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a primitive/basic operation

A

the operation that contributes most towards the running time of the algorithm

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

What is the problem if counting operations as a way of time complexity analysis

A
  • Hard to analyze
  • Precise information may not be needed ie Precise details less relevant than order growth
  • May not know times (or relative times) of steps
  • Only gives results within range: aC(n) < T(n) < bC(n)
  • More interested in growth rates with respect to n ((i.e Big O) )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the asymptotic order pf growth

A

how number of basic ops GROWS as n increases
The asymptotic analysis of an algorithm determines the running time in big-Oh notation
• To perform the asymptotic analysis we find the worst-case number of primitive operations executed as a function of the input size
• We then express this function with big-Oh notation•

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

Give examples of important functions that often appear in algorithm analysis

A
  • Constant - 1
  • Logarithmic -log n
  • Linear -n
  • N-Log-N - n log n
  • Quadratic - n^2
  • Cubic - n^3
  • Exponential - 2^n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Differentiate between best case, average case and worst case

A

Best case is the function which performs the minimum number of steps on input data of n elements. Worst case is the function which performs the maximum number of steps on input data of size n. Average case is the function which performs an average number of steps on input data of n elements.

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

Explain any four elements that affect the running time of algorithms

A

size of input
the hardware environment and the software environment.
Number of primitive operations
Asymptotic order of growth of the algorithm

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

A loop invariant is some predicate (condition) that holds for every iteration in the loop.
Discuss the three properties of a loop invariant.

A

Initialization: The loop invariant must be true before the first execution of the loop.
Maintenance: If the invariant is true before an iteration of the loop, it should be true also after the iteration.
Termination: When the loop is terminated the invariant should tell us something useful, something that helps us understand the algorithm.

17
Q

Draw graphs depicting different orders of growth

A

*See PHONE for pic