SlideShare a Scribd company logo
Algorithms
1. Notion of an algorithm
2. Properties of an algorithm
3. The GCD algorithm
4. Correctness of the GCD algorithm
5. Termination of the GCD algorithm
6. Performance
7. Data structures
Need for studying algorithms:
• The study of algorithms is the cornerstone of computer
science. It can be recognized as the core of computer
science.
• Computer programs would not exist without algorithms.
With computers becoming an essential part of our
professional & personal life‘s, studying algorithms
becomes a necessity, more so for computer science
engineers.
• Another reason for studying algorithms is that if we know a
standard set of important algorithms, They enhance our
analytical skills & help us in developing new algorithms for
required applications
Problem
Datastructure
Algorithm
Program
Computer
+
Input Output
1-Notion of an algorithm
Definition
An algorithm is a clearly specified set of instructions
describing the solution to a specific problem.
• An algorithm is finite set of instructions that is followed,
accomplishes a particular task. (Sahani)
An algorithm
• takes the input and transforms it into an adequate output,
• must be independent from any programming language,
• is written in a level of detail that allows to reproduce it in
any programming language,
• has to be designed so it can be reused and understood by
others.
Algorithms must satisfy the following
criteria
1.Input: Zero or more quantities are externally supplied.
2.Output : At least one quantity is produced.
3.Definiteness:Each instruction is clear and unambiguous.
4.Finiteness: If we trace out the instructions of an
algorithm, then for all cases, the algorithm terminates after
a finite number of steps.
5.Effectiveness: Every instruction must be very basic so
that it can be carried out, in principle,by a person using only
pencil and paper. It is not enough that each operation be
definite as in criterion3; it also must be feasible.
2-Properties of an algorithm
Some properties must be satisfied by an algorithm in
order to allow a successful execution of the
corresponding program:
1. Correctness: if the input conditions are satisfied and the
algorithm instructions executed, then the correct output is
produced.
2. Termination: the algorithm must terminate after a finite number
of steps. Thus, it has to be composed by a finite number of steps.
This can be ensured if the algorithm avoids an infinite loop.
3. Performance: Quantification of the space and time complexities.
• Algorithms that are definite and effective
are also called computational procedures.
• The same algorithm can be represented in
several ways
• Several algorithms to solve the same
problem
• Different ideas different speed
The four distinct areas of
studying algorithms
1. How to devise algorithms
2. How to validate algorithms
3. How to analyze algorithms
4. How to test a program
The GCD algorithm:
Given two positive integers m and n, find the greatest common divisor,
gcd(m,n).
A view of the problem:
All numbers from 1 up to the smallest of m and n, say n.
Naive algorithm:
Go through search space (from 1 to n)
Keep track of largest number that divides both m and n.
Is there a more efficient way of doing this?
Yes, the Euclidean Algorithm (Euclid – c.350 B.C.E.)
Pseudocode of the GCD algorithm :
Algorithm GreatestCommonDivisor
Input: Two positive integers, m and n
Ouptut: The gcd of m and n
repeat
r  m mod n
m  n
n  r
until (r == 0)
Output m and STOP.
Example:
m = 24, n = 9
r  24 mod 9 = 6
m  9
n  6
r  9 mod 6 = 3
m  6
n  3
r  6 mod 3 = 0
m  3
n  0
Output 3
STOP
Euclids algorithm
Step1:if n=0 return val of m & stop else proceed step 2
Step 2:Divide m by n & assign the value of remainder to r
Step 3:Assign the value of n to m,r to n,Go to step1.
Another algorithm to solve the same problem
Euclids algorithm
Step1:Assign the value of min(m,n) to t
Step 2:Divide m by t.if remainder is 0,go to step3 else goto step4
Step 3: Divide n by t.if the remainder is 0,return the value of t as the
answer and stop,otherwise proceed to step4
Step4 :Decrease the value of t by 1. go to step 2
Thus, ri will become 0 in at most 2 log n iterations
Example: m = 1989 and n = 1590
Remainder sequence:
399 = 1989 mod 1590  399 < 1989/2
393 = 1590 mod 399  393 < 1590/2
6 = 399 mod 393  6 < 399/2 < 1989/4
3 = 393 mod 6  3 < 393/2 < 1590/4
0 = 6 mod 3  0 < 6/2 < 399/4 < 1989/8
We stop here, but if we continue: < 1590/8
< 1989/16
< 1590/16
Number of Steps:
In 2 * 3 steps, ri reduced by factor of 8
2 * 4 ri 16
2 * 5 ri 32
2 * 6 ri 64
……
2 * log n ri n
Thus, ri becomes 0 in at most 2 log n iterations.
4-Correctness of the GCD algorithm.
4-Correctness of the GCD algorithm.
• Correctness is an important issue in algorithm design. This means
Correctness is an important issue in algorithm design. This means
proving that the algorithm works for all legal inputs.
proving that the algorithm works for all legal inputs.
It is analogous to proving the correctness of a theorem in
It is analogous to proving the correctness of a theorem in
mathematics!
mathematics!
• The correctness of the GCD algorithm depends on the following loop
The correctness of the GCD algorithm depends on the following loop
invariant:
invariant:
gcd(m,n)=gcd(n,r) where r=m%n
gcd(m,n)=gcd(n,r) where r=m%n
Claim 1:
gcd(m,n) = gcd(n,r)
Proof:
The gcd of the new pair is equal to the gcd of the previous pair.
How is this correct?
Let us write:
m = q * n + r
where 0  r  n.
This implies that:
a common divisor of m and n is also
a common divisor of n and r,
and vice versa. q.e.d.
5-Termination of the GCD algorithm.
5-Termination of the GCD algorithm.
• Show that algorithm terminates in a finite number of steps.
Show that algorithm terminates in a finite number of steps.
• This must be true for every valid input.
This must be true for every valid input.
• Can we show this for Algorithm GCD?
Can we show this for Algorithm GCD?
• We must show that
We must show that ri
ri goes to 0 in a finite number of steps.
goes to 0 in a finite number of steps.
Observe:
Observe:
• The sequence of remainders strictly decreases.
The sequence of remainders strictly decreases.
• They are all non-negative.
They are all non-negative.
• Thus
Thus ri
ri will become 0 in at most 2 log
will become 0 in at most 2 log n
n steps.
steps.
6-Performance of the GCD algorithm.
6-Performance of the GCD algorithm.
• Quantification of performance of the algorithm.
Quantification of performance of the algorithm.
• Crucial parameters: time and space.
Crucial parameters: time and space.
• Called time and space complexity of the algorithm.
Called time and space complexity of the algorithm.
• Will be discussed latter in the course.
Will be discussed latter in the course.
For example:
For example:
Time complexity of GCD:
Time complexity of GCD:
Takes at most 2 log
Takes at most 2 log n
n steps, where
steps, where n
n <
< m
m
Thus, worst-case time complexity:
Thus, worst-case time complexity: O
O(log
(log n
n)
)
7-Data structures
7-Data structures
• The study of different ways of organizing data.
The study of different ways of organizing data.
• Why?
Why?
• Efficiency of algorithm depends on how data is organized.
Efficiency of algorithm depends on how data is organized.
• Reason for studying data structures and algorithms together.
Reason for studying data structures and algorithms together.
• Organic connection between the two areas.
Organic connection between the two areas.
• In 60-212 the programming language JAVA is studied.
In 60-212 the programming language JAVA is studied.
• Here: An algorithmic perspective.
Here: An algorithmic perspective.
• Independent of programming language (eg. C, C++, JAVA).
Independent of programming language (eg. C, C++, JAVA).
For example:
• The median of a list of n numbers is a number m such that:
n/2 numbers in the list are  m, and
n/2 … are  m.
• Many definitions of median, we take:
If n is even:
Two medians:
lower median and upper median,
Then, median is average of lower and upper medians.
If n is odd:
Both medians (lower and upper) are the same.
• Consider this problem:
Given a sorted list of n numbers, find the median.
• A crucial question:
How should we store the list?
• We store it in an array, A, then
The median is found in constant time, O(1) !!
• Median = (A[5]+A[6])/2 = (19+22)/2 = 20.5
2 5 9 16 19 22 26 27 30 31
1 2 3 4 5 6 7 8 9 10
• Whereas in a linked list:
Traverse half of the list in n/2 steps, which is O(n) !
• Quite simple stated:
The way in which data is organized is crucial in complexity.
More examples like this will be seen later.
2 5 9 16 19 22 ….
first
Example of problems:
• Design an efficient algorithm to determine if a list has repeated
elements.
• Given a list of n elements find their minimum (or maximum).
• Given n points in the plane, find the pair(s) of points which are closest
to each other.
• Given n points in the plane determine if any three are contained in a
straight line.
Notion of Algorithms.pdf

