Lect1
Lect1
(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:
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