Free Essay

Introduction to Algorithm

In:

Submitted By mytaison
Words 3591
Pages 15
4. G REEDY A LGORITHMS I
‣ coin changing
‣ interval scheduling
‣ scheduling to minimize lateness
‣ optimal caching

Lecture slides by Kevin Wayne
Copyright © 2005 Pearson-Addison Wesley
Copyright © 2013 Kevin Wayne http://www.cs.princeton.edu/~wayne/kleinberg-tardos Last updated on Sep 8, 2013 6:30 AM

4. G REEDY A LGORITHMS I
‣ coin changing
‣ interval scheduling
‣ scheduling to minimize lateness
‣ optimal caching

Coin changing
Goal. Given currency denominations: 1, 5, 10, 25, 100, devise a method to pay amount to customer using fewest number of coins.

Ex. 34¢.

Cashier's algorithm. At each iteration, add coin of the largest value that does not take us past the amount to be paid.

Ex. $2.89.

3

Cashier's algorithm
At each iteration, add coin of the largest value that does not take us past the amount to be paid.
CASHIERS-ALGORITHM (x, c1, c2, …, cn)
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

SORT

n coin denominations so that c1 < c2 < … < cn

S←φ

set of coins selected

WHILE

x > 0

k ← largest coin denomination ck such that ck ≤ x
IF

no such k, RETURN "no solution"

ELSE

x ← x – ck
S ←S∪{k}
RETURN

S

_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Q. Is cashier's algorithm optimal?
4

Properties of optimal solution
Property. Number of pennies ≤ 4.
Pf. Replace 5 pennies with 1 nickel.
Property. Number of nickels ≤ 1.
Property. Number of quarters ≤ 3.
Property. Number of nickels + number of dimes ≤ 2.
Pf.

・Replace 3 dimes and 0 nickels with 1 quarter and 1 nickel;
・Replace 2 dimes and 1 nickel with 1 quarter.
・Recall: at most 1 nickel.

5

Analysis of cashier's algorithm
Theorem. Cashier's algorithm is optimal for U.S. coins: 1, 5, 10, 25, 100.
Pf. [by induction on x]

・Consider optimal way to change ck ≤ x < ck+1 : greedy takes coin k.
・We claim that any optimal solution must also take coin k.
- if not, it needs enough coins of type c1, …, ck–1 to add up to x
- table below indicates no optimal solution can do this

・Problem reduces to coin-changing x – ck cents, which, by induction, is optimally solved by cashier's algorithm. ▪

k

ck

all optimal solutions must satisfy

max value of coins c1, c2, …, ck–1 in any OPT

1

1

P ≤ 4



2

5

N ≤ 1

4

3

10

N+D ≤ 2

4+5=9

4

25

Q ≤ 3

20 + 4 = 24

5

100

no limit

75 + 24 = 99
6

Cashier's algorithm for other denominations
Q. Is cashier's algorithm for any set of denominations?
A. No. Consider U.S. postage: 1, 10, 21, 34, 70, 100, 350, 1225, 1500.

・Cashier's algorithm: 140¢ = 100 + 34 + 1 + 1 + 1 + 1 + 1 + 1.
・Optimal: 140¢ = 70 + 70.

A. No. It may not even lead to a feasible solution if c1 > 1: 7, 8, 9.

・Cashier's algorithm: 15¢ = 9 + ???.
・Optimal: 15¢ = 7 + 8.
7

4. G REEDY A LGORITHMS I
‣ coin changing
‣ interval scheduling
‣ scheduling to minimize lateness
‣ optimal caching

SECTION 4.1

Interval scheduling

・Job j starts at sj and finishes at fj.
・Two jobs compatible if they don't overlap.
・Goal: find maximum subset of mutually compatible jobs.

a b c d jobs d and g are incompatible

e f g h 0

1

2

3

4

5

6

7

8

9

time
10

11
9

Interval scheduling: greedy algorithms
Greedy template. Consider jobs in some natural order.
Take each job provided it's compatible with the ones already taken.

・[Earliest start time]

Consider jobs in ascending order of sj.

・[Earliest finish time]

Consider jobs in ascending order of fj.

・[Shortest interval]

Consider jobs in ascending order of fj – sj.

・[Fewest conflicts]

For each job j, count the number of

conflicting jobs cj. Schedule in ascending order of cj.

10

Interval scheduling: greedy algorithms
Greedy template. Consider jobs in some natural order.
Take each job provided it's compatible with the ones already taken.

counterexample for earliest start time

counterexample for shortest interval

counterexample for fewest conflicts

11

Interval scheduling: earliest-finish-time-first algorithm

EARLIEST-FINISH-TIME-FIRST (n, s1, s2, …, sn , f1, f2, …, fn)
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

SORT jobs by finish time so that f1 ≤ f2 ≤ … ≤ fn
A←φ
FOR j = 1

set of jobs selected

TO

n

IF job j is compatible with A
A ←A∪{j}
RETURN A
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

Proposition. Can implement earliest-finish-time first in O(n log n) time.

・Keep track of job j* that was added last to A.
・Job j is compatible with A iff sj ≥ fj* .
・Sorting by finish time takes O(n log n) time.
12

Interval scheduling: analysis of earliest-finish-time-first algorithm
Theorem. The earliest-finish-time-first algorithm is optimal.
Pf. [by contradiction]

