Sie sind auf Seite 1von 10

Chapter 2

Program Analysis
Programming is the software concept where it is the playback of
computer job, computer person should be perfect in the
programming. The results of any computer job,printout, layput,
results, data processing. All works are basically depends upon the
programming technique and accuracy of programming.Your
program tells computer to do particular job in desired manner.
Program development is not so simple it requires number of
systematic working steps to make it simple and perfect. Program
development is a skill, it requires logic. Any problem, which is to
be computerised, must be properly analysed and organised. It is
to be always planned because computer is very precious and one
cant afford computer by experimentally on methods of problem
solving.
Any problem,which has to be converted in computer program,
must be carefully analysed. Program analysis consisys in finding
or deriving the procedural steps involved in getting the solution to
a problem. That step must come within the computer capabilities.
e.g Problem statement
add 2 numbers and display the result
1.
2.
3.
4.

Take 2 numbers suppose A and B as input.


Add 2 numbers.
Store the result in c.
Display value of c.

In this way above simple problem is divided into 4 steps.


For analysis various methods are used. These methods are:
1. Flowchart
2. Algorithm
3. Pseudo code

Nirmala Memorial Foundation college of Commerce and Science

Page 1

Program Development
Program is a list of instructions in specific language to tell the
computer to do the job in sequence. Before writing a program
user has to define problem. Problem is first analyzed. Actually
problem solution gets converted into program. But for
conversation there is process of programming. Programming is a
process for development of program, for a specific problem.
Whenever problem has to be converted in to a program, then oits
process has following steps :
1.
2.
3.
4.
5.

Problem analysis
Design
Coding
Testing
Documentation

1. Problem analysis
You should have complete definition of problem and the
requirements should be clear before writing the solution.
Generally every program needs input, output, storage and
process.
2. Design
A business function when implemented in a computer system is
termed as a program. Before a program is developed, it must be
designed. Program developers use tools such as pseudocode, flow
chart, and hierarchy chart to design
programs.
3. Coding
After a program is designed, it is implemented. A program code is
a set of instructions developed by a programmer to carry out the
business functionality in a particular language such as VB, C#,
Java, ASP, etc.
4. Testing
As the program is being coded, and after the code is completed it
must be tested to see that program is running properly and it
produces required outputs with appropriate input data.
Nirmala Memorial Foundation college of Commerce and Science

Page 2

5. Documentation
As a program is being coded, and after the coding is
completed, the developers should document the program.
Documenting a program means writing down some instruction for
the users, the purpose of the program, the
way it performs the tasks, the inputs and the outputs expected.
Once each program or sub-program is documented, it is
necessary to create documentation for the whole business
information system.

Problem Analysis Tools


There are various tools for problem analysis. As we have already
said for analysis or for defining logic we have to divide program
into steps, then you can show overall logic using following
methods :
a) Algorithm
b) Flowchart
c) Pseudo code
a) Algorithm :
Algorithm is a logical sequence of steps prepared for solving
problem. It is not a programming language or program.
The characteristics of a good algorithm are:

Precision the steps are precisely stated(defined).

Uniqueness results of each step are uniquely defined and


only depend on the input and the result of the preceding steps.

Finiteness the algorithm stops after a finite number of


instructions are executed.

Input the algorithm receives input.

Output the algorithm produces output.

Generality the algorithm applies to a set of inputs.

b) Flowchart
Nirmala Memorial Foundation college of Commerce and Science

Page 3

Flow Line
Flow line connectors show the direction
(Arrow,
that the process flows.
Connector)
Terminators show the start and stop
Terminator points in a process. When used as a Start
(Terminal
symbol, terminators depict a trigger
Point, Oval) action that sets the process flow into
motion.
Decision

Indicates a question or branch in the


process flow. Typically, a Decision
flowchart shape is used when there are 2
options (Yes/No, No/No-Go, etc.)

Flowchart: In flowcharts, this symbol is


typically small and is used as a Connector
to show a jump from one point in the
process flow to another. Connectors are
usually labeled with capital letters (A, B,
AA) to show matching jump points. They
are handy for avoiding flow lines that
cross other shapes and flow lines. They
are also handy for jumping to and from a
Connector
sub-processes defined in a separate area
(Inspection
than the main flowchart.
)
Process Mapping: In process maps, this
symbol is full sized and shows an
Inspection point in the process flow.
[Just to confuse things further, some
people will use a circle to indicate an
operation and a square to indicate an
inspection. That's why it's important to
include a symbol key in the flowchart.]
Process

Show a Process or action step. This


is the most common symbol in both
process flowcharts and process
maps.

Nirmala Memorial Foundation college of Commerce and Science

Page 4

c)

Pseu
do
code
:
It is a programming analysis tool used for planning program logic.
Pseudo meand false and code refers to the instruction written in
Nirmala Memorial Foundation college of Commerce and Science

Page 5

programming language. It is an imitation of actual computer


instruction.
Pseudo code is made up of following basic logic structures that
have been proved to be sufficient for writing any computer
program.
1. Sequence
2. Selection
3. Iteration
Advantages :
* It can be easily in any word processor.
* It can be easily modified as compared to flowchart.
* It's implementation is very useful in structured design elements.
* It can be written easily.
* It can be read and understood easily.
* Converting a pseudocode to programming language is very easy
as compared with converting a flowchart to programming
language.
Disadvantages :
* It is not visual.
* We do not get a picture of the design.
* There is no standardised style or format, so one pseudocode
may be different from another.
* For a beginner, It is more difficult to follow the logic or write
pseudocode as compared to flowchart.
Programming techniques:
There are two basic techniques:
1. Structure programming
Structured programming is a programming paradigm aimed at
improving the clarity, quality, and development time of a
computer program by making extensive use of subroutines, block
structures and for and while loopsin contrast to using simple
tests and jumps such as the goto statement.
Following the structured program theorem, all programs are seen
as composed of three control structures:

