Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
100% found this document useful (1 vote)
47 views

22CS110 - 210-Unit-1 - Art of Programming Through Algorithms and Flowcharts

Uploaded by

Riddhi Gayathri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
47 views

22CS110 - 210-Unit-1 - Art of Programming Through Algorithms and Flowcharts

Uploaded by

Riddhi Gayathri
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Art of Programming through Algorithms and Flowcharts

PROBLEM SOLVING TECHNIQUES - SIMPLIFIED APPROACH


In order to solve a given problem (Problem Statement) using computer, follow the certain
steps:
⮚ Understanding and Analyzing the problem
By identifying the facts (Data items involved such as knowns/constants and
unknowns/variables, Data types i.e., type of data it holds e.g., whole numbers/real
numbers, etc., and their Relationships)
⮚ Plan the solution
Using two tools: Algorithm and Flowchart
⮚ Test the solution
Using 2-3 set of inputs at least and calculate the expected output
⮚ Code the solution
Using suitable programming language like C, C++, Java, R, Python, etc.,
⮚ Documentation
⮚ Implementation

ALGORITHM: Algorithm = Calculation Procedure


This is a problem-solving technique, cab defined as a step-by-step procedure to solve a
particular problem. An algorithm is a procedure (a finite set of well-defined
instructions) for accomplishing some tasks which, given an initial state, will terminate in
a defined end-state. An algorithm (pronounced AL-go-rith-um) is a procedure or formula
for solving a problem. The word derives from the name of the mathematician,
Mohammed ibn-Musa al-Khwarizmi.
The traditional definition of "algorithm" is that it is a formally defined procedure for
performing some calculation.
Algorithmic Notations are Name of the algorithm, Step Number, Explanatory
Comment and Termination.
According to D E Knuth, a pioneer in the computer science discipline, an algorithm has
five important features.
i. Finiteness: An algorithm terminates after a fixed number of steps.
ii. Definiteness: Each step of the algorithm is precisely defined, i.e. the action to be
carried out should be specified unambiguously.
iii. Effectiveness: All the operations used in the algorithm are basic (division,
multiplication, comparison, etc, ) and can be performed exactly in a fixed duration
of time.
iv. Input: An Algorithm has certain precise inputs, i.e. quantities which are specified
to it initially, before the execution of the algorithm begins.
v. Output: An Algorithm has one or more outputs, that is, the results of operations
which have a specified relation to the inputs.

Page 1 of 7
FLOWCHART: A schematic representation of a process
A graphic representation of an algorithm, often used in the design phase of programming
to work out the logical flow of a program. A flowchart is a diagrammatic representation
that illustrates the sequence of operations to be performed to get the solution of a
problem. Flowcharts facilitate communication between programmers and business
people. Once the flowchart is drawn, it becomes easy to write the program in any
high-level language. Often, we see how flowcharts are helpful in explaining the program
to others. A flowchart is a must for the better documentation of a complex program.
The benefits of flowcharts are as follows:
1. Communication: Flowcharts are better way of communicating the logic of a system to all
concerned.
2. Effective analysis: With the help of flowchart, problem can be analysed in more effective way.
3. Proper documentation: Program flowcharts serve as a good program documentation, which is
needed for various purposes.
4. Efficient Coding: The flowcharts act as a guide or blueprint during the systems analysis and
program development phase.
5. Proper Debugging: The flowchart helps in debugging process.
6. Efficient Program Maintenance: The maintenance of operating program becomes easy with the
help of flowchart. It helps the programmer to put efforts more efficiently on that part.
Guidelines for drawing a flowchart: Flowcharts are usually drawn using following
standard symbols;
Name Symbol Use in Flowchart / Function
Oval Denotes the Beginning or End of a program.

Parallelogram Denotes either an input operation or an


output operation.

Rectangle Denotes a process to be carried out.

Rhombus or Denotes a Decision (or Branch) to be made.


Diamond The program should continue along one of
two routes.

Circle Denotes Continuation.

Hexagon Denotes Repetition / Looping.

Arrows/Flowlines Denotes the direction of logic flow in a


program.

Page 2 of 7
Pseudocode is a compact and informal high-level description of a computer
programming algorithm that uses the structural conventions of a programming language,
but is intended for human reading rather than machine reading. Pseudocode typically
omits details that are not essential for human understanding of the algorithm, such as
variable declarations, system-specific code and subroutines. No standard for pseudocode
syntax exists, as a program in pseudocode is not an executable program. Pseudocode
resembles, but should not be confused with, skeleton programs including dummy code,
which can be compiled without errors. Flowcharts can be thought of as a graphical
alternative to pseudocode.
DIVIDE AND CONQUER STRATEGY
The divide-and-conquer methodology is very similar to the modularization approach to
software design. Small instance of a problem is solved using some direct approach.
To solve large instance,
(a) We divide it into two or more smaller instances,
(b) Solve each of these smaller problems, and
(c) Combines the solutions of these smaller problems to obtain the solution to the
original instance.
The smaller instances are often instances of the original problem and may be solved using
the divide-and-conquer strategy recursively. Problems like Sorting (Quick, Merge) Binary
Searching etc.,
Writing algorithms and Drawing Flowcharts for simple exercises:
(i) Swapping content of two variables.
(ii) Largest of given three numbers.
(iii) Solving a given quadratic equation.
(iv) Factorial of a given integer.

Page 3 of 7
(i) Swapping content of two variables.
Algorithm: To swap content of two variables.
STEPS PROCEDURES
Step-1: Begin
Step-2: Read the value of A and B
Step-3: Assign, Temp = A or A = A + B
A=B or B = A - B
B = Temp or A = A - B
Step-4: Print “The Value of A and B”, A, B
Step-5: End
Flowchart: To swap content of two variables.

(ii)Largest of given three numbers.


Algorithm: To find the largest of given three numbers.
STEPS PROCEDURES
Step-1: Begin
Step-2: Read the value of A, B and C
Step-3: Compare A and B
Compare (A>B) go to Step-5
Step-4: Otherwise Compare B with C
Compare (B>C) then
Print “B is the Largest”
otherwise
Print “C is the Largest”
Go to Step-6
Step-5: Compare A with C
Compare (A>C) then
Print “A is the Largest”
otherwise
Print “C is the Largest”
Step-6: End

Page 4 of 7
Flowchart: To find the largest of given three numbers.

(iii) Solving a given quadratic equation


Algorithm: To find the solution of the quadratic equation.
STEPS PROCEDURES
Step-1: Begin
Step-2: Read the value of a, b and c
Step-3: Calculate the Discriminant,
disc = b2 - 4 a c
Step-4: Compare (disc < 0 )
Print “The Roots are Imaginary” go to Step-7
Step-5: Otherwise, Calculate root1 and root2
root1 = ( - b + √(disc)) / ( 2a )
root2 = ( - b - √(disc)) / ( 2a )
Step-6: Print “Root1 and Root2 =”, root1, root2
Step-7: End

Page 5 of 7
Flowchart: To find the solution of the quadratic equation.

No Yes

(iv) Factorial of a given integer.


Algorithm: To find the factorial of a given integer. (N!)
STEPS PROCEDURES
Step-1: Begin
Step-2: Read the value of N
Step-3: Assign,
M=1
F=1
Step-4: Compute the FACT
F=FxM
Step-5: Compare M with N
(M equals to N) go to Step-7
Step-6: Otherwise, Update M
Compute M = M + 1, go to Step-4
Step-7: Print Factorial of N = F
Step-8: End

Page 6 of 7
Flowchart: To find the factorial of a given integer. (N!)

Page 7 of 7

You might also like