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

CHAPTER 2 - PRINCIPLES OF PROGRAMMING & DESIGN OF ALGORITHMSds

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

CHAPTER -2

PRINCIPLES OF PROGRAMMING & DESIGN OF ALGORITHMS

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 1: Requirement collection and analysis

Phase 2: Feasibility study:

Phase 3: Design:

Phase 4: Coding:

Phase 5: Testing:

Phase 6: Installation/Deployment:

Phase 7: Maintenance:

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 1


Phase 1: Requirement collection and analysis

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.

Phase 2: Feasibility study

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.

There are mainly five types of feasibilities checks:

 Economic: Can we complete the project within the budget or not?


 Legal: Can we handle this project as cyber law and other regulatory
framework/compliances.
 Operation feasibility: Can we create operations which is expected by the client?
 Technical: Need to check whether the current computer system can support the software
 Schedule: Decide that the project can be completed within the given schedule or not.

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.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 2


There are two kinds of design documents developed in this phase:

High-Level Design (HLD)

 Brief description and name of each module


 An outline about the functionality of every module
 Interface relationship and dependencies between modules
 Database tables identified along with their key elements
 Complete architecture diagrams along with technology details

Low-Level Design(LLD)

 Functional logic of the modules


 Database tables, which include type and size
 Complete detail of the interface
 Addresses all types of dependency issues
 Listing of error messages
 Complete input and outputs for every module

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.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 3


During this phase, QA and testing team may find some bugs/defects which they communicate to
developers. The development team fixes the bug and sends back to QA for a re-test. This process
continues until the software is bug-free, stable, and working according to the business needs of
that system.

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

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 4


Top-down 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.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 5


ALGORITHM ANALYSIS

An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In


addition, all algorithms must satisfy the following criteria.

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.

3. Finiteness: An algorithm should terminate after a finite no. of operations.

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

The space complexity of an algorithm is the amount of memory it needs to run.

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.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 6


Data Structures - Asymptotic Analysis
Asymptotic analysis of an algorithm refers to defining the mathematical bounding/framing of its
run-time performance. Using asymptotic analysis, we can very well conclude the best case,
average case and worst case scenario of an algorithm.

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.

Usually, time required by an algorithm falls under three types

 Best Case − Minimum time required for program execution.


 Average Case − Average time required for program execution.
 Worst Case − Maximum time required for program execution.

Asymptotic Notations
Following are commonly used asymptotic notations used in calculating running time
complexity of an algorithm.

 Ο Notation
 Ω Notation
 θ Notation

Big Oh Notation, Ο

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 7


The Ο(n) is the formal way to express the upper bound of an algorithm's running time. It
measures the worst case time complexity or longest amount of time an algorithm can possibly
take to complete.

For example, for a function f(n)

Ο(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.

For example, for a function f(n)

Ω(f(n)) ≥ { g(n) : there exists c > 0 and n0 such that g(n) ≤ c.f(n) for all n
> n0. }

Theta Notation, θ

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 8


The θ(n) is the formal way to express both the lower bound and upper bound of an algorithm's
running time. It is represented as following −

θ(f(n)) = { g(n) if and only if g(n) = Ο(f(n)) and g(n) = Ω(f(n)) for all n
> n0. }

Common Asymptotic Notations


constant − Ο(1)

logarithmic − Ο(log n)

linear − Ο(n)

n log n − Ο(n log n)

quadratic − Ο(n2)

cubic − Ο(n3)

polynomial − nΟ(1)

exponential − 2Ο(n)

STRUCTURED APPROACH TO PROGRAMMING

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 9


Structured programming is a method for designing and coding programs in a systematic,
organized manner. Some of the control structures which can be used for structured programming
are:

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:

1) Find the Key Step:

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.

2) Find a Stopping Rule:

The stopping rule indicates that the problem or a substantial part of it is done and the execution
of the algorithm can be stopped.

3) Outline your Algorithm:

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:

Function for factorial using Recursion:

factorial(n)

int n;

int fact = 1;

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 11


if ( n > 1)

fact = n*factorial(n-1);

return(fact);

TIPS AND TECHNIQUES FOR WRITING ‘’C” PROGRAMS

A program in any language is a collection of one or more functions. Every function is a


collection of statements which performs a specific task. A program written in “C” language can
have the following format:

A program starts with comments enclosed between /* and */. Comments can be given anywhere
in the program.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 12


The pre-processor directives are executed before ‘C’ program code passes through the compiler.
These pre-processor directives make programs more efficient. Most commonly used directives
are: #include which includes files, #define which defines the macro name and macro expansion.

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:

typedef type and dataname

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.

Prepared by Dr.B.GOPI, Asst. Professor, KIST, KAKUTUR, NELLORE,A.P Page 13

You might also like