SlideShare a Scribd company logo
01
Introduction to
Algorithms
CS 221 – ALGORITHMS AND COMPLEXITY
Introduction
The study of algorithms, sometimes called algorithmics, has
come to be recognized as the cornerstone of computer
science.
Algorithmics is more than a branch of computer science. It is
the core of computer science, and, in all fairness, can be said
to be relevant to most of science, business, and technology.
- David Harel, Algorithmics: the Spirit of Computing
Why study Algorithms?
Computer programs would not exist without algorithms.
With computer applications becoming indispensable in almost all
aspects of our professional and personal lives, studying algorithms
becomes a necessity for more and more people.
Usefulness in developing analytical skills.
The precision inherently imposed by algorithmic thinking limits the
kinds of problems that can be solved with an algorithm.
What is an Algorithm?
An algorithm is a sequence of unambiguous instructions for
solving a problem, i.e., for obtaining a required output for
any legitimate input in a finite amount of time.
Methods of solving the same problem
illustrates several important points:
The nonambiguity requirement for each step of an algorithm
cannot be compromised.
The range of inputs for which an algorithm works has to be
specified carefully.
The same algorithm can be represented in several different ways.
There may exist several algorithms for solving the same problem.
Algorithms for the same problem can be based on very different
ideas and can solve the problem with dramatically different speeds.
Euclid’s Algorithm
Recall that the greatest common divisor of two
nonnegative, not-both-zero integers m and n, denoted
gcd(m, n), is defined as the largest integer that divides both
m and n evenly, i.e., with a remainder of zero.
Euclid of Alexandria (third century b.c.) outlined an
algorithm for solving this problem in one of the volumes of
his Elements most famous for its systematic exposition of
geometry.
Euclid’s Algorithm (cont.)
gcd(m, n) = gcd(n, m mod n)
where m mod n is the remainder of the division of m by n,
until m mod n is equal to 0. Since gcd(m, 0) = m (why?), the
last value of m is also the greatest common divisor of the
initial m and n.
For example, gcd(60, 24) can be computed as follows:
gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
Euclid’s algorithm for computing gcd(m, n)
Pseudocode:
Consecutive Integer Checking Algorithm
Middle-School Procedure
Middle-School Procedure (cont.)
To find the gcd(60, 24), get the
◦prime factors of 60 = 2.2.3.5
◦prime factors of 24 = 2.2.2.3
gcd(60, 24) = 2.2.3 = 12
Sieve of Erathostenes
the algorithm for generating consecutive primes not
exceeding any given integer n > 1.
Sieve of Erathostenes (cont.)
Fundamentals of Algorithmic Solving
Problems
1. Understanding the problem
An input to an algorithm specifies an instance of the problem the algorithm
solves.
2. Ascertaining the Capabilities of the Computational Device
sequential algorithm – executes one after another
parallel algorithm – executes concurrently
3. Choosing between Exact and Approximate Problem Solving
4. Algorithm Design Techniques
An algorithm design technique (or “strategy” or “paradigm”) is a general
approach to solving problems algorithmically that is applicable to a variety of
problems from different areas of computing.
Fundamentals of Algorithmic Solving
Problems
5. Designing an Algorithm and Data Structures
Methods of Specifying an Algorithm: Pseudocode and Flowchart
6. Proving an Algorithm’s Correctness
7. Analyzing an Algorithm
qualities of an algorithm:
oefficiency – time and space
osimplicity
ogenerality
8. Coding an Algorithm
optimality
Algorithm
Design and
Analysis Process
Important Problem Types
Sorting
Searching
String processing
Graph problems
Combinatorial problems
Geometric problems
Numerical problems
Fundamental Data Structures
Linear Data Structure
Graphs
Trees
Sets and Dictionaries
-End -

More Related Content

