0% found this document useful (0 votes)
6 views29 pages

CP Unit-1

Uploaded by

Vaibhav Tamboli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views29 pages

CP Unit-1

Uploaded by

Vaibhav Tamboli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

Fundamentals of

Programming
Algorithm
• In computer programming terms, an algorithm is a set of well-defined
instructions to solve a particular problem. It takes a set of input(s)
and produces the desired output.
Algorithm
• The Algorithm designed are language-independent, i.e. they are just
plain instructions that can be implemented in any language, and yet
the output will be the same, as expected.

An algorithm to add two numbers:


1.Take two number as inputs
2.Add numbers using the + operator
3.Display the result
Characteristics of an Algorithm
• Clear and Unambiguous: The algorithm should be clear and
unambiguous. Each of its steps should be clear in all aspects
and must lead to only one meaning.
• Well-Defined Inputs: If an algorithm says to take inputs, it
should be well-defined inputs. It may or may not take input.
• Well-Defined Outputs: The algorithm must clearly define
what output will be yielded and it should be well-defined as
well. It should take at least 1 output.
Characteristics of an Algorithm
• Finite-ness: The algorithm must be finite, i.e. it should
terminate after a finite time.
• Feasible: The algorithm must be simple, generic, and practical,
such that it can be executed with the available resources. It
must not contain some future technology or anything.
• Language Independent: The Algorithm designed must be
language-independent, i.e. it must be just plain instructions
that can be implemented in any language, and yet the output
will be the same, as expected.
Properties of Algorithm
• It should terminate after a finite time.
• It should produce at least one output.
• It should take zero or more input.
• It should be deterministic means giving the same output for
the same input case.
• Every step in the algorithm must be effective i.e. every step
should do some work.
Advantages of algorithm
• It is easy to understand.
• An algorithm is a step-wise representation of a solution to a
given problem.
• In Algorithm the problem is broken down into smaller pieces
or steps hence, it is easier for the programmer to convert it
into an actual program.
Disadvantages of Algorithm
• Writing an algorithm takes a long time so it is time-
consuming.
• Understanding complex logic through algorithms can be very
difficult.
• Branching and Looping statements are difficult to show in
Algorithms
Pseudo code
• Pseudo code is an implementation of an algorithm in the form
of annotations and informative text written in plain English.
• It has no syntax like any of the programming language and thus
can’t be compiled or interpreted by the computer.
• It is used for creating an outline or a rough draft of a program
Algorithm, Pseudo code and Program: Difference
• Algorithm: Systematic logical approach which is a well-
defined, step-by-step procedure that allows a computer to
solve a problem.
• Pseudocode : It is a simpler version of a programming
code in plain English which uses short phrases to write code
for a program before it is implemented in a specific
programming language.
• Program : It is exact code written for problem following all
the rules of the programming language.
Flowchart

Input p,r,t

Print SI
Basic Symbols used in Flow chart design
Basic Symbols used in Flow chart design
Flow chart of
if statement
Flow chart of
if-else
statement
Draw a flowchart to
input two numbers
from the user and
display the largest of
two numbers
Flow chart to add
two numbers
entered by the user.
Find the largest
among three
different numbers
entered by the user.
Flow chart
of if-else-if
statement
Flow chart of
While loop
Flow chart of
do-While
loop
Flow chart of
for loop
Flow chart of
break
statement
Flow chart of
continue
statement
Flow chart of
switch
statement
Check odd or
even
number
Flowchart: Advantages
• Communication: A flowchart is a better way of communicating the logic of a program.
• Efficient Coding: Flowcharts act as a guide for a programmer in writing the actual code
in a high-level language.
• Proper Debugging: Flowcharts help in the debugging process.
• Effective Analysis: Effective analysis of logical programs can be easily done with the
help of a related flowchart.
• Proper Documentation: Flowchart provides better and proper documentation. It
consists of various activities such as collecting, organizing, storing, and maintaining all
related program records.
• Testing: A flowchart helps in the testing process.
• Efficient program maintenance: The maintenance of the program becomes easy with
the help of a flowchart.
Flowchart: Disadvantages
• Time-consuming: Designing a flowchart is a very time-consuming
process.
• Complex: It isn't easy to draw a flowchart for large and complex
programs.
• There is no standard in the flowchart; there is no standard to
determine the quantity of detail.
• Difficult to modify: It is very difficult to modify the existing
flowchart.

You might also like