0% found this document useful (0 votes)
7 views21 pages

Top-Down and Bottom-Up Design Approach

The document discusses two algorithm design approaches: Top-Down and Bottom-Up. The Top-Down approach breaks complex problems into smaller modules, while the Bottom-Up approach combines smaller modules into a larger structure. Additionally, it covers data structures, including primitive and non-primitive types, abstract data types, and provides sample algorithms for various tasks.

Uploaded by

shanthinkrcs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views21 pages

Top-Down and Bottom-Up Design Approach

The document discusses two algorithm design approaches: Top-Down and Bottom-Up. The Top-Down approach breaks complex problems into smaller modules, while the Bottom-Up approach combines smaller modules into a larger structure. Additionally, it covers data structures, including primitive and non-primitive types, abstract data types, and provides sample algorithms for various tasks.

Uploaded by

shanthinkrcs
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

Top-Down and Bottom-Up Design Approach

Introduction to Top-down and bottom-Up Design


There are two design approach which are used for
algorithm designs namely Top-down design approach and
Bottom-Up design approach.
Top-Down design approach divides the complex module
into smaller sub-module whereas Bottom-up design
approach combines the smaller sub-module into the
larger complex module.
In this post, We are going to explore more about these
two design approaches.
Top-Down Approach

• As mentioned, the Top-Down design follows splitting design


approach which breaks a complex algorithm or a problem into
smaller segments called modules, this process is also called
as modularization.
• In Top-Down design approach following steps:
• Take the complex whole problem and split it into two or more
parts.
• Find the solution to these parts.
• If split parts turn out to be too big to be solved, split them
further.
• Find solutions to those sub parts.
• Merge solutions according to the sub-problem hierarchy.
• If all parts have been successfully solved, the whole problem is
solved.
Bottom-Up Approach

• As mentioned, the Bottom-Up approach follows the


merging design approach which combines the smaller
sub-module into the larger complex module. Models are
built from simple components connected.
• In Bottom-Up design approach following steps:
• Take the smallest sub-part of the complex module.
• Solve that sub part.
• Take other smallest part ,solve that sub part and so on…
• Merge all the smallest sub-part iteratively to get the
final solution.
Difference between Top-Down and Bottom-Up design approach
Top-Down Design Approach Bottom-Up Design Approach

Top-Down design approach divides the Bottom-up design approach combines


complex module into smaller sub- the smaller sub-module into the larger
module. complex module.

Follows splitting technique. Follows merging technique.

This approach contains redundant This approach easily eliminates


information. redundant information.

Communication among steps is not Communication among steps is


mandatory. mandatory.

The individual modules are thoroughly Works on the concept of encapsulation


analyzed. and data-hiding.

A programming language like C++,


A programming language like C
Java follows the bottom-up design
follows the top-down design approach.
approach.
Types of Data Structure
Primitive Data Type
• Primitive data types are the data types available in most of the
programming languages.
• These data types are used to represent single value.
• It is a basic data type available in most of the programming language.

Data type Description


Integer Used to represent a number
without decimal point.
Float Used to represent a number with
decimal point.
Character Used to represent single character.
Boolean Used to represent logical values
either true or false.
Non-Primitive Data Type
• Data type derived from primary data types are known as Non-Primitive
data types.
• Non-Primitive data types are used to store group of values.
• It can be divided into two types:

1. Linear Data Structure


2. Non-Linear Data Structure

1. Linear Data Structure

Linear data structure traverses the data elements sequentially.


• In linear data structure, only one data element can directly be reached.
• It includes array, linked list, stack and queues.
Types Description
Arrays Array is a collection of elements. It is used in mathematical problems like matrix,
algebra etc. each element of an array is referenced by a subscripted variable or
value, called subscript or index enclosed in parenthesis.

Linked list Linked list is a collection of data elements. It consists of two parts: Info and Link.
Info gives information and Link is an address of next node. Linked list can be
implemented by using pointers.

Stack Stack is a list of elements. In stack, an element may be inserted or deleted at one
end which is known as Top of the stack. It performs two operations: Push and Pop.
Push means adding an element in stack and Pop means removing an element in
stack. It is also called Last-in-First-out (LIFO).

Queue Queue is a linear list of element. In queue, elements are added at one end called
rear and the existing elements are deleted from other end called front. It is also
called as First-in-First-out (FIFO).
Non-Linear Data Structure
•Non-Linear data structure is opposite to linear data structure.
•In non-linear data structure, the data values are not arranged in
order and a data item is connected to several other data items.
•It uses memory efficiently. Free contiguous memory is not
required for allocating data items.
•It includes trees and graphs.
Type Description

