SlideShare una empresa de Scribd logo
1 de 24
Descargar para leer sin conexión
Lecture 1:
  Introduction to Algorithms
         Steven Skiena

Department of Computer Science
 State University of New York
 Stony Brook, NY 11794–4400

http://www.cs.sunysb.edu/∼skiena
What Is An Algorithm?
Algorithms are the ideas behind computer programs.
An algorithm is the thing which stays the same whether the
program is in Pascal running on a Cray in New York or is in
BASIC running on a Macintosh in Kathmandu!
To be interesting, an algorithm has to solve a general,
specified problem. An algorithmic problem is specified by
describing the set of instances it must work on and what
desired properties the output must have.
Example: Sorting
Input: A sequence of N numbers a1 ...an
Output: the permutation (reordering) of the input sequence
such as a1 ≤ a2 . . . ≤ an.
We seek algorithms which are correct and efficient.
Correctness
For any algorithm, we must prove that it always returns the
desired output for all legal instances of the problem.
For sorting, this means even if (1) the input is already sorted,
or (2) it contains repeated elements.
Algorithm correctness is not obvious in many optimization
problems!
Robot Tour Optimization
Suppose you have a robot arm equipped with a tool, say a
soldering iron. To enable the robot arm to do a soldering job,
we must construct an ordering of the contact points, so the
robot visits (and solders) the points in order.
We seek the order which minimizes the testing time (i.e.
travel distance) it takes to assemble the circuit board.
Find the Shortest Robot Tour




You are given the job to program the robot arm. Give me an
algorithm to find the best tour!
Nearest Neighbor Tour
A popular solution starts at some point p0 and then walks to
its nearest neighbor p1 first, then repeats from p1 , etc. until
done.
Pick and visit an initial point p0
p = p0
i=0
While there are still unvisited points
       i=i+1
       Let pi be the closest unvisited point to pi−1
       Visit pi
Return to p0 from pi
Nearest Neighbor Tour is Wrong!




        -21                  -5   -1   0   1   3   11




        -21                  -5   -1   0   1   3   11




Starting from the leftmost point will not fix the problem.
Closest Pair Tour
Another idea is to repeatedly connect the closest pair of
points whose connection will not cause a cycle or a three-way
branch, until all points are in one tour.
Let n be the number of points in the set
d=∞
For i = 1 to n − 1 do
      For each pair of endpoints (x, y) of partial paths
             If dist(x, y) ≤ d then
                    xm = x, ym = y, d = dist(x, y)
      Connect (xm , ym) by an edge
Connect the two endpoints by an edge.
Closest Pair Tour is Wrong!
Although it works correctly on the previous example, other
data causes trouble:
A Correct Algorithm: Exhaustive Search
We could try all possible orderings of the points, then select
the one which minimizes the total length:
d=∞
For each of the n! permutations Πi of the n points
      If (cost(Πi) ≤ d) then
             d = cost(Πi) and Pmin = Πi
Return Pmin


Since all possible orderings are considered, we are guaranteed
to end up with the shortest possible tour.
Exhaustive Search is Slow!
Because it tries all n! permutations, it is much too slow to use
when there are more than 10-20 points.
No efficient, correct algorithm exists for the traveling
salesman problem, as we will see later.
Efficiency: Why Not Use a Supercomputer?
A faster algorithm running on a slower computer will always
win for sufficiently large instances, as we shall see.
Usually, problems don’t have to get that large before the faster
algorithm wins.
Expressing Algorithms
We need some way to express the sequence of steps
comprising an algorithm.
In order of increasing precision, we have English, pseu-
docode, and real programming languages. Unfortunately,
ease of expression moves in the reverse order.
I prefer to describe the ideas of an algorithm in English,
moving to pseudocode to clarify sufficiently tricky details of
the algorithm.
Algorithms problems must be carefully specified to allow a
provably correct algorithm to exist. We can find the “shortest
tour” but not the “best tour”.
%swallow
Selecting the Right Jobs
A movie star wants to the select the maximum number of
staring roles such that no two jobs require his presence at the
same time.
                          Tarjan of the Jungle                    The Four Volume Problem

              The President’s Algorist           Steiner’s Tree                         Process Terminated
                                           Halting State            Programming Challenges
            "Discrete" Mathematics                                                             Calculated Bets