・Assume greedy is not optimal, and let's see what happens.
・Let i1, i2, ... ik denote set of jobs selected by greedy.
・Let j1, j2, ... jm denote set of jobs in an optimal solution with i1 = j1, i2 = j2, ..., ir = jr for the largest possible value of r. job ir+1 exists and finishes before jr+1

Greedy:

i1

i2

ir

OPT:

j1

j2

jr

...

ir+1

jr+1

...

ik

jm

why not replace job jr+1 with job ir+1?
13

Interval scheduling: analysis of earliest-finish-time-first algorithm
Theorem. The earliest-finish-time-first algorithm is optimal.
Pf. [by contradiction]

・Assume greedy is not optimal, and let's see what happens.
・Let i1, i2, ... ik denote set of jobs selected by greedy.
・Let j1, j2, ... jm denote set of jobs in an optimal solution with i1 = j1, i2 = j2, ..., ir = jr for the largest possible value of r. job ir+1 exists and finishes before jr+1

Greedy:

i1

i2

ir

ir+1

...

OPT:

j1

j2

jr

ir+1

...

ik

jm

solution still feasible and optimal
(but contradicts maximality of r)
14

Interval partitioning
Interval partitioning.

・Lecture j starts at sj and finishes at fj.
・Goal: find minimum number of classrooms to schedule all lectures so that no two lectures occur at the same time in the same room.

Ex. This schedule uses 4 classrooms to schedule 10 lectures.

e

4
3

c

j g d

2

b

h

a

1

9

9:30

i

f

10

10:30

11

11:30

12

12:30

1

1:30

2

2:30

3

3:30

4

4:30

time
15

Interval partitioning
Interval partitioning.

・Lecture j starts at sj and finishes at fj.
・Goal: find minimum number of classrooms to schedule all lectures so that no two lectures occur at the same time in the same room.

Ex. This schedule uses 3 classrooms to schedule 10 lectures.

3

f

d

2

b a 1

9

9:30

j

g

c

i h e

10

10:30

11

11:30

12

12:30

1

1:30

2

2:30

3

3:30

4

4:30

time
16

Interval partitioning: greedy algorithms
Greedy template. Consider lectures in some natural order.
Assign each lecture to an available classroom (which one?); allocate a new classroom if none are available.

・[Earliest start time]

Consider lectures in ascending order of sj.

・[Earliest finish time]

Consider lectures in ascending order of fj.

・[Shortest interval]

Consider lectures in ascending order of fj – sj.

・[Fewest conflicts]

For each lecture j, count the number of

conflicting lectures cj. Schedule in ascending order of cj.

17

Interval partitioning: greedy algorithms
Greedy template. Consider lectures in some natural order.
Assign each lecture to an available classroom (which one?); allocate a new classroom if none are available.

counterexample for earliest finish time
3
2
1

counterexample for shortest interval
3
2
1

counterexample for fewest conflicts
3
2
1
18

Interval partitioning: earliest-start-time-first algorithm

EARLIEST-START-TIME-FIRST (n, s1, s2, …, sn , f1, f2, …, fn)
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

SORT lectures by start time so that s1 ≤ s2 ≤ … ≤ sn. d←0 number of allocated classrooms

FOR j = 1 TO n
IF lecture j is compatible with some classroom
Schedule lecture j in any such classroom k.
ELSE
Allocate a new classroom d + 1.
Schedule lecture j in classroom d + 1. d←d +1
RETURN schedule.
_________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

19

Interval partitioning: earliest-start-time-first algorithm
Proposition. The earliest-start-time-first algorithm can be implemented in
O(n log n) time.
Pf. Store classrooms in a priority queue (key = finish time of its last lecture).

・To determine whether lecture j is compatible with some classroom, compare sj to key of min classroom k in priority queue.

・To add lecture j to classroom k, increase key of classroom k to fj.
・Total number of priority queue operations is O(n).
・Sorting by start time takes O(n log n) time. ▪
Remark. This implementation chooses the classroom k whose finish time of its last lecture is the earliest.

20

Interval partitioning: lower bound on optimal solution
Def. The depth of a set of open intervals is the maximum number that contain any given time.
Key observation. Number of classrooms needed ≥ depth.
Q. Does number of classrooms needed always equal depth?
A. Yes! Moreover, earliest-start-time-first algorithm finds one.

depth = 3

3

f

d

2

b

1

9:30

i h e

a

9

j

g

c

10

10:30

11

11:30

12

12:30

1

1:30

2

2:30

3

3:30

4

4:30

time
21

Interval partitioning: analysis of earliest-start-time-first algorithm
Observation. The earliest-start-time first algorithm never schedules two incompatible lectures in the same classroom.
Theorem. Earliest-start-time-first algorithm is optimal.
Pf.

・Let d = number of classrooms that the algorithm allocates.
・Classroom d is opened because we needed to schedule a lecture, say j, that is incompatible with all d – 1 other classrooms.

・These d lectures each end after sj.
・Since we sorted by start time, all these incompatibilities are caused by lectures that start no later than sj.

・Thus, we have d lectures overlapping at time sj + ε.
・Key observation ⇒ all schedules use ≥ d classrooms.



22