Nirmala Memorial Foundation college of Commerce and Science

Page 6

"Sequence" : ordered statements or subroutines executed in


sequence.
"Selection": one or a number of statements is executed
depending on the state of the program. This is usually expressed
with keywords such as if..then..else..endif.
"Iteration": a statement or block is executed until the program
reaches a certain state, or operations have been applied to every
element of a collection. This is usually expressed with keywords
such as while, repeat, for or do..until. Often it is recommended
that each loop should only have one entry point (and in the
original structural programming, also only one exit point, and a
few languages enforce this).
2. Modular programming
Modular programming is a software design technique that
emphasizes separating the functionality of a program into
independent, interchangeable modules, such that each contains
everything necessary to execute only one aspect of the desired
functionality.[1]
A module interface expresses the elements that are provided and
required by the module. The elements defined in the interface are
detectable by other modules. The implementation contains the
working code that corresponds to the elements declared in the
interface. Modular programming is closely related to structured
programming and object-oriented programming, all having the
same goal of facilitating construction of large software programs
and systems by decomposition into smaller pieces, and all
originating around the 1960s. While historically usage of these
terms has been inconsistent, today "modular programming" refers
to high-level decomposition of the code of an entire program into
pieces, structured programming to the low-level code use of
structured control flow, and object-oriented programming to the
data use of objects, a kind of data structure.
Searching
1. Linear search
Nirmala Memorial Foundation college of Commerce and Science

Page 7

Linear search or sequential search is a method for finding a


particular value in a list, that consists of checking every one of its
elements, one at a time and in sequence, until the desired one is
found. Linear search is the simplest search algorithm. For a list
with n items, the best case is when the value is equal to the first
element of the list, in which case only one comparison is needed.
The worst case is when the value is not in the list (or occurs only
once at the end of the list), in which case n comparisons are
needed.
The worst case performance scenario for a linear search is that it
has to loop through the entire collection, either because the item
is the last one, or because the item is not found. In other words, if
you have N items in your collection, the worst case scenario to
find an item is N iterations.
2.Binary search :
The binary search algorithm begins by comparing the target value
to value of the middle element of the sorted array. If the target
value is equal to the middle element's value, the position is
returned. If the target value is smaller, the search continues on
the lower half of the array, or if the target value is larger, the
search continues on the upper half of the array. This process
continues until the element is found and its position is returned,
or there are no more elements left to search for in the array and a
"not found" indicator is returned.
Bubble sort
A bubble sort is an internal exchange sort. It is considered one of
the simplest methods to sort an array of objects. It is also known
as a sinking sort (because the smallest items "sink" to the bottom
of the array).
Instead of searching an array as a whole, the bubble sort works by
comparing adjacent pairs of objects in the array. If the objects are
not in the correct ordered, they are swapped so that the largest of
the two moves up. This process continues until the largest of the
objects, eventually "bubbles" up to the highest position in the
array. After this occurs, the search for the next largest object
Nirmala Memorial Foundation college of Commerce and Science

Page 8

begins. The swapping continues until the whole array is in the


correct order.
Bubble sort algorithm starts by comparing the first two
elements of an array and swapping if necessary, i.e., if you
want to sort the elements of array in ascending order and if
the first element is greater than second then, you need to
swap the elements but, if the first element is smaller than
second, you mustn't swap the element. Then, again second
and third elements are compared and swapped if it is
necessary and this process go on until last and second last
element is compared and swapped. This completes the first
step of bubble sort.
If there are n elements to be sorted then, the process
mentioned above should be repeated n-1 times to get
required result. But, for better performance, in second step,
last and second last elements are not compared becuase, the
proper element is automatically placed at last after first step.
Similarly, in third step, last and second last and second last
and third last elements are not compared and so on.

Step-by-step example
Let us take the array of numbers "5 1 4 2 8", and sort the array
from lowest number to greatest number using bubble sort. In
each step, elements written in bold are being compared. Three
passes will be required.
First Pass:
(51428)
( 1 5 4 2 8 ), Here, algorithm compares the first
two elements, and swaps since 5 > 1.
(15428)
( 1 4 5 2 8 ), Swap since 5 > 4
(14528)
( 1 4 2 5 8 ), Swap since 5 > 2
(14258)
( 1 4 2 5 8 ), Now, since these elements are
already in order (8 > 5), algorithm does not swap them.
Second Pass:
(14258)
(14258)
(14258)
( 1 2 4 5 8 ), Swap since 4 > 2
(12458)
(12458)
Nirmala Memorial Foundation college of Commerce and Science

Page 9

(12458)
(12458)
Now, the array is already sorted, but the algorithm does not know
if it is completed. The algorithm needs one whole pass
without any swap to know it is sorted.
Third Pass:
(12458)
(12458)
(12458)
(12458)
(12458)
(12458)
(12458)
(12458)
Disadvantages:
It's the slowest type of sort... Imagine comparing and swapping a
list of 300 elements, analyzing pair by pair. The process gets
long!
Experts advise against the use of the bubble sort for repetitive
sorts or sorts that contain more than a few hundred objects.

Nirmala Memorial Foundation college of Commerce and Science

Page 10

Das könnte Ihnen auch gefallen