The Movie Star Scheduling Problem
Input: A set I of n intervals on the line.
Output: What is the largest subset of mutually non-
overlapping intervals which can be selected from I?
Give an algorithm to solve the problem!
Earliest Job First
Start working as soon as there is work available:
EarliestJobFirst(I)
      Accept the earlest starting job j from I which
      does not overlap any previously accepted job, and
      repeat until no more such jobs remain.
Earliest Job First is Wrong!
The first job might be so long (War and Peace) that it prevents
us from taking any other job.
Shortest Job First
Always take the shortest possible job, so you spend the least
time working (and thus unavailable).
ShortestJobFirst(I)
      While (I = ∅) do
            Accept the shortest possible job j from I.
            Delete j, and intervals which intersect j from I.
Shortest Job First is Wrong!
Taking the shortest job can prevent us from taking two longer
jobs which barely overlap it.
First Job to Complete
Take the job with the earliest completion date:
OptimalScheduling(I)
     While (I = ∅) do
          Accept job j with the earliest completion date.
          Delete j, and whatever intersects j from I.
First Job to Complete is Optimal!
Other jobs may well have started before the first to complete
(x), but all must at least partially overlap each other.
Thus we can select at most one from the group.
The first these jobs to complete is x, so the rest can only block
out more opportunties to the right of x.
Demonstrating Incorrectness
Searching for counterexamples is the best way to disprove the
correctness of a heuristic.
 • Think about all small examples.
 • Think about examples with ties on your decision criteria
   (e.g. pick the nearest point)
 • Think about examples with extremes of big and small. . .
Induction and Recursion
Failure to find a counterexample to a given algorithm does
not mean “it is obvious” that the algorithm is correct.
Mathematical induction is a very useful method for proving
the correctness of recursive algorithms.
Recursion and induction are the same basic idea: (1) basis
case, (2) general assumption, (3) general case.
                     n
                          i = n(n + 1)/2
                    i=1

Más contenido relacionado

La actualidad más candente

Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP CompletenessGene Moo Lee
 
Computability and Complexity
Computability and ComplexityComputability and Complexity
Computability and ComplexityEdward Blurock
 
Np Completeness
Np CompletenessNp Completeness
Np CompletenessRajan Shah
 
lecture 27
lecture 27lecture 27
lecture 27sajinsc
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithmCHANDAN KUMAR
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithmNisha Soms
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練Abner Huang
 

La actualidad más candente (10)

Introduction to NP Completeness
Introduction to NP CompletenessIntroduction to NP Completeness
Introduction to NP Completeness
 
Computability and Complexity
Computability and ComplexityComputability and Complexity
Computability and Complexity
 
Turing machine
Turing machineTuring machine
Turing machine
 
NP Complete Problems in Graph Theory
NP Complete Problems in Graph TheoryNP Complete Problems in Graph Theory
NP Complete Problems in Graph Theory
 
Np Completeness
Np CompletenessNp Completeness
Np Completeness
 
lecture 27
lecture 27lecture 27
lecture 27
 
Divide and conquer algorithm
Divide and conquer algorithmDivide and conquer algorithm
Divide and conquer algorithm
 
Notion of an algorithm
Notion of an algorithmNotion of an algorithm
Notion of an algorithm
 
Greedy algorithm
Greedy algorithmGreedy algorithm
Greedy algorithm
 
2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練2009 CSBB LAB 新生訓練
2009 CSBB LAB 新生訓練
 

Destacado

09 cv mil_classification
09 cv mil_classification09 cv mil_classification
09 cv mil_classificationzukun
 
10 cv mil_graphical_models
10 cv mil_graphical_models10 cv mil_graphical_models
10 cv mil_graphical_modelszukun
 
Skiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challengeSkiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challengezukun
 
Fcv hist lowe
Fcv hist loweFcv hist lowe
Fcv hist lowezukun
 
Fcv poster ji
Fcv poster jiFcv poster ji
Fcv poster jizukun
 
Fcv appli science_golland
Fcv appli science_gollandFcv appli science_golland
Fcv appli science_gollandzukun
 
Fcv taxo chellappa
Fcv taxo chellappaFcv taxo chellappa
Fcv taxo chellappazukun
 
Fcv acad ind_martin
Fcv acad ind_martinFcv acad ind_martin
Fcv acad ind_martinzukun
 
Fcv scene efros
Fcv scene efrosFcv scene efros
Fcv scene efroszukun
 
Fcv scene lazebnik
Fcv scene lazebnikFcv scene lazebnik
Fcv scene lazebnikzukun
 
Fcv rep tenenbaum
Fcv rep tenenbaumFcv rep tenenbaum
Fcv rep tenenbaumzukun
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingzukun
 
Fcv rep a_berg
Fcv rep a_bergFcv rep a_berg
Fcv rep a_bergzukun
 
Fcv hum mach_belongie
Fcv hum mach_belongieFcv hum mach_belongie
Fcv hum mach_belongiezukun
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortzukun
 
04 structured support vector machine
04 structured support vector machine04 structured support vector machine
04 structured support vector machinezukun
 
19 cv mil_temporal_models
19 cv mil_temporal_models19 cv mil_temporal_models
19 cv mil_temporal_modelszukun
 
Fcv hum mach_t_berg
Fcv hum mach_t_bergFcv hum mach_t_berg
Fcv hum mach_t_bergzukun
 
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer Vision
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer VisionCVPR2012: Tutorial: Graphcut-based Optimisation for Computer Vision
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer Visionzukun
 
Pp présentation apsad 93 part1
Pp présentation apsad 93 part1Pp présentation apsad 93 part1
Pp présentation apsad 93 part1gorbi94
 

Destacado (20)

09 cv mil_classification
09 cv mil_classification09 cv mil_classification
09 cv mil_classification
 
10 cv mil_graphical_models
10 cv mil_graphical_models10 cv mil_graphical_models
10 cv mil_graphical_models
 
Skiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challengeSkiena algorithm 2007 lecture22 np completeness challenge
Skiena algorithm 2007 lecture22 np completeness challenge
 
Fcv hist lowe
Fcv hist loweFcv hist lowe
Fcv hist lowe
 
Fcv poster ji
Fcv poster jiFcv poster ji
Fcv poster ji
 
Fcv appli science_golland
Fcv appli science_gollandFcv appli science_golland
Fcv appli science_golland
 
Fcv taxo chellappa
Fcv taxo chellappaFcv taxo chellappa
Fcv taxo chellappa
 
Fcv acad ind_martin
Fcv acad ind_martinFcv acad ind_martin
Fcv acad ind_martin
 
Fcv scene efros
Fcv scene efrosFcv scene efros
Fcv scene efros
 
Fcv scene lazebnik
Fcv scene lazebnikFcv scene lazebnik
Fcv scene lazebnik
 
Fcv rep tenenbaum
Fcv rep tenenbaumFcv rep tenenbaum
Fcv rep tenenbaum
 
Skiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sortingSkiena algorithm 2007 lecture06 sorting
Skiena algorithm 2007 lecture06 sorting
 
Fcv rep a_berg
Fcv rep a_bergFcv rep a_berg
Fcv rep a_berg
 
Fcv hum mach_belongie
Fcv hum mach_belongieFcv hum mach_belongie
Fcv hum mach_belongie
 
Skiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksortSkiena algorithm 2007 lecture08 quicksort
Skiena algorithm 2007 lecture08 quicksort
 
04 structured support vector machine
04 structured support vector machine04 structured support vector machine
04 structured support vector machine
 