4. G REEDY A LGORITHMS I
‣ coin changing
‣ interval scheduling
‣ scheduling to minimize lateness
‣ optimal caching

SECTION 4.2

Scheduling to minimizing lateness
Minimizing lateness problem.

・Single resource processes one job at a time.
・Job j requires tj units of processing time and is due at time dj.
・If j starts at time sj, it finishes at time fj = sj + tj.
・Lateness: ℓj = max { 0, fj – dj }.
・Goal: schedule all jobs to minimize maximum lateness L = maxj ℓj.
1

2

3

4

5

6

tj

3

2

1

4

3

2

dj

6

8

9

9

14

15

lateness = 2

d3 = 9
0

d2 = 8
1

2

d6 = 15
3

4

d1 = 6
5

6

max lateness = 6

lateness = 0

d5 = 14
7

8

9

10

d4 = 9
11

12

13

14

15

24

Minimizing lateness: greedy algorithms
Greedy template. Schedule jobs according to some natural order.

・[Shortest processing time first]

Schedule jobs in ascending order of

processing time tj.

・[Earliest deadline first]

・[Smallest slack]

Schedule jobs in ascending order of deadline dj.

Schedule jobs in ascending order of slack dj – tj.

25

Minimizing lateness: greedy algorithms
Greedy template. Schedule jobs according to some natural order.

・[Shortest processing time first]

Schedule jobs in ascending order of

processing time tj.
1
tj

1

10

dj

・[Smallest slack]

2

100

10

counterexample

Schedule jobs in ascending order of slack dj – tj.
1

2

tj

1

10

dj

2

10

counterexample

26

Minimizing lateness: earliest deadline first
EARLIEST-DEADLINE-FIRST (n, t1, t2, …, tn , d1, d2, …, dn)
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

SORT n jobs so that d1 ≤ d2 ≤ … ≤ dn. t←0 FOR j = 1 TO n
Assign job j to interval [t, t +tj]. sj ← t ; fj ← t + tj t ← t + tj
RETURN intervals [s1, f1], [s2, f2], …, [sn, fn].
__________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________

max lateness = 1

d1 = 6
0

1

d2 = 8
2

3

4

d3 = 9
5

d4 = 9
6

7

8

d5 = 14
9

10

11

12

d6 = 15
13

14

15

27

Minimizing lateness: no idle time
Observation 1. There exists an optimal schedule with no idle time.

d=4
0

1

d=6
2

3

d=4
0

1

4

d = 12
5

d=6
2

3

6

7

8

9

10

11

8

9

10

11

d = 12
4

5

6

7

Observation 2. The earliest-deadline-first schedule has no idle time.

28

Minimizing lateness: inversions
Def. Given a schedule S, an inversion is a pair of jobs i and j such that: i < j but j scheduled before i. inversion j

fi

i

[ as before, we assume jobs are numbered so that d1 ≤ d2 ≤ … ≤ dn ]

Observation 3. The earliest-deadline-first schedule has no inversions.
Observation 4. If a schedule (with no idle time) has an inversion, it has one with a pair of inverted jobs scheduled consecutively.

29

Minimizing lateness: inversions
Def. Given a schedule S, an inversion is a pair of jobs i and j such that: i < j but j scheduled before i. inversion j

before swap

i i after swap

fi

j f 'j

Claim. Swapping two adjacent, inverted jobs reduces the number of inversions by one and does not increase the max lateness.
Pf. Letℓ be the lateness before the swap, and let ℓ be it afterwards.
'

・ℓ'k = ℓk for all k ≠ i, j.
・ℓ'i ≤ ℓi.
・If job j is late, ℓ'j = f 'j

– dj

= fi – dj

≤ fi – di

≤ ℓ .

i

(definition)
( j now finishes at time fi )
(since i and j inverted)
(definition)
30

Minimizing lateness: analysis of earliest-deadline-first algorithm
Theorem. The earliest-deadline-first schedule S is optimal.
Pf. [by contradiction]
Define S* to be an optimal schedule that has the fewest number of inversions, and let's see what happens.

・Can assume S* has no idle time.
・If S* has no inversions, then S = S*.
・If S* has an inversion, let i–j be an adjacent inversion.
・Swapping i and j
- does not increase the max lateness
- strictly decreases the number of inversions

・This contradicts definition of S*



31

Greedy analysis strategies
Greedy algorithm stays ahead. Show that after each step of the greedy algorithm, its solution is at least as good as any other algorithm's.
Structural. Discover a simple "structural" bound asserting that every possible solution must have a certain value. Then show that your algorithm always achieves this bound.
Exchange argument. Gradually transform any solution to the one found by the greedy algorithm without hurting its quality.

Other greedy algorithms. Gale-Shapley, Kruskal, Prim, Dijkstra, Huffman, …

32

4. G REEDY A LGORITHMS I
‣ coin changing
‣ interval scheduling
‣ scheduling to minimize lateness
‣ optimal caching

SECTION 4.3

Optimal offline caching
Caching.

・Cache with capacity to store k items.
・Sequence of m item requests d1, d2, …, dm.
・Cache hit: item already in cache when requested.
・Cache miss: item not already in cache when requested:

must bring

requested item into cache, and evict some existing item, if full.
Goal. Eviction schedule that minimizes number of evictions.