More Related Content

What's hot

Hashing
HashingHashing
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
Damian T. Gordon
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
Jd Mercado
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
Sajid Marwat
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
Mohamed Loey
 
Hashing
HashingHashing
Hashing
Ghaffar Khan
 
Computer architecture and organization
Computer architecture and organizationComputer architecture and organization
Computer architecture and organization
Tushar B Kute
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
Janki Shah
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
Syed Hassan Ali
 
Process & Thread Management
Process & Thread  ManagementProcess & Thread  Management
Process & Thread Management
Vpmv
 
Heaps
HeapsHeaps
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Operating system 31 multiple processor scheduling
Operating system 31 multiple processor schedulingOperating system 31 multiple processor scheduling
Operating system 31 multiple processor scheduling
Vaibhav Khanna
 
Computer Organization and Architecture 10th Edition by Stallings Test Bank
Computer Organization and Architecture 10th Edition by Stallings Test BankComputer Organization and Architecture 10th Edition by Stallings Test Bank
Computer Organization and Architecture 10th Edition by Stallings Test Bank
rohalcabaye
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
Mazin Alwaaly
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
Dhananjaysinh Jhala
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
A B Shinde
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
Muhammad Hammad Waseem
 
Cache memory
Cache memoryCache memory
Cache memory
Ansari Maviya
 

