Design and Analysis
of Algorithms
CMPS 323
SORTING BUBBLE SORT
Divide and Conquer
Algorithms and Complexity
Sorting
Sorting = ordering.
Sorted = ordered based on a particular way.
Generally, collections of data are presented in
a sorted manner.
Exampl
Design and Analysis
of Algorithms
CMPS 323
1
Some slides are
adapted from
various sources
Counting Exact
Numbers of Statements
3
Counting Primitive Operations
Algorithm arrayMax(A , n)
currentMax A [0]
for (i =1; i<n; i+)
# operations
?
?
if A [i] > curre
ALGORITHMS
DESIGN AND
FLOWCHARTS
A QUICK REVIEW
Slides are adapted
from various sources
ALGORITHMS AND FLOWCHARTS
Programming task is divided into two phases:
Problem solving phase
Develop
an algorithm.
Implementation phase
Implement
the algorithm in so
DYNAMIC
PROGRAMMING
Slides are adapted
from various sources
Dynamic Programming
Start from Bottom-up.
Split the problem into overlapping problems called
stages.
Each stage consists of states.
Evaluate all the states for every stage and select
the best.
Re
Design and Analysis
of Algorithms
CMPS 323
1
Some slides are
adapted from
various sources
Mathematics
Part-1 + Part-2+Part-3
3
Sequence: Sequential Statements
sum = sum + 1;
x+;
sum = sum + x;
Number of operations: ?
4
Sequence
sum = sum + 1;
x+;
sum = su
Design and Analysis
of Algorithms
CMPS 323
SORTING
Algorithms and Complexity
1
Some slides are
adapted from
various sources
Sorting
Algorithms
3
Sorting
Sorting is the process by which data is
arranged according to its values
(keys).
We are surrounded by
Design and Analysis
of Algorithms
CMPS 323
1
Some slides are
adapted from
various sources
Mathematics
3
Fibonacci Numbers
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, .
where each number is the sum of the preceding two.
Recursive definition:
F(0) = 0;
F(1) = 1;
F(
Design and Analysis
of Algorithms
CMPS 323
Branch and Bound
1
Some slides are
adapted from
various sources
FROM THEORY
TO
APPLICATIONS
LINEAR
PROGRAMMING
LINEAR
PROGRAMMING
Maximizing or Minimizing
an objective function
based on a set of constraints
LINEA