a

a

b

Ex. k = 2, initial cache = ab, requests: a, b, c, b, c, a, a.

b

a

b

Optimal eviction schedule. 2 evictions.

c

c

b

b

c

b

c

c

b

a

a

b

b

a

cache miss
(eviction)

b

requests

cache

34

Optimal offline caching: greedy algorithms
LIFO / FIFO. Evict element brought in most (east) recently.
LRU. Evict element whose most recent access was earliest.
LFU. Evict element that was least frequently requested. previous queries

⋮ a x

y

z

FIFO: eject a

a

w

x

d

z

LRU: eject d

a

a

w

x

d

z

b

a

b

x

d

z

c

cache miss
(which item to eject?)

w

d

current cache

a

a

b

c

d

z

e

a

b

c

d

e

LIFO: eject e

g b e d ⋮

future queries
35

Optimal offline caching: farthest-in-future (clairvoyant algorithm)
Farthest-in-future. Evict item in the cache that is not requested until farthest in the future. current cache cache miss
(which item to eject?)

a

a

b

c

d

e

f a b c e g b e d

FF: eject d

⋮ future queries

Theorem. [Bélády 1966] FF is optimal eviction schedule.
Pf. Algorithm and theorem are intuitive; proof is subtle.

36

Reduced eviction schedules
Def. A reduced schedule is a schedule that only inserts an item into the cache in a step in which that item is requested.

item inserted when not requested

a

a

b

c

a

a

b

c

a

a

x

c

a

a

b

c

c

a

d

c

c

a

b

c

d

a

d

b

d

a

d

c

a

a

c

b

a

a

d

c

b

a

x

b

b

a

d

b

c

a

c

b

c

a

c

b

a

a

b

c

a

a

b

c

a

a

b

c

a

a

b

c

an unreduced schedule

a reduced schedule

37

Reduced eviction schedules
Claim. Given any unreduced schedule S, can transform it into a reduced schedule S' with no more evictions.
Pf. [by induction on number of unreduced items]

・Suppose S brings d into the cache at time t, without a request.
・Let c be the item S evicts when it brings d into the cache.
・Case 1: d evicted at time t', before next request for d. unreduced schedule S

Case 1

S'

.

c

.

c

.

.

c

.

c

.

.

c

.

.

d

.

.

c

.

d

.

.

c

. e .

.

time t'

.

.
¬d

c

.

time t

.

.

d

.

.

c

.

.

e

.

.

e

.

.

e

.

.

e

d enters cache without a request

d evicted before next request

¬d

e

might as well leave c in cache

38

Reduced eviction schedules
Claim. Given any unreduced schedule S, can transform it into a reduced schedule S' with no more evictions.
Pf. [by induction on number of unreduced items]

・Suppose S brings d into the cache at time t, without a request.
・Let c be the item S evicts when it brings d into the cache.
・Case 1: d evicted at time t', before next request for d.
・Case 2: d requested at time t' before d is evicted. ▪ unreduced schedule S

Case 2

S'

.

c

.

c

.

.

c

.

c

.

.

c

.

.

d

.

.

c

.

d

.

.

c

. d .

.

time t'

.

.
¬d

c

.

time t

.

.

d

.

.

c

.

.

d

.

.

d

.

.

d

.

.

d

d enters cache without a request

d requested before d evicted

¬d

d

might as well leave c in cache until d is requested

39

Farthest-in-future: analysis
Theorem. FF is optimal eviction algorithm.
Pf. Follows directly from invariant.
Invariant. There exists an optimal reduced schedule S that makes the same eviction schedule as SFF through the first j requests.
Pf. [by induction on j]
Let S be reduced schedule that satisfies invariant through j requests.
We produce S' that satisfies invariant after j + 1 requests.

・Consider (j + 1)st request d = dj+1.
・Since S and SFF have agreed up until now, they have the same cache contents before request j + 1.

・Case 1:
・Case 2:

(d is already in the cache). S' = S satisfies invariant.
(d is not in the cache and S and SFF evict the same element).

S' = S satisfies invariant.

40

Farthest-in-future: analysis
Pf. [continued]

・Case 3:

(d is not in the cache; SFF evicts e; S evicts f ≠ e).

- begin construction of S' from S by evicting e instead of f

same

e

f

j

same

S same e

f

d

f

S' e d

j+1

same

- now S' agrees with SFF on first j + 1 requests; we show that having element f in cache is no worse than having element e
- let S' behave the same as S until S' is forced to take a different action
(because either S evicts e; or because either e or f is requested)

41

Farthest-in-future: analysis
Let j' be the first time after j + 1 that S' must take a different action from S, and let g be item requested at time j'. involves e or f (or both)

same

e

j'

S

・Case 3a:

same

f

S'

g = e.

Can't happen with FF since there must be a request for f before e.

・Case 3b:

g = f.

Element f can't be in cache of S, so let e' be the element that S evicts.
- if e' = e, S' accesses f from cache; now S and S' have same cache
- if e' ≠ e, we make S' evict e' and brings e into the cache; now S and S' have the same cache
We let S' behave exactly like S for remaining requests.
S' is no longer reduced, but can be transformed into a reduced schedule that agrees with SFF through step j+1

42