What's hot (20)

Hashing
HashingHashing
Hashing
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
 
Do...while loop structure
Do...while loop structureDo...while loop structure
Do...while loop structure
 
Lec 17 heap data structure
Lec 17 heap data structureLec 17 heap data structure
Lec 17 heap data structure
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Algorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms IAlgorithms Lecture 2: Analysis of Algorithms I
Algorithms Lecture 2: Analysis of Algorithms I
 
Hashing
HashingHashing
Hashing
 
Computer architecture and organization
Computer architecture and organizationComputer architecture and organization
Computer architecture and organization
 
File Management in Operating System
File Management in Operating SystemFile Management in Operating System
File Management in Operating System
 
Process synchronization
Process synchronizationProcess synchronization
Process synchronization
 
Process & Thread Management
Process & Thread  ManagementProcess & Thread  Management
Process & Thread Management
 
Heaps
HeapsHeaps
Heaps
 
Unit 1 chapter 1 Design and Analysis of Algorithms
Unit 1   chapter 1 Design and Analysis of AlgorithmsUnit 1   chapter 1 Design and Analysis of Algorithms
Unit 1 chapter 1 Design and Analysis of Algorithms
 
Operating system 31 multiple processor scheduling
Operating system 31 multiple processor schedulingOperating system 31 multiple processor scheduling
Operating system 31 multiple processor scheduling
 
Computer Organization and Architecture 10th Edition by Stallings Test Bank
Computer Organization and Architecture 10th Edition by Stallings Test BankComputer Organization and Architecture 10th Edition by Stallings Test Bank
Computer Organization and Architecture 10th Edition by Stallings Test Bank
 
Computer architecture instruction formats
Computer architecture instruction formatsComputer architecture instruction formats
Computer architecture instruction formats
 
Design of a two pass assembler
Design of a two pass assemblerDesign of a two pass assembler
Design of a two pass assembler
 
Multiprocessor
MultiprocessorMultiprocessor
Multiprocessor
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
Cache memory
Cache memoryCache memory
Cache memory
 

