Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Top and Bottom in Dsuc

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

Top-Down Approach

The basic idea in top-down approach is to break a complex algorithm or a problem into
smaller segments called modules, this process is also called as modularization. The modules
are further decomposed until there is no space left for breaking the modules without
hampering the originality. The uniqueness of the problem must be retained and preserved.
The decomposition of the modules is restricted after achieving a certain level of modularity.
The top-down way of solving a program is step-by-step process of breaking down the
problem into chunks for organising and solving the sole problem. The C- programming
language uses the top-down approach of solving a problem in which the flow of control is in
the downward direction.

Bottom-Up Approach

As the name suggests, this method of solving a problem works exactly opposite of how the
top-down approach works. In this approach we start working from the most basic level of
problem solving and moving up in conjugation of several parts of the solution to achieve
required results. The most fundamental units, modules and sub-modules are designed and
solved individually, these units are then integrated together to get a more concrete base to
problem solving.

This bottom-up approach works in different phases or layers. Each module designed is tested
at fundamental level that means unit testing is done before the integration of the individual
modules to get solution. Unit testing is accomplished using low-level functions, that is
another topic we will talk about later.

Let us now see a comparative study of both the strategies and try to understand what are
common and odds among them.

Difference between Top-down and Bottom-up Approach

Top-Down Approach Bottom-Up Approach

Divides a problem into smaller units


Starts from solving small modules and adding them up together.
and then solve it.

This approach contains redundant


Redundancy can easily be eliminated.
information.

A well-established communication is
Communication among steps is mandatory.
not required.
The individual modules are
Works on the concept of data-hiding and encapsulation.
thoroughly analysed.

Structured programming languages


OOP languages like C++ and Java, etc. uses bottom-up mechanism
such as C uses top-down approach.

The modules must be related for better communication and work


Relation among modules is not always
required.
flow.

Primarily used in code


implementation, test case generation,
Finds use primarily in testing.
debugging and module
documentation.

Conclusion

After having a sound discussion on this we all should now have got a clear understanding of
the two approaches. The top-down approach is the conventional approach in which
decomposition of higher level system into lower level system takes place respectively.
Talking about the bottom-up mechanism for algorithm designing, starting from designing
lower abstraction modules and then integrating them to higher level provides better
efficiency.

We have seen the modules in top-down approach aren’t connected in a manner so that they
can communicate well, so giving rise to redundancies, whereas in the later case the
redundancies are omitted to large extent. The feature of information hiding and reusability
provided by bottom-up approach makes this mechanism even more popular.

Structured Programming Approach

Structured Programming Approach, as the word suggests, can be defined as a


programming approach in which the program is made as a single structure. It means that the
code will execute the instruction by instruction one after the other. It doesn’t support the
possibility of jumping from one instruction to some other with the help of any statement like
GOTO, etc. Therefore, the instructions in this approach will be executed in a serial and
structured manner. The languages that support Structured programming approach are:
 C
 C++
 Java
 C#
..etc

Take a step-up from those "Hello World" programs. Learn to implement data structures like
Heap, Stacks, Linked List and many more! Check out our Data Structures in C course to
start learning today.

On the contrary, in the Assembly languages like Microprocessor 8085, etc, the statements do
not get executed in a structured manner. It allows jump statements like GOTO. So the
program flow might be random.
The structured program mainly consists of three types of elements:

 Selection Statements
 Sequence Statements
 Iteration Statements
The structured program consists of well structured and separated modules. But the entry and
exit in a Structured program is a single-time event. It means that the program uses single-
entry and single-exit elements. Therefore a structured program is well maintained, neat and
clean program. This is the reason why the Structured Programming Approach is well
accepted in the programming world.
Advantages of Structured Programming Approach:
1. Easier to read and understand
2. User Friendly
3. Easier to Maintain
4. Mainly problem based instead of being machine based
5. Development is easier as it requires less effort and time
6. Easier to Debug
7. Machine-Independent, mostly.
Disadvantages of Structured Programming Approach:
1. Since it is Machine-Independent, So it takes time to convert into machine code.
2. The converted machine code is not the same as for assembly language.
3. The program depends upon changeable factors like data-types. Therefore it needs to
be updated with the need on the go.
4. Usually the development in this approach takes longer time as it is language-
dependent. Whereas in the case of assembly language, the development takes lesser time
as it is fixed for the machine.

Difference between structured and unstructured programming languages


A structured programming language facilitates or enforces structured programming practices.
These practices can also be supported with unstructured languages, but that will require
specific steps in program design and implementation. Structured programming practices thus
date to the emergence of structured programming languages.