Farthest-in-future: analysis
Let j' be the first time after j + 1 that S' must take a different action from S, and let g be item requested at time j'. involves e or f (or both)

same

e

j'

S

same

f

S'

otherwise S' could have take the same action

・Case 3c:

g ≠ e, f. S evicts e.

Make S' evict f . same g

j'

S

same

g

S'

Now S and S' have the same cache.
(and we let S' behave exactly like S for the remaining requests) ▪
43

Caching perspective
Online vs. offline algorithms.

・Offline: full sequence of requests is known a priori.
・Online (reality): requests are not known in advance.
・Caching is among most fundamental online problems in CS.
LIFO. Evict page brought in most recently.
LRU. Evict page whose most recent access was earliest.
FIF with direction of time reversed!

Theorem. FF is optimal offline eviction algorithm.

・Provides basis for understanding and analyzing online algorithms.
・LRU is k-competitive. [Section 13.8]
・LIFO is arbitrarily bad.
44

Similar Documents

Free Essay

Greedy Algorithm

...GREEDY ALGORITHM A greedy algorithm is a mathematical process that looks for simple, easy-to-implement solutions to complex, multi-step problems by deciding which next step will provide the most obvious benefit. Greedy algorithms are similar to dynamic programming algorithms in that the solutions are both efficient and optimal if the problem exhibits some particular sort of substructure. A greedy algorithm builds a solution by going one step at a time through the feasible solutions, applying a heuristic to determine the best choice. A heuristic applies an insight to solving the problem, such as always choose the largest, smallest, etc. Such algorithms are called greedy because while the optimal solution to each smaller instance will provide an immediate output, the algorithm doesn’t consider the larger problem as a whole. Once a decision has been made, it is never reconsidered. Greedy algorithms work by recursively constructing a set of objects from the smallest possible constituent parts. Recursion is an approach to problem solving in which the solution to a particular problem depends on solutions to smaller instances of the same problem. Advantages of greed algorithm * Always taking the best available choice is usually easy. * It usually requires sorting the choices. * Solutions to smaller instances of the problem can be straightforward and easy to understand. * Repeatedly taking the next available best choice is usually linear work. * But don't...

Words: 387 - Pages: 2

Free Essay

Introduction to Problem Solving and Algorithm Design

...CMIS 102 4060 Introduction to Problem Solving and Algorithm Design HOMEWORK 2 Declare CPUCost As Float Declare CaseCost As Float Declare PowerSupplyCost As Float Declare Motherboard As Float Declare HardDriveCost As Float Declare RAMCost As Float Declare DVDCost As Float Declare SoundCardCost As Float Declare MonitorCost As Float Declare GraphicsCardCost As Float Declare OperatingSystem Cost As Float //Prompt for and input the computer price: Write “Enter the computer price:” Input ComputerPrice Call Compute_CPU_Cost module Call Compute_Case_Cost module Call Compute_Power_Supply_Cost module Call Compute_Motherboard_Cost module Call Compute_Hard_Drive_Cost module Call Compute_RAM_Cost module Call Compute_DVD_Cost module Call Compute_Monitor_Card_Cost module Call Compute_Graphics_Card_Cost module Call Compute_Operating_System_Cost module End Program Declare CPUCost as Character //Display the menu and input user selection: Write “S – Intel i7” Write “E – Intel i5” Write “D – Intel i3” Write “Selection” Input CPU Choice Select Case of CPU Choice Case “S”: Set CPUCost = 319 Break Case “E”: Set CPUCost = 229 Break Case “D”: Set CPUCost = 119 Break Default: Write” Invalid Selection” End Case Declare CaseCost as Character //Display the menu and input user selection: Write “V – Thermaltake V3” Write “C – NZXT Guardian” Write “L – Cooler Master Elite 430” Write “Selection” Input Case Choice Select Case of Case Choice Case “V”: ...

Words: 311 - Pages: 2

Free Essay

Case Study

...programming and Web Design Data Mining and Warehousing Internet programming and Web Design Lab Project Work and Viva Voce Total University Examinations Durations Max in Hrs Marks 3 100 3 100 3 100 3 100 3 100 3 3 3 3 100 100 100 100 100 1000 II For project work and viva voce (External) Breakup: Project Evaluation : 75 Viva Voce : 25 1 Anx.31 J - M Sc CS (SDE) 2007-08 with MQP Page 2 of 16 YEAR – I PAPER I: ADVANCED COMPUTER ARCHITECTURE Subject Description: This paper presents the concept of parallel processing, solving problem in parallel processing, Parallel algorithms and different types of processors. Goal: To enable the students to learn the Architecture of the Computer. Objectives: On successful completion of the course the students should have: Understand the concept of Parallel Processing. Learnt the different types of Processors. Learnt the Parallel algorithms. Content: Unit I Introduction to parallel processing – Trends towards parallel processing – parallelism in uniprocessor Systems – Parallel Computer structures – architectural classification schemes – Flynn’ Classification – Feng’s Classification – Handler’s Classification – Parallel Processing Applications. Unit II Solving problems in Parallel: Utilizing Temporal Parallelism – Utilizing Data Parallelism –...

Words: 3613 - Pages: 15

Premium Essay

It- 3rd Year

...E-COMMERCE (TIT-501) UNIT I Introduction What is E-Commerce, Forces behind E-Commerce Industry Framework, Brief history of ECommerce, Inter Organizational E-Commerce Intra Organizational E-Commerce, and Consumer to Business Electronic Commerce, Architectural framework Network Infrastructure for E-Commerce Network Infrastructure for E-Commerce, Market forces behind I Way, Component of I way Access Equipment, Global Information Distribution Network, Broad band Telecommunication. UNIT-II Mobile Commerce Introduction to Mobile Commerce, Mobile Computing Application, Wireless Application Protocols, WAP Technology, Mobile Information Devices, Web Security Introduction to Web security, Firewalls & Transaction Security, Client Server Network, Emerging Client Server Security Threats, firewalls & Network Security. UNIT-III Encryption World Wide Web & Security, Encryption, Transaction security, Secret Key Encryption, Public Key Encryption, Virtual Private Network (VPM), Implementation Management Issues. UNIT - IV Electronic Payments Overview of Electronics payments, Digital Token based Electronics payment System, Smart Cards, Credit Card I Debit Card based EPS, Emerging financial Instruments, Home Banking, Online Banking. UNIT-V Net Commerce EDA, EDI Application in Business, Legal requirement in E -Commerce, Introduction to supply Chain Management, CRM, issues in Customer Relationship Management. References: 1. Greenstein and Feinman, “E-Commerce”, TMH 2. Ravi Kalakota, Andrew Whinston...

Words: 2913 - Pages: 12

Free Essay

Software Developer

...31, 2016 Introduction I am evaluating a journal article titled: Algorithmic accountability. The article was published in Digital Journalism, in November 7, 2014. The author of the article is Nicholas Diakopoulos from College of Journalism, University of M aryland . Evaluation This article focuses on the concept of “Algorithmic Accountability Reporting” as a way of investing biases and influences employed by algorithms in todays society and how new age computational journalists should approach it. This article is directed at journalists who are scrutinizing algorithms to understand biases and false analysis portrayed by algorithms. The article is well structured. Text is organized in coherent sections which logically connects the entire article. The article starts with the brief introduction which outlines the points which will be covered in the article. Introduction also answers the questions of – what is this article about, who is the target audience, what are the current issues faced in journalism and how methods described in this article will help address those issue. Author, then mentions few real world examples of software companies which collect user data and then build ingenious algorithms to classify, group and eventually target people for their benefits – and how in doing so – they often open risks and flaws. The author exposes potential flaws by raising very valid questions about the decisions made during the development of algorithms. These questions...

Words: 900 - Pages: 4

Premium Essay

Algorithms In Computer Science

...Abstract—Algorithms are commonly perceived as a difficult subject, which is quite an irony as they have a fundamental role in computer science. Failure to master this subject will inhibit students’ capabilities as they advance to higher levels. Algorithm visualization, as an effort to overcome the problem, has been growing towards gameful visualization recently that is presumed to be able to engage learners longer and more intensely. However, integrating algorithm visualization, game elements, and instructional design is not a trivial task as it requires a careful design. Hence, a conceptual model of how algorithm learning instructions, algorithm visualization, and gamification improve learning outcomes was developed. While instructional design...

Words: 753 - Pages: 4

Free Essay

Sorting Algorithms

...REVIEW ON SORTING ALGORITHMS A comparative study on two sorting algorithms By Pooja Adhikari A Term Paper Submitted to the Faculty of Dr. Gene Boggess Mississippi State University In the Department of Computer Science & Engineering Mississippi State, Mississippi 04 20072 ABSTRACT Any number of practical applications in computing requires things to be in order. The performance of any computation depends upon the performance of sorting algorithms. Like all complicated problems, there are many solutions that can achieve the same results. One sort algorithm can do sorting of data faster than another. A lot of sorting algorithms has been developed to enhance the performance in terms of computational complexity, memory and other factors. This paper choose two of the sorting algorithms among them selection sort and shell sort and compares the various performance factor among them. 1. INTRODUCTION Sorting is the rearrangement of things in a list into their correct lexicographic order. A number of sorting algorithms have been developed like include heap sort , merge sort, quick sort, selection sort all of which are comparison based sort .There is another class of sorting algorithms which are non comparison based sort. This paper gives the brief introduction about sorting algorithms [2] where it discuss about the class of sorting algorithms and their running times. It mainly analyses the performance between two...

Words: 841 - Pages: 4

Premium Essay

Doc Remove Delibitablement

...Functional Analysis | 3,5 | 48 | Algebra for Engineers | 2,5 | 32 | Probability 1 | 3,5 | 48 | Statistical Decision (courses +Tuto) | 3,5 | 48 | Microprocessor System | 3 | 40 | Signal Transmission | 2,5 | 32 | Data Transmission | 2,5 | 32 | Workshop on Linux | 3 | 40 | Databases | 3 | 40 | TOEIC 1 | 2,5 | 32 | Advanced Maintenance | 2,5 | 32 | Numerical Analysis | 2,5 | 32 | Operations Research | 2,5 | 32 | Servo (Tuto) | 2,5 | 32 | Servo (Courses) | 2,5 | 32 | Algorithm (Data Structure) | 2,5 | 32 | Algorithm oriented object (Tuto, C++ Language) | 3 | 40 | Operating System (Theories and Fundamental) | 2,5 | 32 | WAN (courses + Tuto) | 4,5 | 60 | Method of Analysis 1 | 3 | 40 | Programming Workshop C | 2,5 | 32 | Software Engineering workshop (Access, VB) | 3 | 40 | Management Workshop for Science Engineer | 2 | 24 | Entrepreneurship | 1,5 | 20 |   |   |   | TOTAL | 63,5 | 832 | ------------------------------------------------- OBJECT ORIENTED ALGORITHM ------------------------------------------------- (Hands-On in Language C + +) CHAPTER I: GENERAL ON CLASS I. Notion of class • Generality of P.O.O • Incompatibility C / C + + II. Property of the member functions • Defaults • Member functions in-line • Transmission of object as argument III. Object assignment IV. Object Constructors and Destructors V. Object initialization VI. The copy constructor VII. Tables to Objects CHAPTER II: THE OPERATOR SURDEFINITION ...

Words: 2262 - Pages: 10

Free Essay

Computer Science

...Homework #1 for CSC 100 Name: ____________________________________ Computer Science, An Overview ------------------------------------------------- Chapter 00 Introduction Read the introduction to the text. The answers to the following questions will appear in order as you read. What is computer science? ------------------------------------------------- The Role of Algorithms What is an algorithm? What are some examples of algorithms? What is a program? What is programming? What is software? What is hardware? Where did the study of algorithms come from? Once you discover an algorithm, do others need to understand it? When does the solution of a problem lie beyond the capabilities of machines? ------------------------------------------------- The History of Computing What are some of the ancestors of the Computer? Eventually, people began using gears for computing. Who are some of the people involved? Which of the men above produced something that was programmable? What were (and are) some uses of holes punched in cards? What kinds of devices replaced gears? What were some early computers? According to the text, what were the first commercially viable computers, and who built them? What happened in 1981? Who wrote the underlying software for the PC? What important development in computers happened as the Twentieth century was closing? What were two big developments for the Internet? (hint, look for the...

Words: 406 - Pages: 2

Free Essay

Genetic Algorithms

...Genetic Algorithm Approach to Solve the Shortest Path Problem for Road Maps Sachith Abeysundara*, Baladasan Giritharan+, Saluka Kodithuwakku◊ *Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: sachith@email.com Telephone: (+94) 81 2374652 + Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: bgiri@pdn.ac.lk ◊ Department of Statistics and Computer Science, Faculty of Science, University of Peradeniya, Sri Lanka Email: salukak@pdn.ac.lk Telephone: (+94) 81 2394260 Abstract—This paper presents a new genetic algorithm approach to solve the shortest path problem for road maps. This is based on the analogy of finding the shortest possible distance between two towns or cities in a graph or a map with potential connection, which means that the path distances are always positive. Typically this is represented by a graph with each node representing a city and each edge being a path between two cities and there exist some traditional algorithms that produce solutions for the problem. A new method is found to solve the shortest path problem using GAs. The algorithm has been tested for a road map containing more than 125 cities and the experimental results guarantee to provide acceptably good solutions for the given search space. HE shortest path problem is typical in the world of combinatorial systems. This research will attempt to apply a Genetic algorithm to solve...

Words: 2513 - Pages: 11

Free Essay

Ramp Metering

...Course: Traffic Engineering, CIV4116 -S12 Instructor: Mr. Peyman Misaghi Date: J uly 1, 2012 T able of Contents 1- Introduction ..................................................................................................................... 3 2- History .............................................................................................................................. 4 3- Ramp Metering Algorithms .......................................................................................... 5 3-1- S ystem Architecture .............................................................................................. 5 3-2- Release Algorithm .................................................................................................. 6 3-3- A rbitration Algorithm .............................................................................................. 7 3-4- S witch On- Off Algorithm ....................................................................................... 8 3-5- Q ueue Override Algorithm .................................................................................... 9 3-6- Q ueue Management Algorithm ........................................................................... 9 3-7- Ramp Metering Algorithm ...................................................................................10 3-8- Data Filtering Algorithm: .....................................................................................10 4- Types of Ramp Metering...

Words: 2688 - Pages: 11

Free Essay

Gene Recognition

...Gene Recognition A project report submitted to M S Ramaiah Institute of Technology An Autonomous Institute, Affiliated to Visvesvaraya Technological University, Belgaum in partial fulfillment for the award of the degree of Bachelor of Engineering in Computer Science & Engineering Submitted by Mudra Hegde 1MS07CS052 Nakul G V 1MS07CS053 Under the guidance of Veena G S Assistant Professor Computer Science and Engineering M S Ramaiah Institute of Technology [pic] DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING M.S.RAMAIAH INSTITUTE OF TECHNOLOGY (Autonomous Institute, Affiliated to VTU) BANGALORE-560054 www.msrit.edu May 2011 Gene Recognition A project report submitted to M. S. Ramaiah Institute of Technology An Autonomous Institute, Affiliated to Visvesvaraya Technological University, Belgaum in partial fulfillment for the award of the degree of Bachelor of Engineering in Computer Science & Engineering Submitted by Mudra Hegde 1MS07CS052 Nakul G V 1MS07CS053 Under the guidance of Veena G S Assistant Professor Computer Science and Engineering M S Ramaiah Institute of Technology [pic] DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING M. S. RAMAIAH INSTITUTE OF TECHNOLOGY (Autonomous Institute, Affiliated to VTU) BANGALORE-560054 www.msrit.edu May 2011 Department of Computer Science...

Words: 8197 - Pages: 33

Free Essay

Bluetooth Network Security

...TECHNOLOGY A seminar report on GENETIC ALGORITHMS Submitted by Pranesh S S 2SD06CS061 8th semester DEPARTMENT OF COMPUTER SCIENCE ENGINEERING 2009-10 1 VISHVESHWARAIAH TECHNOLOGICAL UNIVERSITY S.D.M COLLEGE OF ENGINEERING AND TECHNOLOGY DEPARTMENT OF COMPUTER SCIENCE ENGINEERING CERTIFICATE Certified that the seminar work entitled “GENETIC ALGORITHMS” is a bona fide work presented by Pranesh S S bearing USN NO 2SD06CS061 in a partial fulfilment for the award of degree of Bachelor of Engineering in Computer Science Engineering of the Vishveshwaraiah Technological University, Belgaum during the year 2009-10. The seminar report has been approved as it satisfies the academic requirements with respect to seminar work presented for the Bachelor of Engineering Degree. Staff in charge SANTOSH DESHPANDE SIR Name: Pranesh S S USN: 2SD06CS061 H.O.D 2 INDEX 1. INTRODUCTION 2. HISTORY 3. DEFINITION AND EXPLANATION 4. NEED FOR GENETIC ALGORITHM 5. IMPORTANCE OF GAOVER OTHER TECHNIQUES? 6. WORKING OF GA 6.1 BASIC DESCRIPTION 6.2 GENERAL ALGORITHM 7. IMPLEMENTATION 8. EXAMPLE-A SIMULATION BY HAND 9. ADVANTAGES AND DISADVANTAGES 10. CONCLUSION 11. REFERENCES 4 4 5 5 6 6 7 7 8 11 12 13 13 3 Abstract Genetic Algorithms have recently become a popular artificial technique for solving complex optimization problems and a sophisticated tool for machine learning. This paper provides an introduction to genetic algorithms and brief applicability to problems. There...

Words: 2516 - Pages: 11

Premium Essay

Syllabus

... 4. 5. 6. CSE411 CSE461 CSE412 CSE462 CSE414 CSE464 Subject Title Scheme of Teaching L 3 0 3 0 3 0 T 1 0 1 0 1 0 P 0 3 0 3 0 3 Hours 4 3 4 3 4 3 Credit 4 2 4 2 4 2 University External Marks 50 50 50 CSE361 CSE313 CSE363 AS301 EC316 EC366 EC317 EC367 Data Structures (Practical) Peripheral Devices & Interfaces Hardware Lab (Practical) Engineering Mathematics – III Digital Electronics Digital Electronics (Practical) Microprocessors Microprocessors (Practical) 0 3 0 3 3 0 3 0 15 0 1 0 1 1 0 1 0 5 3 0 2 0 0 2 0 2 09 3 4 2 4 4 2 4 2 29 2 4 1 4 4 1 4 1 25 50 50 50 50 250 Internal Total Sessional Marks 50 50 50 50 50 50 50 50 50 450 100 50 100 50 100 100 50 100 50 700 7. 8. Total ASC405 CSE 415 Analysis & Design of Algorithms Analysis & Design of Algorithms (Practical) Database Management System Database Management System (Practical) Object Oriented Programming Object Oriented Programming (Practical) Cyber Law & IPR Computer Architecture & Organization Internal Total Sessional Marks 50 100 50 50 50 50 50 50 100 50 100 50 3 3 15 0 1 4 0 0 9 3 4 28 3 4 25 50 50 250 50 50 400 100 100 650 2 Scheme of Examination of B.E. in Computer Science & Engineering Third Year - Fifth Semester Sr. Paper Subject Title Scheme of Teaching Univesity Internal Sessional Code External L T P Hou Credit Marks Total Marks rs s 1. CSE511 Operating System 3 1 0 4 4 50 50...

Words: 14784 - Pages: 60

Free Essay

Biometrics

...Optimization of biometric Fingerprint Recognition parameters using Genetic Algorithms Report submitted for CPSC - 6126 Fall 2014 Term Paper By Krishna Sindhuri Nagavolu 13th December, 2014 Optimization  of  biometric  fingerprint  recognition  parameters  using   Genetic  Algorithms   Abstract This research paper discusses about parameter optimization for biometric fingerprint recognition with the use of genetic algorithms. An accurate access control system is very important in domains like identification checks at airports, government organizations, FBI’s, scientific working groups like NASA, US defense department and driver’s license office. The main reason these organizations prefer Biometrics is because it measures physiological characteristics like fingerprints, iris patterns, facial recognition, retina recognition, ear recognition and DNA analysis. Based on the features of the biometric sensors used, the system can detect whether a person is an authorized user or not. Though there are many other methods for identification, biometric sensors are considered to be very reliable and accurate. The main objective of this paper is to build a fingerprint recognizer that is fully automatic and can minimize the errors caused while matching the fingerprints. Keywords: Biometrics, genetic algorithms, Parameter optimization, fingerprints                           2|Page Optimization ...

Words: 2966 - Pages: 12