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

ALGO MS Week 1

Here are the key points about Turing machines: - A Turing machine is an abstract computing device that manipulates symbols on a strip of tape according to a table of rules. It was designed by Alan Turing in 1936 to formalize the concept of algorithm and computation. - Turing machines can be used to simulate any computer algorithm, and are used to prove results about computability and complexity theory. They are a model of computation equivalent to other models like lambda calculus or recursive functions. - Turing machines can solve problems that are algorithmically solvable in principle, like deciding whether a string is in a formal language or calculating the value of a function. However, they cannot solve problems that require unbounded resources

Uploaded by

Hassan Raza
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)
24 views

ALGO MS Week 1

Here are the key points about Turing machines: - A Turing machine is an abstract computing device that manipulates symbols on a strip of tape according to a table of rules. It was designed by Alan Turing in 1936 to formalize the concept of algorithm and computation. - Turing machines can be used to simulate any computer algorithm, and are used to prove results about computability and complexity theory. They are a model of computation equivalent to other models like lambda calculus or recursive functions. - Turing machines can solve problems that are algorithmically solvable in principle, like deciding whether a string is in a formal language or calculating the value of a function. However, they cannot solve problems that require unbounded resources

Uploaded by

Hassan Raza
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/ 40

Advanced Analysis of Algorithms

(AAA)
Dr. Shahzad Sarwar Bhatti

Assistant Professor,
Department of Information Sciences