Tree Tree is a flexible, versatile and powerful non-linear


data structure. It is used to represent data items
processing hierarchical relationship between the
grandfather and his children & grandchildren. It is an
ideal data structure for representing hierarchical data.

Graph Graph is a non-linear data structure which consists of


a finite set of ordered pairs called edges. Graph is a
set of elements connected by edges. Each elements
are called a vertex and node.
Abstract Data type (ADT)
• What is ADT?
• ADT stands for Abstract Data Type.
• It is an abstraction of a data structure.
• Abstract data type is a mathematical model of a data structure.
• It describes a container which holds a finite number of objects where
the objects may be associated through a given binary relationship.
• It is a logical description of how we view the data and the operations
allowed without regard to how they will be implemented.
• ADT concerns only with what the data is representing and not with
how it will eventually be constructed.
• It is a set of objects and operations. For example, List, Insert, Delete,
Search, Sort.
• It consists of following three parts:

1. Data
2. Operation
3. Error

1. Data describes the structure of the data used in the


ADT.

2. Operation describes valid operations for the ADT. It


describes its interface.

3. Error describes how to deal with the errors that can


occur.
Advantages of ADT
•ADT is reusable and ensures robust data structure.
•It reduces coding efforts.
•Encapsulation ensures that data cannot be corrupted.
•ADT is based on principles of Object Oriented Programming
(OOP) and Software Engineering (SE).
•It specifies error conditions associated with operations.
Sample algorithms
Exchange the value of two variables
Algorithm:
1. Start
2. Read value of A
3. Read value of B
4. C=A
5. A=B
6. B=C
7. Print A
8. Print B
9. End
Summation of set of numbers
Algorithm:
1. Start
2. I=0
3. Sum=0
4. Sum=Sum+I
5. if I =15 then
Goto 6
else
I=I+1
Goto 4
endif
6. print Sum
7. stop
Decimal to Binary conversion
Algorithm:
Step 1: Divide the number by 2 through % (modulus
operator) and store the remainder in array

Step 2: Divide the number by 2 through / (division


operator)

Step 3: Repeat the step 2 until number is greater


than 0
Sorting in ascending order
Algorithm:
Steps:
1.Start.
2.Accept three numbers from user (a, b, c).
3.If a < b then goto step 4 else goto step 8.
4.If a < c then goto step 5 else goto step 7.
5.If b < c then goto step 9 else goto step 6.
6.Interchange b and c and goto step 9.
7.Interchange a and c and goto step 3.
8.Interchange a and b and goto step 3.
9.Display “Ascending order”.
10.Display a, b, c.
11.Stop.
Factorial
Algorithm :
• Step 1 : Start
• Start 2 : Read n
• Start 3 : Initialize counter variable i to 1 and fact to 1
• Start 4 : if i <= n go to step 5 otherwise goto step 7
• Start 5 : calculate fact = fact * i
• Start 6 : increment counter variable i and goto step 4
• Start 7 : Write fact.
• Start 8 : Stop
Fibonacci
Algorithm
• START
• Step 1 → Take integer variable A, B, C
• Step 2 → Set A = 0, B = 0
• Step 3 → DISPLAY A, B
• Step 4 → C = A + B
• Step 5 → DISPLAY C
• Step 6 → Set A = B, B = C
• Step 7 → REPEAT from 4 - 6, for n times
• STOP
Algorithm to find the smallest and
largest numbers in an array
Algorithm :
1.Input the array elements.
2.Initialize small = large = arr[0]
3.Repeat from i = 2 to n
4.if(arr[i] > large)
5.large = arr[i]
6.if(arr[i] < small)
7.small = arr[i]
8.Print small and large.
Reverse the order of elements in array
• ALGORITHM:
STEP 1: START
STEP 2: INITIALIZE arr[] = {1, 2, 3, 4, 5}
STEP 3: length= sizeof(arr)/sizeof(arr[0])
STEP 4: PRINT "Original Array:"
STEP 5: REPEAT STEP 6 and STEP 7 UNTIL i<length
STEP 6: PRINT arr[i]
STEP 7: i=i+1
STEP 8: PRINT new line.
STEP 9: PRINT "Array in reverse order"
STEP 10: SET i=length-1. REPEAT STEP 11 and STEP 12 UNTIL i>=0
STEP 11: PRINT a[i]
STEP 12: i=i-1
STEP 13: RETURN 0.
STEP 14: END

You might also like