Top Down Design

Top-Down Method Of Design


  • It decompose the overall problem into precisely specified sub-problems, and then prove that if each Sub problem is satisfied correctly, and the solutions are fitted together in a specified way, then the original problem will be solved correctly.
  • Repeat this process of "decompose and prove correctness of the decomposition” for the sub-problems, and keep repeating this process till the resulting Subproblems are so simple that their solution can be expressed in a few lines of a programming language.
  • For long, programmers have tried to design and code algorithms directly in a programming language, as many of us do even today, rather than carefully decomposing the problem into simpler problems and checking the relationship between them before proceeding to a more detailed specification. The latter which is a more methodical approach is called the Top-Down design technique.
  • Experience has shown that this approach to program development results in programs with fewer mistakes than line- by-line development.
  • Top-Down design technique has shown that this approach to program development results in programs with fewer mistakes than line by-line development.
  • In the case of line-by-line method of program development, the only way to assure that the program is working correctly is by thorough testing with some data sets. If the program gives correct results, we may be confident that the program is correct but this cannot guarantee that the program will work correctly for all data sets.
  • The only way to ensure this is to use top-down design procedure, which, as a part of the design procedure itself, contains a schema, as a result of which programs are designed correctly.

Find The Greatest Common D 

Few rules for gcd 
gcd (0, 0) = 0 
gcd(u, 0) = |u| 
gcd(x, y) = gcd(y, x mod y)

Complete Algorithm For Gcd 
Step-1:Set x <-a ,y<-b; 
Step-2:If y!= 0 then Set r<-x mod y Set x<-y Set y<-r 
Step-3:Repet step 2 If y=0 then set gcd(a,b)<-x
Example:
Find the GCD of 270 and 192 A=270, B=192
A ≠0 B ≠0
Use long division to find that 270/192 = 1 with a remainder of 78.
We can write this as: 270 = 192 * 1 +78
Find GCD(192,78), since GCD(270,192)=GCD(192,78).
A=192, B=78
A ≠0
B ≠0
Use long division to find that 192/78 = 2 with a remainder of 36. We can write this as:
192 = 78 * 2 + 36
Find GCD(78,36), since GCD(192,78)=GCD(78,36)
A=78, B=36
A ≠0
B ≠0
Use long division to find that 78/36 = 2 with a remainder of 6. We can write this as:
78 = 36 * 2 + 6
Find GCD(36,6), since GCD(78,36)=GCD(36,6)
A=36, B=6
A ≠0
B ≠0
Use long division to find that 36/6 = 6 with a remainder of 0. We can write this as:
36 = 6 * 6 + 0
Find GCD(6,0), since GCD(36,6)=GCD(6,0)
A=6, B=0
A ≠0
B =0, GCD(6,0)=6
Hence ,GCD(270,192) = GCD(192,78) = GCD(78,36) = GCD(36,6) = GCD(6,0) = 6
ANS :GCD(270,192) = 6

No comments:

Post a Comment