0% found this document useful (0 votes)
6 views

Lect1

The document covers the fundamentals of algorithms, pseudocode, and flowcharts in programming for problem-solving. It defines algorithms and their characteristics, outlines structured programming concepts, and provides guidelines for developing algorithms and pseudocode. Additionally, it explains the use of flowcharts as a graphical representation of algorithms, including standard symbols and rules for their construction.

Uploaded by

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

Lect1

The document covers the fundamentals of algorithms, pseudocode, and flowcharts in programming for problem-solving. It defines algorithms and their characteristics, outlines structured programming concepts, and provides guidelines for developing algorithms and pseudocode. Additionally, it explains the use of flowcharts as a graphical representation of algorithms, including standard symbols and rules for their construction.

Uploaded by

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

Programming for ProblemSolving

(ES-CS201)

RCCIIT
CSE(SEC C)
Ms. Sukla Banerjee
Asst. Prof., Dept. of CSE
Content

Algorithms

Pseudocode

Flowcharts
Algorithm
An algorithm, is defined as a:
“well-ordered collection of unambiguous and effectively
computable operations, that when executed, produces a result and
halts in a finite amount of time.”
Characteristics of an Algorithm -

Well-ordered: the steps are in a clear order.

Unambiguous: the operations described are understood by a
computing agent without further simplification.

Effectively computable: the computing agent can actually carry out
the operation .
Algorithm
Method for Developing an Algorithm
1) Define the problem: State the problem you are trying to solve in
clear and concise terms.
2) List the inputs (information needed to solve the problem) and the
outputs (what the algorithm will produce as a result).
3) Describe the steps needed to convert or manipulate the inputs to
produce the outputs. Start at a high level first, and keep refining the
steps until they are effectively computable operations.
4) Test the algorithm: choose data sets and verify that your algorithm
works!
Structured Programming:
In 1966, computer scientists Corrado Böhm and Giuseppe Jacopini
demonstrated that all programs could be written using three control structures:
Sequence, Selection, and Repetition.
1) The sequence structure is the construct where one statement is executed
after another
2) The selection structure is the construct where statements can executed or
skipped depending on whether a condition evaluates to TRUE or FALSE
1) There are three selection structures in C:
1) 1. IF
2) 2. IF – ELSE
3) 3. SWITCH
Structured Programming:

3) The repetition structure is the construct where statements


can be executed repeatedly until a condition evaluates to
TRUE or FALSE
1) There are three repetition structures in C:
1) 1. WHILE
2) 2. DO – WHILE
3) 3. FOR
Algorithm to to get two numbers from the user (dividend and
divisor), testing to make sure that the divisor number is not zero,
and displaying their quotient.
Algorithm to find the sum of two
numbers
Algorithm to find Area & Perimeter of Triangle
Pseudocode
(or Program Design Language)

Consists of natural language-like statements that precisely describe the
steps of an algorithm or program.

Statements describe actions.

Focuses on the logic of the algorithm or program.

Avoids language-specific elements.

Written at a level so that the desired programming code can be
generated almost automatically from each statement.

Steps are numbered. Subordinate numbers and/or indentation are used
for dependent statements in selection and repetition structures.
Pseudocode
(or Program Design Language)
Notes:
Some programmers also include data declarations in their
pseudocode.

Some programmers will add an ending ‘keyword’ on a separate line to


make it explicit where a selection or repetition structure ends, for
example: ENDIF, ENDWHILE, etc. such statements will not ‘translate’ into
an actual line of code in C
Pseudocode Language Constructs

Computation/Assignment
Compute var1 as the sum of x and y
Assign expression to var2
Increment counter1
Assignment Symbol (  or =) is used to assign value to the variable.
Pseudocode Language Constructs

Input/Output
Input: Get var1, var2, …
Output: Display var1, var2, …
Selection
Single-Selection IF
1. IF condition THEN (IF condition is true, then do subordinate
statement 1, etc. If condition is false, then skip
statements)
1.1 statement 1
1.2 etc.
Pseudocode Language Constructs
Selection
Double-Selection IF
2. IF condition THEN (IF condition is true, then do subordinate
statement 1, etc. If condition is false, then skip statements
and execute statements under ELSE)
2.1 statement 1
2.2 etc.
3. ELSE (else if condition is not true, then do subordinate statement
2, etc.)
3.1 statement 2
3.2 statement 3
Pseudocode Language Constructs

Selection
Double-Selection IF
4. SWITCH expression TO
4.1 case 1: action1
4.2 case 2: action2
4.3 etc.
4.4 default: actionx
Pseudocode Language Constructs
Pseudocode Language Constructs

Repetition
5. WHILE condition (while condition is true, then do subordinate
statements)
5.1 statement 1
5.2 etc.
DO – WHILE structure (like WHILE, but tests condition at the end of the loop.
Thus, statements in the structure will always be executed at least once.)
6. DO
6.1 statement 1
6.2 etc.
7. WHILE condition
Pseudocode Language Constructs

FOR structure (a specialized version of WHILE for repeating


execution of statements a specific number of times)
8. FOR bounds on repetition
8.1 statement 1
8.2 etc.
Pseudocode Language Constructs
Pseudocode Language Constructs
Pseudocode Language Constructs
Pseudocode Language Constructs
Note:

GO TO statement also called unconditional transfer of control


statement is used to transfer control of execution to another
step/statement. . e.g. the statement GOTO n will transfer control
to step/statement n.

We can use keyword INPUT or READ or GET to accept


input(s) /value(s) and keywords PRINT or WRITE or DISPLAY to
output the result(s).
Example of Algorithm
Flowcharts
A graphical tool that diagrammatically depicts the steps and
structure of an algorithm or program.
The first design of flowchart goes back to 1945 which was
designed by John Von Neumann.
Unlike an algorithm, Flowchart uses different symbols to
design a solution to a problem. By looking at a Flowchartone
can understand the operations and sequence of operations
performed in a system. Flowchart is often considered as a
blueprint of a design used for solving a specific problem.
General rules for flowcharts

All symbols of the flowchart are connected by flow lines (note


arrows, not lines).
Flowlines enter the top of the symbol and exit out the bottom,
except for the Decision symbol, which can have flow lines exiting
from the bottom or the sides.
Flowcharts are drawn so flow generally goes from top to bottom.
The beginning and the end of the flowchart is indicated using the
Terminal symbol
Flowchart Constructs
Flowchart Constructs
Flowcharts standard symbols
Flowcharts standard symbols

You might also like