19 cv mil_temporal_models
19 cv mil_temporal_models19 cv mil_temporal_models
19 cv mil_temporal_models
 
Fcv hum mach_t_berg
Fcv hum mach_t_bergFcv hum mach_t_berg
Fcv hum mach_t_berg
 
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer Vision
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer VisionCVPR2012: Tutorial: Graphcut-based Optimisation for Computer Vision
CVPR2012: Tutorial: Graphcut-based Optimisation for Computer Vision
 
Pp présentation apsad 93 part1
Pp présentation apsad 93 part1Pp présentation apsad 93 part1
Pp présentation apsad 93 part1
 

Similar a Skiena algorithm 2007 lecture01 introduction to algorithms

2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiouvafopoulos
 
Bt0080 fundamentals of algorithms1
Bt0080 fundamentals of algorithms1Bt0080 fundamentals of algorithms1
Bt0080 fundamentals of algorithms1Techglyphs
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notesProf. Dr. K. Adisesha
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problemsJyotsna Suryadevara
 
(1) collections algorithms
(1) collections algorithms(1) collections algorithms
(1) collections algorithmsNico Ludwig
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer scienceRiazul Islam
 
the halting_problem
the halting_problemthe halting_problem
the halting_problemRajendran
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality TestingMohammad Elsheikh
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to AlgorithmsVenkatesh Iyer
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsNagendraK18
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfShiwani Gupta
 

Similar a Skiena algorithm 2007 lecture01 introduction to algorithms (20)

2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou2010 3-24 cryptography stamatiou
2010 3-24 cryptography stamatiou
 
Bt0080 fundamentals of algorithms1
Bt0080 fundamentals of algorithms1Bt0080 fundamentals of algorithms1
Bt0080 fundamentals of algorithms1
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
(1) collections algorithms
(1) collections algorithms(1) collections algorithms
(1) collections algorithms
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer science
 
the halting_problem
the halting_problemthe halting_problem
the halting_problem
 
Daa notes 2
Daa notes 2Daa notes 2
Daa notes 2
 
The Complexity Of Primality Testing
The Complexity Of Primality TestingThe Complexity Of Primality Testing
The Complexity Of Primality Testing
 
Analysis of algorithms
Analysis of algorithmsAnalysis of algorithms
Analysis of algorithms
 
Introduction to Algorithms
Introduction to AlgorithmsIntroduction to Algorithms
Introduction to Algorithms
 
01-algo.ppt
01-algo.ppt01-algo.ppt
01-algo.ppt
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
DAA UNIT 3
DAA UNIT 3DAA UNIT 3
DAA UNIT 3
 
module1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdfmodule1_Introductiontoalgorithms_2022.pdf
module1_Introductiontoalgorithms_2022.pdf
 
Ch08
Ch08Ch08
Ch08
 
Algorithm Assignment Help
Algorithm Assignment HelpAlgorithm Assignment Help
Algorithm Assignment Help
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
Alg1
Alg1Alg1
Alg1
 

Más de zukun

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009zukun
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVzukun
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Informationzukun
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statisticszukun
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibrationzukun
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionzukun
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluationzukun
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-softwarezukun
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptorszukun
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectorszukun
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-introzukun
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video searchzukun
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video searchzukun
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video searchzukun
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learningzukun
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionzukun
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick startzukun
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysiszukun
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structureszukun
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities zukun
 

Más de zukun (20)

My lyn tutorial 2009
My lyn tutorial 2009My lyn tutorial 2009
My lyn tutorial 2009
 
ETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCVETHZ CV2012: Tutorial openCV
ETHZ CV2012: Tutorial openCV
 
ETHZ CV2012: Information
ETHZ CV2012: InformationETHZ CV2012: Information
ETHZ CV2012: Information
 
Siwei lyu: natural image statistics
Siwei lyu: natural image statisticsSiwei lyu: natural image statistics
Siwei lyu: natural image statistics
 
Lecture9 camera calibration
Lecture9 camera calibrationLecture9 camera calibration
Lecture9 camera calibration
 
Brunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer visionBrunelli 2008: template matching techniques in computer vision
Brunelli 2008: template matching techniques in computer vision
 
Modern features-part-4-evaluation
Modern features-part-4-evaluationModern features-part-4-evaluation
Modern features-part-4-evaluation
 
Modern features-part-3-software
Modern features-part-3-softwareModern features-part-3-software
Modern features-part-3-software
 
Modern features-part-2-descriptors
Modern features-part-2-descriptorsModern features-part-2-descriptors
Modern features-part-2-descriptors
 
Modern features-part-1-detectors
Modern features-part-1-detectorsModern features-part-1-detectors
Modern features-part-1-detectors
 
Modern features-part-0-intro
Modern features-part-0-introModern features-part-0-intro
Modern features-part-0-intro
 
Lecture 02 internet video search
Lecture 02 internet video searchLecture 02 internet video search
Lecture 02 internet video search
 
Lecture 01 internet video search
Lecture 01 internet video searchLecture 01 internet video search
Lecture 01 internet video search
 
Lecture 03 internet video search
Lecture 03 internet video searchLecture 03 internet video search
Lecture 03 internet video search
 
Icml2012 tutorial representation_learning
Icml2012 tutorial representation_learningIcml2012 tutorial representation_learning
Icml2012 tutorial representation_learning
 
Advances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer visionAdvances in discrete energy minimisation for computer vision
Advances in discrete energy minimisation for computer vision
 
Gephi tutorial: quick start
Gephi tutorial: quick startGephi tutorial: quick start
Gephi tutorial: quick start
 
EM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysisEM algorithm and its application in probabilistic latent semantic analysis
EM algorithm and its application in probabilistic latent semantic analysis
 
Object recognition with pictorial structures
Object recognition with pictorial structuresObject recognition with pictorial structures
Object recognition with pictorial structures
 
Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities Iccv2011 learning spatiotemporal graphs of human activities
Iccv2011 learning spatiotemporal graphs of human activities
 

Último

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Último (20)

Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

