CHAPTER 2 - PRINCIPLES OF PROGRAMMING & DESIGN OF ALGORITHMSds
CHAPTER 2 - PRINCIPLES OF PROGRAMMING & DESIGN OF ALGORITHMSds
CHAPTER 2 - PRINCIPLES OF PROGRAMMING & DESIGN OF ALGORITHMSds
SOFTWARE ENGINEERING
Software Engineering is the theory and practice of methods for the construction and maintenance
of large software systems. There are many stages in the software development cycle. The process
is often referred to as Software Development Life Cycle (SDLC). In SDLC, the output from one
stage becomes the input to the next stage.
Phase 3: Design:
Phase 4: Coding:
Phase 5: Testing:
Phase 6: Installation/Deployment:
Phase 7: Maintenance:
The requirement is the first stage in the SDLC process. It is conducted by the senior team
members with inputs from all the stakeholders and domain experts in the industry. Planning for
the quality assurance requirements and recognition of the risks involved is also done at this stage.
This stage gives a clearer picture of the scope of the entire project and the anticipated issues,
opportunities, and directives which triggered the project.
Requirements Gathering stage need teams to get detailed and precise requirements. This helps
companies to finalize the necessary timeline to finish the work of that system.
Once the requirement analysis phase is completed the next sdlc step is to define and document
software needs. This process conducted with the help of 'Software Requirement Specification'
document also known as 'SRS' document. It includes everything which should be designed and
developed during the project life cycle.
Phase 3: Design
In this third phase, the system and software design documents are prepared as per the
requirement specification document. This helps define overall system architecture.
This design phase serves as input for the next phase of the model.
Low-Level Design(LLD)
Phase 4: Coding
Once the system design phase is over, the next phase is coding. In this phase, developers start
build the entire system by writing code using the chosen programming language. In the coding
phase, tasks are divided into units or modules and assigned to the various developers. It is the
longest phase of the Software Development Life Cycle process.
In this phase, Developer needs to follow certain predefined coding guidelines. They also need to
use programming tools like compiler, interpreters, debugger to generate and implement the code.
Phase 5: Testing
Once the software is complete, and it is deployed in the testing environment. The testing team
starts testing the functionality of the entire system. This is done to verify that the entire
application works according to the customer requirement.
Phase 6: Installation/Deployment
Once the software testing phase is over and no bugs or errors left in the system then the final
deployment process starts. Based on the feedback given by the project manager, the final
software is released and checked for deployment issues if any.
Phase 7: Maintenance
Once the system is deployed, and customers start using the developed system, following 3
activities occur
Bug fixing - bugs are reported because of some scenarios which are not tested at all
Upgrade - Upgrading the application to the newer versions of the Software
Enhancement - Adding some new features into the existing software
The main focus of this SDLC phase is to ensure that needs continue to be met and that the
system continues to perform as per the specification mentioned in the first phase.
PROGRAM DESIGN
Program design can be considered as important phase of the software development life cycle. As
the design stage involves taking the specifications and designing solutions to the problems, the
designer needs to adapt a design strategy. The strategy adapted while designing should be
according to the given specifications.
A large program should be divided into small modules and sub-modules by following one of the
two decomposition approaches:
Top-down approach
Bottom-up approach
Top-Down Model is a system design approach where design starts from the system as a whole.
Complete System is then divided into smaller sub-applications with more details. Each part again
goes through the top-down approach till the complete system is designed with all minute details.
Top Down approach is also termed as breaking the bigger problem into smaller problems and
solving them individually in recursive manner.
Bottom-Up approach
Bottom-Up Model is a system design approach where parts of the system are defined in details.
Once these parts are designed and developed, then these parts or components are linked together
to prepare a bigger component. This approach is repeated until the complete system is built.
Advantage of Bottom-Up Model is in making decisions at very low level and to decide the re-
usability of components.
Following are the important differences between Bottom-Up Model and Top-Down Model.
Other important criteria by which a program can be designed are execution time and storage
requirement.
1. Input
2. Output
3. Definiteness
4. Finiteness
5. Effectiveness
1. Input& Output: An algorithm produces one or more outputs & has zero or more input.
2. Definiteness: Each operation must be definite such that it must be perfectly clear what should
be done.
4. Effectiveness: Every instruction must be very basic so that it can be carried out.
There may be many algorithms devised for an application and we must analyze and validate the
algorithms to judge the suitable one.
To judge an algorithm the most important factors is to have a direct relationship to the
performance of the algorithm. These have to do with their computing time & storage
requirements referred as Time complexity & Space complexity.
Space Complexity
Time Complexity
The time taken by a program is the sum of the compiled time & the run time. The time
complexity of an algorithm is given by the number of steps taken by the algorithm to compute
the function it was written for.
Asymptotic analysis are input bound i.e., if there's no input to the algorithm it is concluded to
work in a constant time. Other than the "input" all other factors are considered constant.
Asymptotic analysis refers to computing the running time of any operation in mathematical
units of computation. For example, running time of one operation is computed as f(n) and may
be for another operation it is computed as g(n2) which means first operation running time will
increase linearly with the increase in n and running time of second operation will increase
exponentially when n increases. Similarly the running time of both operations will be nearly
same if n is significantly small.
Asymptotic Notations
Following are commonly used asymptotic notations used in calculating running time
complexity of an algorithm.
Ο Notation
Ω Notation
θ Notation
Big Oh Notation, Ο
Ο(f(n)) = { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n
> n0. }
Omega Notation, Ω
The Ω(n) is the formal way to express the lower bound of an algorithm's running time. It
measures the best case time complexity or best amount of time an algorithm can possibly take to
complete.
Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n
> n0. }
Theta Notation, θ
θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n
> n0. }
logarithmic − Ο(log n)
linear − Ο(n)
quadratic − Ο(n2)
cubic − Ο(n3)
polynomial − nΟ(1)
exponential − 2Ο(n)
Structured Programming emphasises functional specialization and tries to ensure that only one
primary function is allocated to any module.
RECURSION
Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 10
Recursion means a function or procedure calling itself.
Principles of Recursion
Some basic principles which are used while designing algorithms with recursion are:
When beginning with the design of algorithms through recursion one should try to find out the
“Key step” for the solution. Once you have executed the key step, find out whether the remainder
of the problem can be solved in the same way and modify the step, if necessary.
The stopping rule indicates that the problem or a substantial part of it is done and the execution
of the algorithm can be stopped.
After determining the key step for the problem and finding the cases which are to be handled, the
next step is to combine these two using an “if” statement to select between them. The main
program and the procedure for recursion are now to be written to carry the key step through until
the stopping rule applies.
4) Check Termination:
Care should be taken to ensure that the recursion will always terminate after the finite number of
steps and the stopping rule should also be satisfied. It should handle the extreme cases correctly.
Example:
factorial(n)
int n;
int fact = 1;
fact = n*factorial(n-1);
return(fact);
A program starts with comments enclosed between /* and */. Comments can be given anywhere
in the program.
Example:
# define TRUE 1
# define FALSE 0
Then there are declarations for global variables, which have the same data type and same name
throughout the function and are defined outside the main() function.
Another keyword which can be used is typedef which is used for defining new data types. The
syntax for typedef is:
Here type is the data type and the data name is user defined name.
‘C’ program contains a main() function but the program should be divided into functions. A
function is a self-contained subprogram which performs some specific, well defined task.