Download as pdf or txt
Download as pdf or txt
You are on page 1of 131

LECTURE NOTES FOR

CHAPTER 9
Medians and Order Statistics

1
Selection problem

2
Selection problem

3
Selection problem

4
Selection problem

5
Selection problem

6
Selection problem

7
Selection problem

8
MINIMUM AND MAXIMUM

9
MINIMUM AND MAXIMUM

10
SELECTION IN EXPECTED LINEAR
TIME

11
SELECTION IN EXPECTED LINEAR
TIME

12
SELECTION IN EXPECTED LINEAR
TIME
p r

=4-1+1

13
SELECTION IN EXPECTED LINEAR
TIME

14
SELECTION IN EXPECTED LINEAR
TIME

15
SELECTION IN EXPECTED LINEAR
TIME

16
SELECTION IN EXPECTED LINEAR
TIME

17
SELECTION IN EXPECTED LINEAR
TIME

18
SELECTION IN EXPECTED LINEAR
TIME

19
SELECTION IN EXPECTED LINEAR
TIME (continued)

20
SELECTION IN EXPECTED LINEAR
TIME (continued)

21
SELECTION IN EXPECTED LINEAR
TIME (continued)

22
SELECTION IN EXPECTED LINEAR
TIME (continued)

23
ANALYSIS

24
ANALYSIS

25
ANALYSIS

26
ANALYSIS

27
SELECTION IN WORST-CASE LINEAR TIME

28
SELECTION IN WORST-CASE LINEAR TIME
(continued)

29
SELECTION IN WORST-CASE LINEAR TIME
(continued)

[Each column is a group of 5


elements. Arrows point from
smaller elements to larger
elements. The group medians are
the middle fifth of the array, shown
in the figure with heavy outlines in
the middle row.]

30
SELECTION IN WORST-CASE LINEAR TIME
(continued)

[Each column is a group of 5


elements. Arrows point from
smaller elements to larger
elements. The group medians are
the middle fifth of the array, shown
in the figure with heavy outlines in
the middle row.]

31
SELECTION IN WORST-CASE LINEAR TIME
(continued)

32
SELECTION IN WORST-CASE LINEAR TIME
(continued)

33
SELECTION IN WORST-CASE LINEAR TIME
(continued)

34
SELECTION IN WORST-CASE LINEAR TIME
(continued)

35
ANALYSIS

36
ANALYSIS

37
ANALYSIS

38
ANALYSIS (continued)

39
Design and Analysis of
Algorithms
Greedy
Interval scheduling
Interval scheduling

Suppose
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
Interval scheduling
The algorithm
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
The algorithm in action
Correctness
Greedy allocation stays ahead
Greedy allocation stays ahead
Greedy allocation stays ahead
Greedy allocation stays ahead
Greedy allocation stays ahead
Greedy allocation is optimal

i1 ik

j1 jk jm
Greedy allocation is optimal
Implementation, complexity
Implementation, complexity
Implementation, complexity
Fractional Knapsack
Problem
Knapsack problem

Given a set of items, each


with a weight and a value,

Determine which items to


include in collection so that

1. Total weight is less than


or equal to a given limit
2. Total value is as large as
possible.
Fractional Knapsack Problem
Example
Example
Example
Example
Example
Example
Example
Greedy Solution for Fractional Knapsack
Greedy Solution for Fractional Knapsack
Greedy Solution for Fractional Knapsack

M
Greedy Solution for Fractional Knapsack

M
Greedy Solution for Fractional Knapsack

M
Greedy Solution for Fractional Knapsack

M
Greedy Solution for Fractional Knapsack

M
Greedy Solution for Fractional Knapsack
Correctness (1)
Correctness (1)
Correctness (1)
Correctness (1)
Correctness (1)

M
Correctness (1)

i
Correctness (1)

M
Correctness (1)

M
Correctness (1)

M
Correctness (2)

O′ = (y1′ , y2′ , ..., yn′ )


i
Correctness (2)
Correctness (2)
Correctness (2)
Correctness (2)
Correctness (2)
Correctness (2)

You might also like