0% found this document useful (0 votes)
3 views19 pages

Algorithm Basics and Complexity Explained

Basic Algo
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)
3 views19 pages

Algorithm Basics and Complexity Explained

Basic Algo
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

Chapter-2

66642-Data Structure & Algorithm


4th Semester Computer Technology
Dhaka Polytechnic Institute

Zahed Ahmed Chowdhury


Chief Instructor (Computer)
Chapter-2: Understand the basic
concept of algorithm

2.1 State the characteristics of algorithm


2.2 Define the pseudo code & algorithmic
notations.
2.3 Describe the structured programming
and flowcharts.
2.4 Describe the Complexity of algorithm
2.1 State the characteristics of algorithm
The characteristics of a good algorithm are:
- Precision (¯úóZv)
- Uniqueness (Abb¨Zv)
- Finiteness (mmxgZv)
- Input (BbcyU)
- Output (AvDUcyU)
- Generality (me©RbxbZv)
2.1 State the characteristics of algorithm
The characteristics of a good algorithm are:
* Precision - the steps are precisely stated.
* 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.
2.2 Define the pseudo code &
algorithmic notations:
Pseudo code is an informal high level
description of the operating principle of a
computer program or other algorithm.
It uses the structural conventions of a normal
programming language, but is intended for
human reading rather than machine reading.
Pseudo code typically omits details that are
essential for machine understanding of the
algorithm, such as variable declarations, system-
specific code and some subroutines.
Example of Pseudo code
Algorithm:
Step-1: Set a variable as GRADE.
Step-2: If student's GRADE is greater than or equal to 60 then
Print "pass"
otherwise
Print "fail“
Step-3: End Processing.

Pseudo code:
If student_GRADE> or = 60
Print "pass"
else
Print "fail“

Python Code:
GRADE=Input (GRADE)
If GRADE > = 60:
print (“Pass”)
else:
print (“Fail”)
Differences between Algorithm & Pseudo code:

An algorithm is a while Pseudo code is the


systematic logical statement in plain
approach used to solve English. Pseudo-code
problems in a computer. does not use the syntax
An algorithm presents of a specific
the solution to a programming language.
problem as a well
defined set of steps or
instructions.
Algorithm Notation
There are some common notation used in
algorithm:
- Identification number of Algorithm
- Name of Algorithm
- Introductory Comment
- Steps of algorithm
- Comments
- Format of Assignment, Branch & Loop
statement/Structure.
2.3 Describe the structured programming
and flowcharts.

Structured programming: It is a programming style,


aimed at improving the clarity, quality, and
development time of a computer by making
extensive use of Subroutine, block structure, for
and while loops—in contrast to using simple tests
and jumps such as the goto statement etc.
Control Structures:
• Basically 3 types of control structure in
Programming style:
1. Sequential structure
2. Selective / Branch structure
3. Repetitive / Loop structure
Subroutine:
a subroutine is a sequence of program
instructions that perform a specific task,
packaged as a unit. This unit can then be used in
programs wherever that particular task should
be performed.
Subprograms may be defined within programs,
or separately in libraries that can be used by
multiple programs. In different programming
languages, a subroutine may be called
a procedure, a function, a routine, a method or
a subprogram.
Block of a Program:
• In computer programming, a block or
code block is a structure of source code which
is grouped together. Blocks consist of one or
more declarations and statements.
• A programming language that permits the
creation of blocks, including blocks nested
within other blocks, is called a block-
structured programming
Flowchart & Symbols:
• A flowchart is a type of diagram that
represents an algorithm, workflow or process,
showing the steps as boxes of various kinds,
and their order by connecting them with
arrows.
Basic symbols of Flowchart:
Flowchart (Sequential Structure)
Flowchart (Selective Structure)
Flowchart (Loop Structure)
2.4 Describe the Complexity of algorithm
Complexity of an algorithm is a measure of the
amount of running time and/or space required by
an algorithm for an input of a given size.
• the running time of an algorithm for a specific input
depends on the number of operations executed. The
greater the number of operations, the longer the
running time of an algorithm.
• the space required of an algorithm is the amount of
memory space required to solve an instance as a
function of the size of the input. It is the
memory required by an algorithm to execute a
program and produce output.
1| A¨vjMwi`‡gi Kx? GKwU fvj A¨vjMwi`‡gi •ewkó¸‡jv eY©bv Ki|
2| Pseudo code ej‡Z Kx †evSvq? D`vniY `vI|
3| Pseudo code Gi mv‡_ Algorithm Gi cv_©K¨ D`vniYmn †`LvI|
4| Algorithm Notation Kx? wewfbœ ai‡Yi Algorithm Notation Gi
eY©bv `vI|
5| †d¬vPv‡U© e¨eüZ wewfbœ ai‡Yi symbol/cÖwZK ¸‡jvi eY©bv `vI|
6| Structured programming ej‡Z Kx †evSvq? †cÖvMÖvwgs Gi †ÿ‡Î
wewfbœ ai‡Yi Control structure Gi bvgmn †d¬vPvU© ‡`LvI|
7| Subroutine ej‡Z Kx ‡evSvq?
8| Complexity of Algorithm ev A¨vjMw`‡gi Kg‡cø·wmwU ej‡Z Kx
†evSvq? eY©bv Ki|

You might also like