Similar to Notion of Algorithms.pdf

Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
chidabdu
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
Low Ying Hao
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
GOWTHAMR721887
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
Krishnan MuthuManickam
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
Ankit Katiyar
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
ibrahim386946
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
RobinRohit2
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
ChSreenivasuluReddy
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
Megha V
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
JeevaMCSEKIOT
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
rajesshs31r
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
rajesshs31r
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
B.Kirron Reddi
 
Unit i
Unit iUnit i
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
KokilaK25
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
2022cspaawan12556
 
Unit i
Unit iUnit i
Unit i
guna287176
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
Tribhuvan University
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
rajatmay1992
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
babuk110
 

Similar to Notion of Algorithms.pdf (20)

Sienna 1 intro
Sienna 1 introSienna 1 intro
Sienna 1 intro
 
Kk20503 1 introduction
Kk20503 1 introductionKk20503 1 introduction
Kk20503 1 introduction
 
19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf19IS402_LP1_LM_22-23.pdf
19IS402_LP1_LM_22-23.pdf
 
CS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of AlgorithmsCS8451 - Design and Analysis of Algorithms
CS8451 - Design and Analysis of Algorithms
 
Time and space complexity
Time and space complexityTime and space complexity
Time and space complexity
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
algorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptxalgorithmanalysis and effciency.pptx
algorithmanalysis and effciency.pptx
 
Algorithm Analysis
Algorithm AnalysisAlgorithm Analysis
Algorithm Analysis
 
Design & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptxDesign & Analysis of Algorithm course .pptx
Design & Analysis of Algorithm course .pptx
 
Design Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptxDesign Analysis of Alogorithm 1 ppt 2024.pptx
Design Analysis of Alogorithm 1 ppt 2024.pptx
 
Analysis of Algorithm full version 2024.pptx
Analysis of Algorithm  full version  2024.pptxAnalysis of Algorithm  full version  2024.pptx
Analysis of Algorithm full version 2024.pptx
 
Daa chapter 1
Daa chapter 1Daa chapter 1
Daa chapter 1
 
Unit i
Unit iUnit i
Unit i
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...DSA Complexity.pptx   What is Complexity Analysis? What is the need for Compl...
DSA Complexity.pptx What is Complexity Analysis? What is the need for Compl...
 
Unit i
Unit iUnit i
Unit i
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
Ch24 efficient algorithms
Ch24 efficient algorithmsCh24 efficient algorithms
Ch24 efficient algorithms
 
Data Structure & Algorithms - Mathematical
Data Structure & Algorithms - MathematicalData Structure & Algorithms - Mathematical
Data Structure & Algorithms - Mathematical
 

More from ShivareddyGangam

Student Voting Application for Election – Using SMS (1).pptx
Student Voting Application for Election – Using SMS (1).pptxStudent Voting Application for Election – Using SMS (1).pptx
Student Voting Application for Election – Using SMS (1).pptx
ShivareddyGangam
 
Project Management (2).pdf
Project Management (2).pdfProject Management (2).pdf
Project Management (2).pdf
ShivareddyGangam
 
pca.ppt
pca.pptpca.ppt
The Product and Process(1).pdf
The Product and Process(1).pdfThe Product and Process(1).pdf
The Product and Process(1).pdf
ShivareddyGangam
 
Unit24_TopologicalSort (2).ppt
Unit24_TopologicalSort (2).pptUnit24_TopologicalSort (2).ppt
Unit24_TopologicalSort (2).ppt
ShivareddyGangam
 
Lecture1_jps (1).ppt
Lecture1_jps (1).pptLecture1_jps (1).ppt
Lecture1_jps (1).ppt
ShivareddyGangam
 
2 semai.pptx
2 semai.pptx2 semai.pptx
2 semai.pptx
ShivareddyGangam
 
artificialintelligencea-200326090832.pdf
artificialintelligencea-200326090832.pdfartificialintelligencea-200326090832.pdf
artificialintelligencea-200326090832.pdf
ShivareddyGangam
 
