Download presentation

Presentation is loading. Please wait.

Published byColleen Phillips Modified over 2 years ago

1
Algorithm Design 3

2
We have seen two different approaches to computing the number of combinations of m out of n items C(n,m) or n choose m. Divide-and-Conquer is clearly inferior to Dynamic Programming since the latter requires the computation of each sub-instance only once. Is there a better approach? In terms of computational load In terms of range of values For example what is the value of C(100,000, 99,998) and can this value be computed using either method described? (D&C or DynPro). If yes, what is the order of complexity? If asked to compute this value by hand, how would you proceed? Introduction

3
Developing a Better Algorithm You have seen two methods for computing binomial coefficients based on a recurrence relation. Using the closed form expression for binomial coefficients provided in the textbook create another version of this function that has a lower order of complexity than either bin or bin2. Develop, implement and test your version of this function and then derive its order of complexty. Hint: simplify the factorial terms algebraically and capture their essential computations in a single loop.

4
Another Binary Coefficient Function function bin3(n,k:integer)return long_float is val : long_float:=1.0; numdone: boolean:=false; dendone: boolean:=false; numval : integer; denval : integer; numend : integer; begin numval:=n; if (n-k)>k then numend:=n-k+1; denval:=k; else numend:=k+1; denval:=n-k; end if; if n>k and k>0 then while not(numdone and dendone) loop if (val<1.0 and not(numdone)) or dendone then val:=val*long_float(numval); numval:=numval-1; numdone:=(numval

5
Summary Divide-and-Conquer method of computing combinations is impractical. Dynamic Programming is also limited. Sometimes the direct calculation or brute-force approach is preferred. The range of values in the direct calculation method is limited only by the size of the answer.

Similar presentations

OK

Dynamic Programming. Many problem can be solved by D&C – (in fact, D&C is a very powerful approach if you generalize it since MOST problems can be solved.

Dynamic Programming. Many problem can be solved by D&C – (in fact, D&C is a very powerful approach if you generalize it since MOST problems can be solved.

© 2018 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Vector scan display ppt online Ppt on galaxy grand Ppt on power system harmonics study Ppt on sports day logo Ppt on networking related topics about psychology Ppt on leverages definition Ppt on solar system and stars Ppt on social work in india Ppt on 60 years of indian parliament today Ppt on mobile number portability in india