PPTX
IntroductionToAlgo_v1_1709293290768 (2).pptx
PPTX
1.introduction analysis and design of algorithms(1).pptx
PDF
19IS402_LP1_LM_22-23.pdf
PDF
Sienna 1 intro
PPTX
Introduction to Design and Analysis of Algorithms
PPT
data unit notes from department of computer science
PPTX
Chapter one
PPT
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt
IntroductionToAlgo_v1_1709293290768 (2).pptx
1.introduction analysis and design of algorithms(1).pptx
19IS402_LP1_LM_22-23.pdf
Sienna 1 intro
Introduction to Design and Analysis of Algorithms
data unit notes from department of computer science
Chapter one
daaadafrhdncxfbfbgdngfmfhmhagshh_unit_i.ppt

Similar to 01 - Introduction to Algorithms.pptx (20)

PPT
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
PPT
Kk20503 1 introduction
PPT
DAA subject Power point presentations unit 1 Anna univer
PPT
DAA subject units powerpoint presentation classification of the university
PPTX
Presentation_23953_Content_Document_20240906040454PM.pptx
PPTX
1. Solving a Problem With a Computer.pptx
PDF
Daa chapter 1
PPTX
Analysis Framework, Asymptotic Notations
PPT
AA Lecture 01 of my lecture os ghhhggh.ppt
PDF
Introduction to Algorithm Design and Analysis.pdf
PPTX
Algorithm & data structures lec1
PPTX
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
PPT
chapter 1
PPT
ALGO.ppt
PPT
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
PPT
02-FAZ-A First Step Toward Algorithm Complexity Analysis.ppt
PPTX
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
PDF
Algorithm chapter 1
PPTX
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
PPTX
Chapter 1 - Algorithm Analysis & Design 2021
daa_unit THIS IS GNDFJG SDGSGS SFDF .ppt
Kk20503 1 introduction
DAA subject Power point presentations unit 1 Anna univer
DAA subject units powerpoint presentation classification of the university
Presentation_23953_Content_Document_20240906040454PM.pptx
1. Solving a Problem With a Computer.pptx
Daa chapter 1
Analysis Framework, Asymptotic Notations
AA Lecture 01 of my lecture os ghhhggh.ppt
Introduction to Algorithm Design and Analysis.pdf
Algorithm & data structures lec1
ADA_Module 1_MN.pptx- Analysis and design of Algorithms
chapter 1
ALGO.ppt
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
02-FAZ-A First Step Toward Algorithm Complexity Analysis.ppt
DESIGN AND ALGORITHM.pptx BCA BANGALORECITY UNIVERSITY
Algorithm chapter 1
BCS401 ADA Module 1 PPT 2024-25 IV SEM.pptx
Chapter 1 - Algorithm Analysis & Design 2021
Ad

Recently uploaded (20)

PDF
A systematic review of self-coping strategies used by university students to ...
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Trump Administration's workforce development strategy
PDF
Yogi Goddess Pres Conference Studio Updates
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
DOC
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Computing-Curriculum for Schools in Ghana
PPTX
master seminar digital applications in india
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
A systematic review of self-coping strategies used by university students to ...
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
Microbial disease of the cardiovascular and lymphatic systems
Trump Administration's workforce development strategy
Yogi Goddess Pres Conference Studio Updates
Pharmacology of Heart Failure /Pharmacotherapy of CHF
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Soft-furnishing-By-Architect-A.F.M.Mohiuddin-Akhand.doc
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Computing-Curriculum for Schools in Ghana
master seminar digital applications in india
O5-L3 Freight Transport Ops (International) V1.pdf
GDM (1) (1).pptx small presentation for students
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
human mycosis Human fungal infections are called human mycosis..pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Chinmaya Tiranga quiz Grand Finale.pdf
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
Ad