Software Project Risks Management (1).pdf
Software Project Risks Management (1).pdfSoftware Project Risks Management (1).pdf
Software Project Risks Management (1).pdf
ShivareddyGangam
 
Introduction (1).pdf
Introduction (1).pdfIntroduction (1).pdf
Introduction (1).pdf
ShivareddyGangam
 
Unit 3 (1) (1).pdf
Unit 3 (1) (1).pdfUnit 3 (1) (1).pdf
Unit 3 (1) (1).pdf
ShivareddyGangam
 
Unit 1 (1).pdf
Unit 1 (1).pdfUnit 1 (1).pdf
Unit 1 (1).pdf
ShivareddyGangam
 
Strassen.ppt
Strassen.pptStrassen.ppt
Strassen.ppt
ShivareddyGangam
 
11_Automated_Testing.ppt
11_Automated_Testing.ppt11_Automated_Testing.ppt
11_Automated_Testing.ppt
ShivareddyGangam
 
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptxOS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
ShivareddyGangam
 
Project Management.pdf
Project Management.pdfProject Management.pdf
Project Management.pdf
ShivareddyGangam
 
PP
PPPP
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
ShivareddyGangam
 
machinelearningengineeringslideshare-160909192132 (1).pdf
machinelearningengineeringslideshare-160909192132 (1).pdfmachinelearningengineeringslideshare-160909192132 (1).pdf
machinelearningengineeringslideshare-160909192132 (1).pdf
ShivareddyGangam
 
intelligent agent (1).pptx
intelligent agent (1).pptxintelligent agent (1).pptx
intelligent agent (1).pptx
ShivareddyGangam
 

More from ShivareddyGangam (20)

Student Voting Application for Election – Using SMS (1).pptx
Student Voting Application for Election – Using SMS (1).pptxStudent Voting Application for Election – Using SMS (1).pptx
Student Voting Application for Election – Using SMS (1).pptx
 
Project Management (2).pdf
Project Management (2).pdfProject Management (2).pdf
Project Management (2).pdf
 
pca.ppt
pca.pptpca.ppt
pca.ppt
 
The Product and Process(1).pdf
The Product and Process(1).pdfThe Product and Process(1).pdf
The Product and Process(1).pdf
 
Unit24_TopologicalSort (2).ppt
Unit24_TopologicalSort (2).pptUnit24_TopologicalSort (2).ppt
Unit24_TopologicalSort (2).ppt
 
Lecture1_jps (1).ppt
Lecture1_jps (1).pptLecture1_jps (1).ppt
Lecture1_jps (1).ppt
 
2 semai.pptx
2 semai.pptx2 semai.pptx
2 semai.pptx
 
artificialintelligencea-200326090832.pdf
artificialintelligencea-200326090832.pdfartificialintelligencea-200326090832.pdf
artificialintelligencea-200326090832.pdf
 
Software Project Risks Management (1).pdf
Software Project Risks Management (1).pdfSoftware Project Risks Management (1).pdf
Software Project Risks Management (1).pdf
 
Introduction (1).pdf
Introduction (1).pdfIntroduction (1).pdf
Introduction (1).pdf
 
Unit 3 (1) (1).pdf
Unit 3 (1) (1).pdfUnit 3 (1) (1).pdf
Unit 3 (1) (1).pdf
 
Unit 1 (1).pdf
Unit 1 (1).pdfUnit 1 (1).pdf
Unit 1 (1).pdf
 
Strassen.ppt
Strassen.pptStrassen.ppt
Strassen.ppt
 
11_Automated_Testing.ppt
11_Automated_Testing.ppt11_Automated_Testing.ppt
11_Automated_Testing.ppt
 
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptxOS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
OS-Final-Transform-Manual-Testing-Processes-to-incorporate-Automatio....pptx
 
Project Management.pdf
Project Management.pdfProject Management.pdf
Project Management.pdf
 
PP
PPPP
PP
 
chapter2.ppt
chapter2.pptchapter2.ppt
chapter2.ppt
 
machinelearningengineeringslideshare-160909192132 (1).pdf
machinelearningengineeringslideshare-160909192132 (1).pdfmachinelearningengineeringslideshare-160909192132 (1).pdf
machinelearningengineeringslideshare-160909192132 (1).pdf
 
