Lecture 1 Introduction
Lecture 1 Introduction
What is Algorithm?
• Algorithm
– is any well-defined computational procedure that
takes some value, or set of values, as input and
produces some value, or set of values, as output.
– is thus a sequence of computational steps that
transform the input into the output.
– is a tool for solving a well - specified
computational problem.
– Any special method of solving a certain kind of pro
blem (Webster Dictionary)
• Correctness
– Does the input/output relation match algorithm re
quirement?
• Amount of work done (aka complexity)
– Basic operations to do task
• Amount of space used
– Memory used
PUZZLE(x)
while x != 1
if x is even
then x = x / 2
else x = 3x + 1
Sample run: 7, 22, 11, 34, 17, 52, 26, 13, 40, 20,
10, 5, 16, 8, 4, 2, 1
OUTPUT
instance
m:= a[1];
25, 90, 53, 23, 11, 34 for I:=2 to size of input 11
if m > a[I] then
m:=a[I];
return s
m
Data-Structure
Algorithm A
2. While n > 1
For i 1 to n /2
t2[ i ] min (t1 [ 2*i ], t1[ 2*i + 1] );
copy array t2 to t1;
n n/2;
3. Output t2[1];
Loop 1
6 5 8 7
Loop 2
5 7
Loop 3
5
Tuesday, January 10, 2023 Lecture 1 Introduction 22
Example Algorithm C
Sort the input in increasing order. Return the
first element of the sorted data.
34 6 5 9 20 8 11 7
black
Sorting box
5 6 7 8 9 11 20 34
Algorithms D is
Ta (n)
implemented and run in
a supercomputer.
0
Let Tk( n ) be the 500 1000
amount of time taken by Input Size
the Algorithm
Tuesday, January 10, 2023 Lecture 1 Introduction 26
What is Algorithm Analysis?
• How to estimate the time required for an algo
rithm
• Techniques that drastically reduce the running
time of an algorithm
• A mathemactical framwork that more rigorous
ly describes the running time of an algorithm