University of Education, Lahore, Multan Campus (Week#1)


Recommended Text
1. Introduction to Algorithm (2nd or 3rd Edition)
by : Thomas H. Cormen, et al.
2. Algorithm Design (1st Edition)
by : Jon Kleinberg and Eva Tardos
3. Computer Networks (5th Edition)
by : Tanenbaum, D.J. Wetherall
Contents
1. Course Outline
2. Origin of Word: Algorithm
3. Why Study Algorithm?
4. Definition of Algorithm
5. Characteristics of Algorithm
6. What is Pseudo code?
7. Difference between Algorithm and Pseudo code
8. Algorithm vs Program
Course Outline
The course consists of four major sections:
1. Mathematical tools necessary for the
design and analysis of algorithms. This will
focus on asymptotic, summation, and
recurrence etc.
2. Sorting: Different strategies for sorting and
use this problem as a case-study in
different techniques for designing and
analyzing algorithms.
Course Outline (continued)
3. Collection of various algorithmic problems and
solution techniques: Dynamic programming,
greedy strategy, graphs etc
4. Introduction to the theory of NP-completeness.
NP-complete problems are those for which no
efficient algorithms are known, but no one knows
for sure whether efficient solutions might exist.
Origin of Word: Algorithm

• The word Algorithm comes from the name of the muslim


author Abu Ja’far Mohammad ibn Musa al-Khowarizmi.
Origin of Word: Algorithm (continued)
Remark on Algorithm
Origin of Word: Algorithm (continued)
Why Study Algorithm?

• This course is all about how to design good algorithms.


• The fact is that many of the courses in computer science
deal with efficient algorithms and data structures.
• They apply to various applications.
• Compilers
• Operating Systems
• Databases
• Artificial Intelligence
• Computer graphics and vision
• Networks and others
Why Study Algorithm? (continued)

A good understanding of algorithm design is a central


element to a good understanding of computer science and
computer programming.
• Improves the Efficiency of a Program
• Proper Utilization of Resources
• Better Problem Solving
• Provides Clarity
Why Study Algorithm? (continued)
Quotation from Donald E. Knuth

* American computer scientist, mathematician, and professor at Stanford University


Knuth has been called the "father of the analysis of algorithms"
Definition of Algorithm
• An algorithm is a procedure that consists of a finite set of
instructions which, given an input from some set of possible
inputs, enables us to obtain an output through a systematic
execution of the instructions that terminates in a finite number of
steps.

• An algorithm is any well-defined computational procedure that


takes some values, or set of values, as input and produces some
value, or set of values, as output.

• An algorithm is thus a sequence of computational steps that


transform the input into output.
Definition of Algorithm (cont’d)
What is an Algorithm

 An algorithm is a step by step procedure to solve a problem


– Plate form independent
– Can be implement in any procedural language
 Simplest form (for experts) is Pseudo code
 Pseudo code can be written in any language syntax
 Two important factors
– Space Tradeoff (Refer to less use of memory i.e. RAM)
– Time Tradeoff (Refer to less time of Micro processor for
execution)
Features Algorithm

 Complete
 Finite
 At least one Output
 0,1 or more inputs
 Correct
 Clarity
Characteristics of Algorithm
The main x-tics of algorithms are as follows:
• Algorithms must have a unique name.
• Algorithms should have explicitly defined set of inputs and
outputs.
• Algorithms are well-ordered with unambiguous operations.
• Algorithms halt in a finite amount of time. Algorithms should not
run for infinity, i.e., an algorithm must end at some point.
Characteristics of Algorithm (cont’d)
What is Pseudo code?

• Pseudo code gives a high-level description of an algorithm


without the ambiguity associated with plain text but also without
the need to know the syntax of a particular programming
language.

• The running time can be estimated in a more general manner


by using Pseudo code to represent the algorithm as a set of
fundamental operations which can then be counted.
Algorithm vs Program
• A good understanding of algorithms is essential for programming.
• Unlike a program, an algorithm is a mathematical entity.
• Algorithm is independent of a specific programming language,
machine, or compiler.
• Algorithm design is about mathematical theory behind the design
of good programs.
• A program is an implementation of an algorithm, or algorithms.
Pseudocode and Program
An Algorithm (Example)

Algorithm SUM (No1, No2, Res)


{ This algorithm is used to read two numbers and print its sum }
Step-1 [ Read numbers No1 and No2]
Read(No1,No2)
Step-2 [Calculate the sum]
Res=No1+No2
Step-3 [Display the Result ]
Write(Res)
Step-4 {Finish]
Exit
Algorithms Notations
 Algorithm Name
– Should be in capital form
– Meaningful
 Parameters
– Should be enclosed in parenthesis ( )
– Variable name comprises on more than one characters
– Scripting or looping variable are of single character
 Introductory Comment
– Description and purpose of an algorithm
 Steps
– Finite steps
Algorithms Notations (cont’d)

 Comments
– Each step start with a comment
– Enclose in [ ]
– Define the purpose of step
 Input Statements
– Read
– Scanf (if using C/C++)
 Output statement
– Write
– Printf (if using C/C++)
Algorithms Notations (cont’d)

 Selection statement
– If –Then –End If
– If – then ---Else --- End If
– Nested If
– Example
If ( a>b ) then
write ( a+”Is Large”)
Else
write ( b+”Is Large”)
End if
Algorithms Notations (cont’d)
 Loops ( For, While, Until )
– Example-1
Repeat Step 2 For i=1, N=10
– Example-2
Repeat Step 2 to Step 4 For i=1, N, 10
– Example-3
Repeat Step 2 while i<=10
– Example-4
Repeat Step 2 Until i>10
Algorithms Notations (cont’d)

 Finish
– Exit (Used in main algorithm)
– Return (Used in sub algorithm)
Example - 1
 Write an algorithms or Pseudo code to read two number
and display the largest number.
Algorithm Example - 1
Algorithm LARGE(No1, No2, lar)
{ This algorithm is used to read two numbers and print the largest}
Step-1 [ Read numbers No1 and No2]
Read(No1,No2)
Step-2 [Find the largest]
if (No1 > No2) then
lar = No1
else
lar = No2
end if
Algorithm Example – 1 (cont’d)
Step-3 [Display the Result ]
Write(lar)
Step-4 {Finish]
Exit
Algorithm Example – 1 (cont’d)
Pseudo Code Example – 1 (cont’d)

Large (a,b, lar)


{
// Find the largest number
if (a>b)
lar=a;
else
lar=b;
}
Example – 2

 Write an algorithms or Pseudo code to read an array of


N integer values, calculate its sum and then print the sum
Algorithm Example – 2
Algorithm SUM(Ary[ ], I, total, N)
{ This algorithm is used to read an array Ary of size N and display its sum }
Step-1 [ Perform a loop to read the values of array]
Repeat step 2 for i=1,N,1
Step-2 [Read value ]
Read(Ary[i])
Step-3 [Initialize variable I and total]
a. I =1
b. total = 0
Step-4 [ Perform a loop to traverse the all elements of array ary and add]
Repeat step 5 while i<=10
Algorithm Example – 2 (Cont’d)

Step-5 [Add the values]


total = total + ary [ I ]
Step-6 {Display the sum of values]
Write (total)
Step-7 {Finish]
Exit
Algorithm Example – 2 (Cont’d)

Write the algorithms convention which are use in Example-2.


 Algorithm Name (SUM)
 Parameters (ary[], I, N, total)
 Input and Output Statement (Read, Write)
 Loop Statement (for, while)
 Assignment
 Comments (enclosed in [ ] before start of each step)
 Introductory comments (enclosed in { } )
 Finish (exit)
Pseudo Code Example – 2

SUM (Ary, N, I, Total)


{
for(i=0;i<=N-1;i++)
scanf(“%d”, Ary[i]);
i=0; total=0;
while(i<=N-1)
total=total+ Ary[i];
printf(“%d”, total);
}
Summary
 An algorithm is a step by step process to solve a problem.
 An algorithm is platform Independent and you can make a
computer program in any language.
 No of Inputs, outputs, completeness, accuracy , correctness and
finite are the main features of algorithms
 Algorithms notation are used to design an algorithm
 Pseudo code are used by experts
Home Work
 Write an algorithm which read three numbers and
print the smallest number. Also write a C or any
language program

 Write an algorithm which read an array of 10 integers


and count the even numbers. Also write a C or any
language program
Assignment # 1
 What is a “Turing Machine”?
 What types of problems did Turing machine solve?
 What are the applications and limitations of Turing
machines?
Thanks

You might also like