Escolar Documentos
Profissional Documentos
Cultura Documentos
Basic Terminologies
[You might
Efficiency
A solution is said to be efficient if it solves the
problem within its resource constraints. [Alt:
Better than known alternatives (relatively efficient)]
space
time
[This does not mean always strive for the most efficient
program. If the program operates well within resource
constraints, there is no benefit to making it faster or smaller.]
[Data +
Overhead]
[Some data
Definitions
A type is a set of values.
[Ex: Integer, Boolean, Float]
Data Type
ADT:
Type
Operations
Data Items:
Logical Form
Data Structure:
{ Storage Space
{ Subroutines
Data Items:
Physical Form
[In this class, we frequently move above and below the line
separating logical and physical forms.]
Problems
Problem: a task to be performed.
Best thought of as inputs and matching
outputs.
Problem definition should include
constraints on the resources that may be
consumed by any acceptable solution. [But
NO constraints on HOW the problem is solved]
[A
Mathematical Background
[Look over Chapter 2, read as needed depending on your
familiarity with this material.]
sequence may]
Recursion
Induction proofs
Logarithms
default base.]
Summations
Algorithm Efficiency
There are often many approaches (algorithms)
to solve a problem. How do we choose between
them?
At the heart of computer program design are
two (sometimes conflicting) goals:
1. To design an algorithm that is easy to
understand, code and debug.
2. To design an algorithm that makes efficient
use of the computers resources.
Goal (1) is the concern of Software
Engineering.
Goal (2) is the concern of data structures and
algorithm analysis.
When goal (2) is important, how do we
measure an algorithms cost?
Programmers effort
Compiler
[Constant cost]
Example 3:
sum = 0;
for (i=1; i<=n; i++)
for (j=1; j<=n; j++)
sum++;
[Cost: T(n) = c1 n2 + c2 Roughly n2 steps, with sum being n2 at
the end. Ignore various overhead such as loop counter
increments.]
2n
2n2
5n log n
1200
20n
1000
800
600
10n
400
200
0
10
20
30
40
2n
50
2n2
400
20n
300
5n log n
200
10n
100
0
0
Input size n
10
15
Worst Case:
Average Case:
T(n)
n
n
Change
n/n
10n
1, 000 10, 000 n = 10n
10
= 10n
20n
500 5, 000 n
10
5n log n
250 1, 842
10n< n < 10n 7.37
2n2
70
223 n = 10n
3.16
13
16 n = n + 3
2n