- The details of the sub-problem solutions are available in advance in the form of bottom level modules.
- The individual sub-problem solutions are designed with great details.
- The main solution can be planned later depending on the available sub-task solutions.
- The main solution is used to link all the sub-problem solutions.
- The sub-solutions obtained are simple
- A complex main module is designed later using these simpler solutions.
- This technique is more general and code are reusable.
- This technique simplifies maintenance and the new features can be added easily.
- This decision of the final solution can be delayed to make it more effective for implementation.
- Testing in this case is simple and test cases can be designed very easily.
Saturday, November 8, 2014
Demerits of top-down technique
- This technique is mainly useful for small-scale problems.
- It is only useful in solving a part of a larger problem.
- This technique is a poor approach for solving larger problems
- This technique is also poor for designing larger programs.
- The application developed using this technique cannot be upgraded easily.
Related Links
Merits of top-down technique
- The summary of the program plan is known in advance in the form of top module.
- Parallel development of the program is possible because of independent design of the modules at different levels.
- Parallel development helps in designing the program at reduced time period.
- Testing and debugging are faster because of independent testing of modules.
- Attention can be given to individual level task to improve the efficiency.
- The hierarchy of the levels helps in understandable low level modules.
- Handling and management of the modules are easy.
- This technique improves the code reliability.
Features of top-down technique
- Program preparation is stretched to a number of levels
- In place of writing long list of statements, the statements are separated into different modules at various levels.
- The stretching is most general to most specific.
- Program is structured as hierarchy of various tasks.
- As the techniques moves from top to bottom, it is a type of specialization.
- Main module can be designed well before without requiring details of complete design.
- Testing can be done after inserting down level modules one-by-one.
- Parallel development is possible because of top and down level modules design.
Rules for making Flowchart
"What are the rules for making the flowchart?"
Rule 1: The flowchart should contain one start and one stop box (terminator).
Rule 2: The symbols of the flowchart are always labeled with simple codes.
Rule 3: The codes used in the flowchart should not give more than one meaning.
Rule 4: The control flows are always represented by directed arrows.
Rule 5: The control flow lines touch the boundary of any box either while leaving from or while entering into the box.
Rule 6: The control flow lines should not cross each other.
Rule 7: The flow line moves in vertical direction either from top to bottom or from bottom to top.
Rule 8: The flow line moves in horizontal direction either from left to right or from right to left.
Rule 9: Only one flow line comes out from all the boxes or symbols excepts decision box.
Rule 10: Two lines can flow from the decision box if single condition is checked. It means a single condition results in one of the two values TRUE or FALSE
Rule 1: The flowchart should contain one start and one stop box (terminator).
Rule 2: The symbols of the flowchart are always labeled with simple codes.
Rule 3: The codes used in the flowchart should not give more than one meaning.
Rule 4: The control flows are always represented by directed arrows.
Rule 5: The control flow lines touch the boundary of any box either while leaving from or while entering into the box.
Rule 6: The control flow lines should not cross each other.
Rule 7: The flow line moves in vertical direction either from top to bottom or from bottom to top.
Rule 8: The flow line moves in horizontal direction either from left to right or from right to left.
Rule 9: Only one flow line comes out from all the boxes or symbols excepts decision box.
Rule 10: Two lines can flow from the decision box if single condition is checked. It means a single condition results in one of the two values TRUE or FALSE
Design an algorithm to search a number using binary search technique
Binary Search algorithm is applied where we want to search number in sorted numbers. In this algorithm, first to find mid position of the list and divide the list into two parts. If number is equal to mid then position find easily , this is the best case of binary search.
Problem: Design an algorithm to search a number using binary search technique.
Input : A list (array) of numbers in ascending order, number of elements in the list and key to search.
Output: Returns 1 if the key is found otherwise returns 0
BIN_SEARCH(LIST, N, KEY)
[LIST is an array of numbers in ascending order]
[N is the size of the array and KEY is the number to search]
L <-- 0; H<-- N-1; [Assuming that array index start from 0]
M <-- INT ( (L+H) /2 ) [Get the quotient or integer part after division]
Repeat While (L <= H)
If(Key == LIST[M]) then:
Return 1 [Key found]
Else:
If(Key < LIST[M] ) then:
H <-- M-1 [Move to the left half of the list]
Else:
H <-- M+1 [Move to the right half of the list]
[End of If]
[End of If]
[End of While]
Return 0 [Key not found]
Exit.
Problem: Design an algorithm to search a number using binary search technique.
Input : A list (array) of numbers in ascending order, number of elements in the list and key to search.
Output: Returns 1 if the key is found otherwise returns 0
BIN_SEARCH(LIST, N, KEY)
[LIST is an array of numbers in ascending order]
[N is the size of the array and KEY is the number to search]
L <-- 0; H<-- N-1; [Assuming that array index start from 0]
M <-- INT ( (L+H) /2 ) [Get the quotient or integer part after division]
Repeat While (L <= H)
If(Key == LIST[M]) then:
Return 1 [Key found]
Else:
If(Key < LIST[M] ) then:
H <-- M-1 [Move to the left half of the list]
Else:
H <-- M+1 [Move to the right half of the list]
[End of If]
[End of If]
[End of While]
Return 0 [Key not found]
Exit.
Friday, November 7, 2014
Design an algorithm to search a number using linear search technique
Problem: Design an algorithm to search a number using linear search technique.
Input : A list (array) of numbers, number of elements in the list and key to search.
Output : Returns 1 if the key is found otherwise returns 0.
LSEARCH(LIST, N, KEY)
[LIST is an array of numbers, N is the size of the array and key is the number to search]
Repeat For I=0, 1, 2, 3......N-1 [Assuming that array index starts from 0]
If(Key == LIST[I]) then:
Returns 1
[End of If]
Returns 0
Exit.
Input : A list (array) of numbers, number of elements in the list and key to search.
Output : Returns 1 if the key is found otherwise returns 0.
LSEARCH(LIST, N, KEY)
[LIST is an array of numbers, N is the size of the array and key is the number to search]
Repeat For I=0, 1, 2, 3......N-1 [Assuming that array index starts from 0]
If(Key == LIST[I]) then:
Returns 1
[End of If]
Returns 0
Exit.