Skiena algorithm 2007 lecture01 introduction to algorithms

  • 1. Lecture 1: Introduction to Algorithms Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794–4400 http://www.cs.sunysb.edu/∼skiena
  • 2. What Is An Algorithm? Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the same whether the program is in Pascal running on a Cray in New York or is in BASIC running on a Macintosh in Kathmandu! To be interesting, an algorithm has to solve a general, specified problem. An algorithmic problem is specified by describing the set of instances it must work on and what desired properties the output must have.
  • 3. Example: Sorting Input: A sequence of N numbers a1 ...an Output: the permutation (reordering) of the input sequence such as a1 ≤ a2 . . . ≤ an. We seek algorithms which are correct and efficient.
  • 4. Correctness For any algorithm, we must prove that it always returns the desired output for all legal instances of the problem. For sorting, this means even if (1) the input is already sorted, or (2) it contains repeated elements. Algorithm correctness is not obvious in many optimization problems!
  • 5. Robot Tour Optimization Suppose you have a robot arm equipped with a tool, say a soldering iron. To enable the robot arm to do a soldering job, we must construct an ordering of the contact points, so the robot visits (and solders) the points in order. We seek the order which minimizes the testing time (i.e. travel distance) it takes to assemble the circuit board.
  • 6. Find the Shortest Robot Tour You are given the job to program the robot arm. Give me an algorithm to find the best tour!
  • 7. Nearest Neighbor Tour A popular solution starts at some point p0 and then walks to its nearest neighbor p1 first, then repeats from p1 , etc. until done. Pick and visit an initial point p0 p = p0 i=0 While there are still unvisited points i=i+1 Let pi be the closest unvisited point to pi−1 Visit pi Return to p0 from pi
  • 8. Nearest Neighbor Tour is Wrong! -21 -5 -1 0 1 3 11 -21 -5 -1 0 1 3 11 Starting from the leftmost point will not fix the problem.
  • 9. Closest Pair Tour Another idea is to repeatedly connect the closest pair of points whose connection will not cause a cycle or a three-way branch, until all points are in one tour. Let n be the number of points in the set d=∞ For i = 1 to n − 1 do For each pair of endpoints (x, y) of partial paths If dist(x, y) ≤ d then xm = x, ym = y, d = dist(x, y) Connect (xm , ym) by an edge Connect the two endpoints by an edge.
  • 10. Closest Pair Tour is Wrong! Although it works correctly on the previous example, other data causes trouble:
  • 11. A Correct Algorithm: Exhaustive Search We could try all possible orderings of the points, then select the one which minimizes the total length: d=∞ For each of the n! permutations Πi of the n points If (cost(Πi) ≤ d) then d = cost(Πi) and Pmin = Πi Return Pmin Since all possible orderings are considered, we are guaranteed to end up with the shortest possible tour.
  • 12. Exhaustive Search is Slow! Because it tries all n! permutations, it is much too slow to use when there are more than 10-20 points. No efficient, correct algorithm exists for the traveling salesman problem, as we will see later.
  • 13. Efficiency: Why Not Use a Supercomputer? A faster algorithm running on a slower computer will always win for sufficiently large instances, as we shall see. Usually, problems don’t have to get that large before the faster algorithm wins.
  • 14. Expressing Algorithms We need some way to express the sequence of steps comprising an algorithm. In order of increasing precision, we have English, pseu- docode, and real programming languages. Unfortunately, ease of expression moves in the reverse order. I prefer to describe the ideas of an algorithm in English, moving to pseudocode to clarify sufficiently tricky details of the algorithm. Algorithms problems must be carefully specified to allow a provably correct algorithm to exist. We can find the “shortest tour” but not the “best tour”. %swallow
  • 15. Selecting the Right Jobs A movie star wants to the select the maximum number of staring roles such that no two jobs require his presence at the same time. Tarjan of the Jungle The Four Volume Problem The President’s Algorist Steiner’s Tree Process Terminated Halting State Programming Challenges "Discrete" Mathematics Calculated Bets
  • 16. The Movie Star Scheduling Problem Input: A set I of n intervals on the line. Output: What is the largest subset of mutually non- overlapping intervals which can be selected from I? Give an algorithm to solve the problem!
  • 17. Earliest Job First Start working as soon as there is work available: EarliestJobFirst(I) Accept the earlest starting job j from I which does not overlap any previously accepted job, and repeat until no more such jobs remain.
  • 18. Earliest Job First is Wrong! The first job might be so long (War and Peace) that it prevents us from taking any other job.
  • 19. Shortest Job First Always take the shortest possible job, so you spend the least time working (and thus unavailable). ShortestJobFirst(I) While (I = ∅) do Accept the shortest possible job j from I. Delete j, and intervals which intersect j from I.
  • 20. Shortest Job First is Wrong! Taking the shortest job can prevent us from taking two longer jobs which barely overlap it.
  • 21. First Job to Complete Take the job with the earliest completion date: OptimalScheduling(I) While (I = ∅) do Accept job j with the earliest completion date. Delete j, and whatever intersects j from I.
  • 22. First Job to Complete is Optimal! Other jobs may well have started before the first to complete (x), but all must at least partially overlap each other. Thus we can select at most one from the group. The first these jobs to complete is x, so the rest can only block out more opportunties to the right of x.
  • 23. Demonstrating Incorrectness Searching for counterexamples is the best way to disprove the correctness of a heuristic. • Think about all small examples. • Think about examples with ties on your decision criteria (e.g. pick the nearest point) • Think about examples with extremes of big and small. . .
  • 24. Induction and Recursion Failure to find a counterexample to a given algorithm does not mean “it is obvious” that the algorithm is correct. Mathematical induction is a very useful method for proving the correctness of recursive algorithms. Recursion and induction are the same basic idea: (1) basis case, (2) general assumption, (3) general case. n i = n(n + 1)/2 i=1