You are on page 1of 9

INTRODUCTION TO

ALGORITHMS

MO3AZ
What is an algorithm ?
A step-by-step process will be designed to solve the problem.

MO3AZ
SAIF
What is the relationship between data and algorithm ?

The algorithm processes data to make it meaningful, the algorithm provides the
logic, and the data provides the values. this relationship is expressed as:
Program = algorithm + data structures

MO3AZ
SAIF
Algorithm must be ?
Correctness : Returns a correct output for every problem input.
Efficient : The minimal cost of the computational resources used by the algorithm.

What is the characteristics of an algorithm ?


Each step must be exact : Precisely described.
Algorithm Must be :
 Terminate : Contain a finite number of steps.
 Effective : Provide the correct answer to the problem.
 General : Solve every instance of the problem.
MO3AZ
SAIF
Design and analysis of algorithms ?

Design Analysis
Calculate the cost of the
Design an algorithm at
algorithm in terms of resources
the minimize cost. and performance.

 Pseudocode  Time Complexity


 Flowchart  Big-O Notation

MO3AZ
SAIF
Algorithm Design
What is Flowchart ?
A visual way of representing by diagrams that uses shapes, lines, and arrows to sequence steps.
Start & End Process Input & Output Conditions (IF) Directions

Oval Rectangle Parallelogram Diamond Arrows

What is Pseudocode ?
A description of the algorithm steps using a mixture of programming languages and English statements.

Pseudo-code differs from real code with ?


it disregards software engineering concerns and ignore issues related to data abstraction and error handling.

MO3AZ
SAIF
Algorithm Analysis
What is algorithm efficiency ?
The amount of time and space resources required to execute it.

What is Time & Space complexity ?


Time Complexity : Relation between input size and taken time to solve the problem.
Space Complexity : Relation between input size and used space to solve the problem.

BIG-O Notation ?
- A mathematical notation that describes the complexity of your code.
Constant Logarithmic Linear Loglinear Polynomial Exponential Factorial
O( 1 ) O( log(n) ) O( n ) O( n log(n) ) O( ) O( ) O( n! )

MO3AZ
SAIF
Recursive Function
What is Recursion ?
A function that calls itself directly or indirectly to solve a problem. It contains two cases:
Base Case ( Solution statement )
General Case ( Recursive function call )

Greatest Common Divisor ( GCD )


Brute Force Euclid’s Algorithm Recursive Method
function gcd(a, b):
function gcd(a, b): function gcd(a, b):
gcd = 1
while b is not 0: if b = 0:
s = min(a, b) r=a%b return a
for i from 1 to s : a=b else:
if a % i == 0 and b % i == b=r return gcd(b, a % b)
0: return a
gcd = i
return gcd

MO3AZ
SAIF
QUESTIONS TIME !

MO3AZ

You might also like