DAA Unit 4
DAA Unit 4
DAA Unit 4
Algorithms
(CSC-314)
B.Sc. CSIT
Unit-4:Greedy Algorithms
Introduction:
●
In the algorithms w e have studied so far correctness tended to b e
easier than efficiency. In optimization problems we are interested
in finding a thing which maximizes or minimizes some function.
●
In computer science an optimization problem is the problem of
finding the best solution from all feasible solutions.
●
Optimization problems can be divided into two categories,
depending on whether the variables are continuous or discrete:
●
An optimization problem with discrete variables is known as a
discrete optimization, in which an object such as an integer,
permutation or graph must be found from a countable set.
●
A problem with continuous variables is known as a continuous
optimization, in which an optimal value from a continuous function
must be found.
The knapsack has capacity W=60, then find optimal profit earned
by using fractional knapsack.
Unit-4:Greedy Algorithms
Job Sequencing with Deadline
●
We are given a set of n jobs. Associated with each job I,
di≥0 is an integer deadline and pi≥0 is profit.
●
For any job i profit is earned iff job is completed by
deadline. To complete a job one has to process a job for
one unit of time.
●
Thus, the sequence of job {J2,J1,J3} are being executed within their
deadline and gives maximum profit i.e. 100+60+20=180.
●
Number of bits required : 5*4+9*4+12*3+13*3+16*3+45*1 = 185 bits
– (300-185)/300*100 % = 38.33%
– i.e. we can save 38.33% space by using huffman coding.
●
Kruskal’s and Prim’s algorithms were covered in class
(see your note books if you have done seriously at that
time.)
Thank You!