01 - Introduction to Algorithms.pptx

  • 1. 01 Introduction to Algorithms CS 221 – ALGORITHMS AND COMPLEXITY
  • 2. Introduction The study of algorithms, sometimes called algorithmics, has come to be recognized as the cornerstone of computer science. Algorithmics is more than a branch of computer science. It is the core of computer science, and, in all fairness, can be said to be relevant to most of science, business, and technology. - David Harel, Algorithmics: the Spirit of Computing
  • 3. Why study Algorithms? Computer programs would not exist without algorithms. With computer applications becoming indispensable in almost all aspects of our professional and personal lives, studying algorithms becomes a necessity for more and more people. Usefulness in developing analytical skills. The precision inherently imposed by algorithmic thinking limits the kinds of problems that can be solved with an algorithm.
  • 4. What is an Algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.
  • 5. Methods of solving the same problem illustrates several important points: The nonambiguity requirement for each step of an algorithm cannot be compromised. The range of inputs for which an algorithm works has to be specified carefully. The same algorithm can be represented in several different ways. There may exist several algorithms for solving the same problem. Algorithms for the same problem can be based on very different ideas and can solve the problem with dramatically different speeds.
  • 6. Euclid’s Algorithm Recall that the greatest common divisor of two nonnegative, not-both-zero integers m and n, denoted gcd(m, n), is defined as the largest integer that divides both m and n evenly, i.e., with a remainder of zero. Euclid of Alexandria (third century b.c.) outlined an algorithm for solving this problem in one of the volumes of his Elements most famous for its systematic exposition of geometry.
  • 7. Euclid’s Algorithm (cont.) gcd(m, n) = gcd(n, m mod n) where m mod n is the remainder of the division of m by n, until m mod n is equal to 0. Since gcd(m, 0) = m (why?), the last value of m is also the greatest common divisor of the initial m and n. For example, gcd(60, 24) can be computed as follows: gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12.
  • 8. Euclid’s algorithm for computing gcd(m, n)
  • 12. Middle-School Procedure (cont.) To find the gcd(60, 24), get the ◦prime factors of 60 = 2.2.3.5 ◦prime factors of 24 = 2.2.2.3 gcd(60, 24) = 2.2.3 = 12
  • 13. Sieve of Erathostenes the algorithm for generating consecutive primes not exceeding any given integer n > 1.
  • 15. Fundamentals of Algorithmic Solving Problems 1. Understanding the problem An input to an algorithm specifies an instance of the problem the algorithm solves. 2. Ascertaining the Capabilities of the Computational Device sequential algorithm – executes one after another parallel algorithm – executes concurrently 3. Choosing between Exact and Approximate Problem Solving 4. Algorithm Design Techniques An algorithm design technique (or “strategy” or “paradigm”) is a general approach to solving problems algorithmically that is applicable to a variety of problems from different areas of computing.
  • 16. Fundamentals of Algorithmic Solving Problems 5. Designing an Algorithm and Data Structures Methods of Specifying an Algorithm: Pseudocode and Flowchart 6. Proving an Algorithm’s Correctness 7. Analyzing an Algorithm qualities of an algorithm: oefficiency – time and space osimplicity ogenerality 8. Coding an Algorithm optimality
  • 18. Important Problem Types Sorting Searching String processing Graph problems Combinatorial problems Geometric problems Numerical problems
  • 19. Fundamental Data Structures Linear Data Structure Graphs Trees Sets and Dictionaries

Editor's Notes

  • #11: Step 1: If n = 0, return the value of m as the answer and stop; otherwise, proceed to Step 2. Step 2: Divide m by n and assign the value of the remainder to r. Step 3: Assign the value of n to m and the value of r to n. Go to Step 1.
  • #12: #include <iostream> using namespace std; int gcd(int m, int n) {     if(n==0)         return m;     else         return gcd(n, m % n); } int main() {          int m, n;     cout << "Enter the value of m and n: ";     cin >> m >> n;     cout << "gcd(" << m << ", " << n << ") = " << gcd(m,n) << endl;     return 0; } int m, n, r;     cout << "Enter the value of m and n: ";     cin >> m >> n;     cout << "gcd(" << m << ", " << n << ") = ";     while(n != 0)     {         r = m % n;         m = n;         n = r;     }     cout << m << endl;