Data Structure and Algorithms
REPUBLIC OF RWANDA
KIGALI INDEPENDENT UNIVERSITY (ULK)
P.O Box 2280
Website://[Link]
E-mail: ulk@[Link]
DATA STRUCTURES
AND ALGORITHMS
Year I Computer Science
Prepared by:
TWAHANYIMPETA Gratien
(+250) 78 8653421
May – June 2026
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 1
Data Structure and Algorithms
Chapter Four: PROGRAMMING METHODOLOGY
Programming methodologies deal with different methods of designing programs. This will teach you how to
program efficiently. Discussions in this chapter outline the importance of structuring the programs, not only
the data pertaining to the solution of a problem but also the programs that operates on the data.
Data is the basic entity or fact that is used in calculation or manipulation process. There are two types of
data such as numerical and alphanumerical data. Integer and floating-point numbers are of numerical data
type and strings are of alphanumeric data type. Data may be single or a set of values, and it is to be
organized in a particular fashion. This organization or structuring of data will have profound impact on the
efficiency of the program.
Data structure affects the design of both the structural and functional aspects of a program.
Algorithm + Data Structure = Program
A data structure is a specialized format for organizing, storing, and managing data in a computer so that it
can be accessed and modified efficiently. Data structures are the building blocks of a program; here the
selection of a particular data structure will help the programmer to design more efficient programs as the
complexity and volume of the problems solved by the computer is steadily increasing day by day. The
programmers have to strive hard to solve these problems. If the problem is analyzed and divided into sub
problems, the task will be much easier i.e., divide, conquer and combine.
A complex problem usually cannot be divided and programmed by set of modules unless its solution is
structured or organized. This is because when we divide the big problems into sub problems, these sub
problems will be programmed by different programmers or group of programmers. But all the programmers
should follow a standard structural method so as to make easy and efficient integration of these modules.
Such type of hierarchical structuring of program modules and sub modules should not only reduce the
complexity and control the flow of program statements but also promote the proper structuring of
information. By choosing a particular structure (or data structure) for the data items, certain data items
become friends while others lose its relations.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 2
Data Structure and Algorithms
4.1. Stepwise refinement method
1. In the first stage, modeling, we try to represent the problem using an appropriate mathematical model
such as a graph, tree etc. At this stage, the solution to the problem is an algorithm expressed very
informally.
2. At the next stage, the algorithm is written in pseudo-language (or formal algorithm) that is, a mixture of
any programming language constructs and less formal English statements. The operations to be performed
on the various types of data become fixed.
3. In the final stage we choose an implementation for each abstract data type and write the procedures for
the various operations on that type. The remaining informal statements in the pseudo-language algorithm
are replaced by (or any programming language) C/C++ code. Following sections will discuss different
programming methodologies to design a program.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 3
Data Structure and Algorithms
4.2. Modular programming
Modular programming is a software design technique where a large program is divided into smaller,
independent, and interchangeable parts called modules. Each module handles a specific, self-contained task,
resulting in more readable, maintainable, and reusable code.
Modular Programming is heavily procedural. The focus is entirely on writing code (functions). Data is
passive in Modular Programming. Any code may access the contents of any data structure passed to it.
Modular Programming is the act of designing and writing programs as functions, that each one performs a
single well-defined function, and which have minimal interaction between them. That is, the content of each
function is cohesive, and there is low coupling between functions.
Modular Programming discourages the use of control variables and flags in parameters; their presence tends
to indicate that the caller needs to know too much about how the function is implemented.
In computer programming, a flag is a variable used as a signal to indicate whether a specific condition has
been met or a particular event has occurred.
Modular programming encourages splitting functionality into two primary types of functions: Manager
functions and Worker functions.
• Manager Functions: These control the high-level program flow. They primarily contain calls to
other functions, acting as coordinators that decide when and how specific tasks are executed.
• Worker Functions: These handle the low-level details of the program. Each worker function is
designed to perform a single, specific task—such as moving data or performing a calculation—
without needing to know about the overall program logic
Two methods may be used for modular programming. They are known as top-down and bottom-up, which
we have discussed in the above section. Regardless of whether the top-down or bottom-up method is used,
the end result is a modular program. This end result is important, because not all errors may be detected at
the time of the initial testing.
It is possible that there are still bugs in the program. If an error is discovered after the program supposedly
has been fully tested, then the modules concerned can be isolated and retested by them.
Regardless of the design method used, if a program has been written in modular form, it is easier to detect
the source of the error and to test it in isolation, than if the program were written as one function.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 4
Data Structure and Algorithms
4.3. Top-down Algorithm design
Top-down algorithm design is a systematic problem-solving strategy where you start with a high-level
overview of a complex system and break it down into smaller, more manageable sub-components. This
process, also known as stepwise refinement or decomposition, continues until each sub-part is simple
enough to be coded as a single function or module.
The principles of top-down design dictates that a program should be divided into a main module and its
related modules. Each module should also be divided into sub modules according to software engineering
and programming style. The division of modules processes until the module consists only of elementary
process that is intrinsically understood and cannot be further subdivided.
Main
Functions called by main
Function 1 Function 2 Function 3
Function a Function b Function c Function c
Functions called by function 1 function called by
function 2
Top-down algorithm design is a technique for organizing and coding programs in which a hierarchy of
modules is used, and breaking the specification down into simpler and simpler pieces, each having a single
entry and a single exit point, and in which control is passed downward through the structure without
unconditional branches to higher levels of the structure. That is top-down programming tends to generate
modules that are based on functionality, usually in the form of functions or procedures or methods.
In C, the idea of top-down design is done using functions. A C program is made of one or more functions,
one and only one of which must be named main. The execution of the program always starts and ends with
main, but it can call other functions to do special tasks.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 5
Data Structure and Algorithms
4.4. Bottom-up Algorithm Design
Bottom-up algorithm design is a problem-solving strategy that begins by addressing the smallest, most
basic sub-problems first. These individual solutions are then combined and integrated to solve increasingly
complex parts until the entire system is complete; Bottom-up algorithm design is the opposite of top-down
design.
It refers to a style of programming where an application is constructed starting with existing primitives of
the programming language, and constructing gradually more and more complicated features, until the all of
the application has been written. That is, starting the design with specific modules and build them into more
complex structures, ending at the top.
The bottom-up method is widely used for testing, because each of the lowest-level functions is written and
tested first. This testing is done by special test functions that call the low-level functions, providing them
with different parameters and examining the results for correctness. Once lowest-level functions have been
tested and verified to be correct, the next level of functions may be tested. Since the lowest-level functions
already have been tested, any detected errors are probably due to the higher-level functions. This process
continues, moving up the levels, until finally the main function is tested.
4.5. Structured Programming
Structured programming is a fundamental software development model designed to improve program
clarity, quality, and maintainability. It achieves this by breaking complex problems into modular blocks and
utilizing logical control flows: sequence, selection, and repetition. Crucially, it discourages unstructured,
chaotic jumps in execution; It is a programming style; and this style of programming is known by several
names: Procedural decomposition, Structured programming, etc…; Structured programming is not
programming with structures but by using following types of code structures to write programs:
1. Sequence of sequentially executed statements
2. Conditional execution of statements (i.e., “if” statements)
3. Looping or iteration (i.e., “for, do...while, and while” statements)
4. Structured subroutine calls (i.e., functions)
In particular, the following language usage is forbidden:
• “GoTo” statements
• “Break” or “continue” out of the middle of loops
• Multiple exit points to a function/procedure/subroutine (i.e., multiple “return” statements)
• Multiple entry points to a function/procedure/subroutine/method
In this style of programming there is a great risk that implementation details of many data structures have to
be shared between functions, and thus globally exposed. This in turn tempts other functions to use these
implementation details; thereby creating unwanted dependencies between different parts of the program.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 6
Data Structure and Algorithms
4.6. Data structure classification
We can classify the data structures in several ways:
a) Linear and Non linear data structures. Linear data structures organize the data in a sequential
order, like you store data on to arrays. Non Linear data types store the data values in such a fashion
so that relationships can be exhibited. Trees and Graphs are examples of non linear data structures.
In trees, for example, we can depict an organizations hierarchy.
b) Homogenous and Non homogenous data structures. Arrays which store same data types are
called homogenous data structures while structures of C language can be called non homogenous
data structures.
c) Static and dynamic data structures. The memory locations and sizes of static data structures are
fixed at compile time itself while they are dynamically allotted at run time in case of dynamic data
structures.
The type of data structure to be used in a program depends on factors such as program execution time and
storage space.
Data Structure and Algorithms (Prepared by Mr Gratien TWAHANYIMPETA) Page 7