The theoretical basis for structured programming goes back to the 1950s, with the emergence
of the ALGOL 58 and 60 languages. Up to then, code clarity was reduced by the need to
build condition/action tests by having programmers write linked tests and actions explicitly
(using the goto statement or its equivalent), resulting in what was often called spaghetti code.
ALGOL included block structure, where an element of code included a condition and an
action.

Modular programming, which is today seen as synonymous with structured programming,


emerged a decade later as it became clear that reuse of common code could improve
developer productivity. In modular programming, a program is divided into semi-independent
modules, each of which are called when needed. Purists argue that modular programming
requires actual independence of modules, but most development teams consider any program
that divides logic into separate elements, even if those elements exist within the same
program, as modular.
Modern programming languages are universally capable of producing structured code.
Similarly, they're also capable of producing code fairly described as unstructured if used
incorrectly. Some would say that an unstructured programming language
contains gotostatements and, thus, does not require a "call" to a separate module, which then
returns when complete, but that definition is unnecessarily restrictive. It's better to say that
the mechanisms for enforcing structure vary by language, with some languages demanding
structure and other accepting less-structured code.

Types of structured programming


Structured programming can be divided into three categories, including:

Procedural programming. Defines modules as "procedures" or "functions" that are called


with a set of parameters to perform a task. A procedural language will begin a process, which
is then given data. It is also the most common category and has recently been subdivided into
the following:

 Service-oriented programming simply defines reusable modules as "services" with


advertised interfaces.

 Microservice programming focuses on creating modules that do not store data


internally, and so are scalable and resilient in cloud deployment.

 Functional programming, technically, means that modules are written from


functions, and that these functions' outputs are derived only from their inputs. Designed
for serverless computing, the definition of functional programming has since expanded to
be largely synonymous with microservices.

Object-oriented programming (OOP). Defines a program as a set of objects or resources to


which commands are sent. An object-oriented language will define a data resource and send
it to process commands. For example, the procedural programmer might say "Print(object)"
while the OOP programmer might say "Tell Object to Print".

Model-based programming. The most common example of this is database querylanguages.


In database programming, units of code are associated with steps in database access and
update or run when those steps occur. The database and database access structure will
determine the structure of the code. Another example of a model-based structure is Reverse
Polish Notation (RPN), a math-problem structure that lends itself to efficient solving of
complex expressions. Quantum computing, just now emerging, is another example of model-
based structured programming; the quantum computer demands a specific model to organize
steps, and the language simply provides it.

Components of structured programming


At the high level, structured programs consist of a structural hierarchy starting with the main
process and decomposing downward to lower levels as the logic dictates. These lower
structures are the modules of the program, and modules may contain both calls to other
(lower-level) modules and blocks representing structured condition/action combinations. All
of this can be combined into a single module or unit of code, or broken down into multiple
modules, resident in libraries.

Modules can be classified as "procedures" or "functions." A procedure is a unit of code that


performs a specific task, usually referencing a common data structure available to the
program at large. Much of the data operated on by procedures is external. A function is a unit
of code that operates on specific inputs and returns a result when called.

Structured programs and modules typically have a header file or section that describes the
modules or libraries referenced and the structure of the parameters and module interface. In
some programming languages, the interface description is abstracted into a separate file,
which is then implemented by one or more other units of code.

Advantages of structured programming


The primary advantages of structured programming are:

1. It encourages top-down implementation, which improves both readability and


maintainability of code.

2. It promotes code reuse, since even internal modules can be extracted and made
independent, residents in libraries, described in directories and referenced by many other
applications.

3. It's widely agreed that development time and code quality are improved through
structured programming.
These advantages are normally seen as compelling, even decisive, and nearly all modern
software development employs structured programming.

Disadvantages of structured programming


The biggest disadvantage of structured programming is a reduction in execution efficiency,
followed by greater memory usage. Both these problems arise from the introduction of calls
to a module or process, which then returns to the caller when it's done. System parameters
and system resources are saved on a stack (a queue organized as LIFO, or last-in-first-out)
and popped when needed. The more program logic is decomposed, meaning the more
modules are involved, the greater the overhead associated with the module interface. All
structured programming languages are at risk to "over-structuring" and loss of efficiency.

Structured programming can also be applied incorrectly if the type of structure selected isn't
right for the task at hand. The best-known example is the solving of math problems. RPL is
an efficient way to state and solve a math problem because it eliminates the need to explicitly
state execution order and eliminates recursion in code. However, if that problem were to be
posed in structured programming procedural or object form, the resulting code would be
much less efficient than the RPL version.

You might also like