intelligent agent (1).pptx
intelligent agent (1).pptxintelligent agent (1).pptx
intelligent agent (1).pptx
 

Recently uploaded

按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
ei8c4cba
 
Why is the AIS 140 standard Mandatory in India?
Why is the AIS 140 standard Mandatory in India?Why is the AIS 140 standard Mandatory in India?
Why is the AIS 140 standard Mandatory in India?
Watsoo Telematics
 
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
byfazef
 
Production.pptxd dddddddddddddddddddddddddddddddddd
Production.pptxd ddddddddddddddddddddddddddddddddddProduction.pptxd dddddddddddddddddddddddddddddddddd
Production.pptxd dddddddddddddddddddddddddddddddddd
DanielOliver74
 
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
yizxn4sx
 
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
2g3om49r
 
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
8db3cz8x
 
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
terpt4iu
 
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
zpc0z12
 
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
1jtj7yul
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
peuce
 
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
6oo02s6l
 
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
yizxn4sx
 
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
yizxn4sx
 
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
nudduv
 
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDARLORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
lorraineandreiamcidl
 
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
uyesp1a
 
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
eydeofo
 
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
kuehcub
 
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
xuqdabu
 

Recently uploaded (20)

按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
按照学校原版(AU文凭证书)英国阿伯丁大学毕业证快速办理
 
Why is the AIS 140 standard Mandatory in India?
Why is the AIS 140 standard Mandatory in India?Why is the AIS 140 standard Mandatory in India?
Why is the AIS 140 standard Mandatory in India?
 
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
一比一原版(Greenwich文凭证书)格林威治大学毕业证如何办理
 
Production.pptxd dddddddddddddddddddddddddddddddddd
Production.pptxd ddddddddddddddddddddddddddddddddddProduction.pptxd dddddddddddddddddddddddddddddddddd
Production.pptxd dddddddddddddddddddddddddddddddddd
 
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
按照学校原版(Greenwich文凭证书)格林威治大学毕业证快速办理
 
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
1比1复刻澳洲皇家墨尔本理工大学毕业证本科学位原版一模一样
 
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理按照学校原版(QU文凭证书)皇后大学毕业证快速办理
按照学校原版(QU文凭证书)皇后大学毕业证快速办理
 
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
按照学校原版(UOL文凭证书)利物浦大学毕业证快速办理
 
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
按照学校原版(UST文凭证书)圣托马斯大学毕业证快速办理
 
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
按照学校原版(UVic文凭证书)维多利亚大学毕业证快速办理
 
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
一比一原版(UMich毕业证)密歇根大学|安娜堡分校毕业证如何办理
 
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
按照学校原版(Birmingham文凭证书)伯明翰大学|学院毕业证快速办理
 
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
按照学校原版(Westminster文凭证书)威斯敏斯特大学毕业证快速办理
 
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
按照学校原版(UAL文凭证书)伦敦艺术大学毕业证快速办理
 
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
一比一原版(ANU文凭证书)澳大利亚国立大学毕业证如何办理
 
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDARLORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
LORRAINE ANDREI_LEQUIGAN_GOOGLE CALENDAR
 
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
按照学校原版(Columbia文凭证书)哥伦比亚大学毕业证快速办理
 
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
一比一原版(UOL文凭证书)利物浦大学毕业证如何办理
 
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
一比一原版(KCL文凭证书)伦敦国王学院毕业证如何办理
 
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
一比一原版(Monash文凭证书)莫纳什大学毕业证如何办理
 

Notion of Algorithms.pdf

  • 1. Algorithms 1. Notion of an algorithm 2. Properties of an algorithm 3. The GCD algorithm 4. Correctness of the GCD algorithm 5. Termination of the GCD algorithm 6. Performance 7. Data structures
  • 2. Need for studying algorithms: • The study of algorithms is the cornerstone of computer science. It can be recognized as the core of computer science. • Computer programs would not exist without algorithms. With computers becoming an essential part of our professional & personal life‘s, studying algorithms becomes a necessity, more so for computer science engineers. • Another reason for studying algorithms is that if we know a standard set of important algorithms, They enhance our analytical skills & help us in developing new algorithms for required applications
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 9. 1-Notion of an algorithm Definition An algorithm is a clearly specified set of instructions describing the solution to a specific problem. • An algorithm is finite set of instructions that is followed, accomplishes a particular task. (Sahani) An algorithm • takes the input and transforms it into an adequate output, • must be independent from any programming language, • is written in a level of detail that allows to reproduce it in any programming language, • has to be designed so it can be reused and understood by others.
  • 10. Algorithms must satisfy the following criteria 1.Input: Zero or more quantities are externally supplied. 2.Output : At least one quantity is produced. 3.Definiteness:Each instruction is clear and unambiguous. 4.Finiteness: If we trace out the instructions of an algorithm, then for all cases, the algorithm terminates after a finite number of steps. 5.Effectiveness: Every instruction must be very basic so that it can be carried out, in principle,by a person using only pencil and paper. It is not enough that each operation be definite as in criterion3; it also must be feasible.
  • 11. 2-Properties of an algorithm Some properties must be satisfied by an algorithm in order to allow a successful execution of the corresponding program: 1. Correctness: if the input conditions are satisfied and the algorithm instructions executed, then the correct output is produced. 2. Termination: the algorithm must terminate after a finite number of steps. Thus, it has to be composed by a finite number of steps. This can be ensured if the algorithm avoids an infinite loop. 3. Performance: Quantification of the space and time complexities.
  • 12. • Algorithms that are definite and effective are also called computational procedures. • The same algorithm can be represented in several ways • Several algorithms to solve the same problem • Different ideas different speed
  • 13. The four distinct areas of studying algorithms 1. How to devise algorithms 2. How to validate algorithms 3. How to analyze algorithms 4. How to test a program
  • 14. The GCD algorithm: Given two positive integers m and n, find the greatest common divisor, gcd(m,n). A view of the problem: All numbers from 1 up to the smallest of m and n, say n. Naive algorithm: Go through search space (from 1 to n) Keep track of largest number that divides both m and n. Is there a more efficient way of doing this? Yes, the Euclidean Algorithm (Euclid – c.350 B.C.E.)
  • 15. Pseudocode of the GCD algorithm : Algorithm GreatestCommonDivisor Input: Two positive integers, m and n Ouptut: The gcd of m and n repeat r  m mod n m  n n  r until (r == 0) Output m and STOP.
  • 16. Example: m = 24, n = 9 r  24 mod 9 = 6 m  9 n  6 r  9 mod 6 = 3 m  6 n  3 r  6 mod 3 = 0 m  3 n  0 Output 3 STOP
  • 17. Euclids algorithm Step1:if n=0 return val of m & stop else proceed step 2 Step 2:Divide m by n & assign the value of remainder to r Step 3:Assign the value of n to m,r to n,Go to step1.
  • 18. Another algorithm to solve the same problem Euclids algorithm Step1:Assign the value of min(m,n) to t Step 2:Divide m by t.if remainder is 0,go to step3 else goto step4 Step 3: Divide n by t.if the remainder is 0,return the value of t as the answer and stop,otherwise proceed to step4 Step4 :Decrease the value of t by 1. go to step 2
  • 19. Thus, ri will become 0 in at most 2 log n iterations Example: m = 1989 and n = 1590 Remainder sequence: 399 = 1989 mod 1590  399 < 1989/2 393 = 1590 mod 399  393 < 1590/2 6 = 399 mod 393  6 < 399/2 < 1989/4 3 = 393 mod 6  3 < 393/2 < 1590/4 0 = 6 mod 3  0 < 6/2 < 399/4 < 1989/8 We stop here, but if we continue: < 1590/8 < 1989/16 < 1590/16
  • 20. Number of Steps: In 2 * 3 steps, ri reduced by factor of 8 2 * 4 ri 16 2 * 5 ri 32 2 * 6 ri 64 …… 2 * log n ri n Thus, ri becomes 0 in at most 2 log n iterations.
  • 21. 4-Correctness of the GCD algorithm. 4-Correctness of the GCD algorithm. • Correctness is an important issue in algorithm design. This means Correctness is an important issue in algorithm design. This means proving that the algorithm works for all legal inputs. proving that the algorithm works for all legal inputs. It is analogous to proving the correctness of a theorem in It is analogous to proving the correctness of a theorem in mathematics! mathematics! • The correctness of the GCD algorithm depends on the following loop The correctness of the GCD algorithm depends on the following loop invariant: invariant: gcd(m,n)=gcd(n,r) where r=m%n gcd(m,n)=gcd(n,r) where r=m%n
  • 22. Claim 1: gcd(m,n) = gcd(n,r) Proof: The gcd of the new pair is equal to the gcd of the previous pair. How is this correct? Let us write: m = q * n + r where 0  r  n. This implies that: a common divisor of m and n is also a common divisor of n and r, and vice versa. q.e.d.
  • 23. 5-Termination of the GCD algorithm. 5-Termination of the GCD algorithm. • Show that algorithm terminates in a finite number of steps. Show that algorithm terminates in a finite number of steps. • This must be true for every valid input. This must be true for every valid input. • Can we show this for Algorithm GCD? Can we show this for Algorithm GCD? • We must show that We must show that ri ri goes to 0 in a finite number of steps. goes to 0 in a finite number of steps. Observe: Observe: • The sequence of remainders strictly decreases. The sequence of remainders strictly decreases. • They are all non-negative. They are all non-negative. • Thus Thus ri ri will become 0 in at most 2 log will become 0 in at most 2 log n n steps. steps.
  • 24. 6-Performance of the GCD algorithm. 6-Performance of the GCD algorithm. • Quantification of performance of the algorithm. Quantification of performance of the algorithm. • Crucial parameters: time and space. Crucial parameters: time and space. • Called time and space complexity of the algorithm. Called time and space complexity of the algorithm. • Will be discussed latter in the course. Will be discussed latter in the course. For example: For example: Time complexity of GCD: Time complexity of GCD: Takes at most 2 log Takes at most 2 log n n steps, where steps, where n n < < m m Thus, worst-case time complexity: Thus, worst-case time complexity: O O(log (log n n) )
  • 25. 7-Data structures 7-Data structures • The study of different ways of organizing data. The study of different ways of organizing data. • Why? Why? • Efficiency of algorithm depends on how data is organized. Efficiency of algorithm depends on how data is organized. • Reason for studying data structures and algorithms together. Reason for studying data structures and algorithms together. • Organic connection between the two areas. Organic connection between the two areas. • In 60-212 the programming language JAVA is studied. In 60-212 the programming language JAVA is studied. • Here: An algorithmic perspective. Here: An algorithmic perspective. • Independent of programming language (eg. C, C++, JAVA). Independent of programming language (eg. C, C++, JAVA).
  • 26. For example: • The median of a list of n numbers is a number m such that: n/2 numbers in the list are  m, and n/2 … are  m. • Many definitions of median, we take: If n is even: Two medians: lower median and upper median, Then, median is average of lower and upper medians. If n is odd: Both medians (lower and upper) are the same.
  • 27. • Consider this problem: Given a sorted list of n numbers, find the median. • A crucial question: How should we store the list? • We store it in an array, A, then The median is found in constant time, O(1) !! • Median = (A[5]+A[6])/2 = (19+22)/2 = 20.5 2 5 9 16 19 22 26 27 30 31 1 2 3 4 5 6 7 8 9 10
  • 28. • Whereas in a linked list: Traverse half of the list in n/2 steps, which is O(n) ! • Quite simple stated: The way in which data is organized is crucial in complexity. More examples like this will be seen later. 2 5 9 16 19 22 …. first
  • 29. Example of problems: • Design an efficient algorithm to determine if a list has repeated elements. • Given a list of n elements find their minimum (or maximum). • Given n points in the plane, find the pair(s) of points which are closest to each other. • Given n points in the plane determine if any three are contained in a straight line.