Design and Analysis of Algorithms - Chapter 1

Slides:



Advertisements
Similar presentations
Anany Levitin ACM SIGCSE 1999SIG. Outline Introduction Four General Design Techniques A Test of Generality Further Refinements Conclusion.
Advertisements

COEN 352 Data structures and Algorithms R. Dssouli.
5/15/2015COT COT 5407: Introduction to Algorithms Tao Li ECS 318; Phone: x6036
Chapter 1 Sections 1.1 – 1.4 pages Homework  Read Section 1.4 (recap of data structures)  pages  Answer the following questions: page 38,
The Design & Analysis of the algorithms Lecture by me M. Sakalli.
Design and Analysis of Algorithms - Chapter 1
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.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
The Design and Analysis of Algorithms
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Design and Analysis of Algorithms - Chapter 11 Algorithm An algorithm is a.
TK3043 Analysis and Design of Algorithms Introduction to Algorithms.
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
Design and Analysis of Algorithms
Induction and recursion
Design & Analysis of Algorithms Introduction. Introduction Algorithms are the ideas behind computer programs. An algorithm is the thing which stays the.
Why study algorithms? Theoretical importance
Introduction Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org Some of the sides are exported from different sources to.
CSCE350: Data Structures and Algorithms Instructor: Dr. Jianjun Hu Fall Department of Computer Science and Engineering.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
The Integers. The Division Algorithms A high-school question: Compute 58/17. We can write 58 as 58 = 3 (17) + 7 This forms illustrates the answer: “3.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
1Computer Sciences Department. Book: Introduction to Algorithms, by: Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest Clifford Stein Electronic:
Design & Analysis of Algorithms Lecture 1 Introduction.
INTRODUCTION. What is an algorithm? What is a Problem?
FIRST QUESTIONS FOR ALGORITHM ANALYSIS. WHAT IS AN ALGORITHM? From the text (p. 3): “An algorithm is a sequence of unambiguous instructions for solving.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. Chapter 1 Introduction.
Design and Analysis of Algorithms - Chapter 11 Algorithm b An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining.
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.
UNIT-I INTRODUCTION ANALYSIS AND DESIGN OF ALGORITHMS CHAPTER 1:
Analysis of Algorithms COME 355 Introduction. What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e.,
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3 rd ed., Ch. 1 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 1. Complexity Bounds.
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
CS 615: Design & Analysis of Algorithms Chapter 2: Efficiency of Algorithms.
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
Introduction to design and analysis algorithm
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
MA/CSSE 473 Day 07 Euclid's Algorithm. MA/CSSE 473 Day 07 Student Questions Review topics not covered in class Euclid's algorithm (if there is time) extended.
Prof. Amr Goneid, AUC1 CSCE 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 3. Introduction to the Analysis of Algorithms.
1.  A step by step process to solve any problem is called algorithm.  Algorithm is a process which take some values as input and provide us output.
1 Introduction to design and analysis algorithm. 2.
Advanced Algorithms Analysis and Design
Chapter 4 (Part 3): Mathematical Reasoning, Induction & Recursion
TK3043 Analysis and Design of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
The Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
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.
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.
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.
Introduction to the Design and Analysis of Algorithms
Introduction to The Design & Analysis of Algorithms
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.
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
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.
アルゴリズムの設計と解析 教授: 黄 潤和 (W4022) SA: 広野 史明 (A4/A10)
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
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.
Objective of This Course
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Lecture 6 Architecture Algorithm Defin ition. Algorithm 1stDefinition: Sequence of steps that can be taken to solve a problem 2ndDefinition: The step.
Algorithms Algorithm. [webster.com] A procedure for solving a mathematical problem (as of finding the greatest common divisor) in a finite number of steps.
Introduction to Algorithms
CSC 380: Design and Analysis of Algorithms
Design and Analysis of Algorithms
Chapter 1 Introduction Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Welcome to the most Amazing course there is 
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.
Presentation transcript:

Design and Analysis of Algorithms - Chapter 1 Σχεδίαση Αλγορίθμων Introduction to the Design and Analysis of Algorithms by Anany Levitin www.aw-bc.com/info/levitin/ Design and Analysis of Algorithms - Chapter 1

Design and Analysis of Algorithms - Chapter 1 Σχεδίαση Αλγορίθμων http://delab.csd.auth.gr/courses.html Ημερολόγιο, βιβλιογραφία, ανακοινώσεις Θα διανεμηθεί το βιβλίο «Αλγόριθμοι» του Παναγιώτη Μποζάνη, Εκδόσεις Τζιόλα, 2005. Design and Analysis of Algorithms - Chapter 1

Design and Analysis of Algorithms - Chapter 1 Why study algorithms? Wirth 1976: Algorithms + Data Structures = Programs Theoretical importance the core of computer science Practical importance A practitioner’s toolkit of known algorithms Framework for designing and analyzing algorithms for new problems Design and Analysis of Algorithms - Chapter 1

Design and Analysis of Algorithms - Chapter 1 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. Design and Analysis of Algorithms - Chapter 1

Design and Analysis of Algorithms - Chapter 1 “Besides merely being a finite set of rules that gives a sequence of operations for solving a specific type of problem, an algorithm has the five important features” [Knuth] finiteness (otherwise: computational method) termination definiteness precise definition of each step input (zero or more) output (one or more) effectiveness Its operations must all be sufficiently basic that they can in principle be done exactly and in a finite length of time by someone using pencil and paper Design and Analysis of Algorithms - Chapter 1

Historical Perspective Euclid’s algorithm for finding the greatest common divisor http://en.wikipedia.org/wiki/Al-Khwarizmi Abū ‘Abd Allāh Muḥammad ibn Mūsā al-Khwārizmī (أبو عبد الله محمد بن موسى الخوارزمي) was a Muslim mathematician, astronomer, astrologer, geographer and author. He was born in Persia around 780, and died around 850. Because of his book on the systematic solution of linear and quadratic equations, al-Kitāb al-mukhtaṣar fī hīsāb al-ğabr wa’l-muqābala, together with Diophantus, he is considered to be the father of algebra. The word algebra is derived from al-ğabr, one of the two operations used to solve quadratic equations, as described in his book. Algoritmi de numero Indorum, the Latin translation of his other major work, on the Indian numerals, introduced the positional number system and the number zero to the Western world in the 12th century. The words algorism and algorithm stem from Algoritmi, the Latinization of his name Euclid’s algorithm is good for introducing the notion of an algorithm because it makes a clear separation from a program that implements the algorithm. It is also one that is familiar to most students. Al Khowarizmi (many spellings possible...) – “algorism” (originally) and then later “algorithm” come from his name. Design and Analysis of Algorithms - Chapter 1

Notion of algorithm problem algorithm input output “computer” input output Algorithmic solution : a way to teach the computer Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 1 Step 1 Assign the value of min{m,n} to t Step 2 Divide m by t. If the remainder of this division is 0, go to Step 3; otherwise, to Step 4 Step 3 Divide n by t. If the remainder of this division is 0, return the value of t as the answer and stop; otherwise, proceed to Step 4 Step 4 Decrease the value of t by 1. Go to Step 2 Note: m and n are positive integers Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 1 Correctness The algorithm terminates, because t is decreased by 1 each time we go through step 4, 1 divides any integer, and t eventually will reach 1 unless the algorithm stops earlier. The algorithm is partially correct, because when it returns t as the answer, t is the minimum value that divides both m and n Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 2 Step 1 Find the prime factors of m Step 2 Find the prime factors of n Step 3 Identify all the common factors in the two prime expansions found in Steps 1 and 2. If p is a common factor repeated i times in m and j times in n, assign to p the multiplicity min{i,j} Step 4 Compute the product of all the common factors with their multiplicities and return it as the GCD of m and n Note: as written, the algorithm requires than m and n be integers greater than 1, since 1 is not a prime Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 2 In fact “Algorithm 2” is not an algorithm unless we can provide an effective way to find prime factors of a number The sieve of Eratosthenes is an algorithm that provides such an effective procedure Πως δουλεύει το κόσκινο του Ερατοσθένη ?? Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 3 Euclid’s Algorithm E0 [Ensure n≤ m] If m < n, exchange m with n E1 [Find Remainder] Divide m by n and let r be the remainder (We will have 0 ≤ r < n) E2 [Is it zero?] If r=0, the algorithm terminates; n is the answer E3 [Reduce] Set m to n, n to r, and go back to E1 Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 3 Termination of Euclid’s Algorithm The second number of the pair gets smaller with each iteration and cannot become negative: indeed, the new value of n is r = m mod n, which is always smaller than n. Eventually, r becomes zero, and the algorithms stops. Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 3 Correctness of Euclid’s Algorithm After step E1, we have m=qn+r, for some integer q. If r=0, then m is a multiple of n, and clearly in such a case n is the GCD of m and n. If r≠0, note that any number that divides both m and n must divide m–qn=r, and any number that divides both n and r must divide qn+r=m; so the set of divisors of {m,n} is the same as the set of divisors of {n,r}. In particular, the GCD of {m,n} is the same as the GCD of {n,r}. Therefore, E3 does not change the answer to the original problem. Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 3 Book Variation (p.4) 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. Note: m and n are nonnegative, not-both-zero integers Design and Analysis of Algorithms - Chapter 1

Greatest Common Divisor - Algorithm 3 Pseudocode for book version while n <> 0 do r  m mod n m  n n  r return m Design and Analysis of Algorithms - Chapter 1

Example of computational problem: sorting Statement of problem: Input: A sequence of n numbers <a1,a2,…,an> Output: A reordering of the input sequence <a1,a´2,…,an> so that ai≤aj whenever i<j Instance: The sequence <5, 3, 2, 8, 3> Algorithms: Selection sort Insertion sort Merge sort (many others) Design and Analysis of Algorithms - Chapter 1

Selection Sort Input: array a[1],...,a[n] Output: array a sorted in non-decreasing order Algorithm: for i=1 to n swap a[i] with smallest of a[i],…a[n] (In place sorting, stable sorting) see also pseudocode, section 3.1 The algorithm is given *very* informally here. Show students the pseudocode in section 3.1. This is a good opportunity to discuss pseudocode conventions. Design and Analysis of Algorithms - Chapter 1

Some Well-known Computational Problems Sorting Searching String searching Graph problems (shortest paths, minimum spanning tree, graph-coloring etc) Combinatorial problems (tsp) Geometric problems (closest-pair, convex hull) Numerical problems (equations, integrals) Other (primality testing, knapsack problem, chess, towers of Hanoi) 1-4 have well known efficient (polynomial-time) solutions 5: primality testing has recently been found to have an efficient solution This is a great problem to discuss because it has recently been in the news (see mathworld news at: http://mathworld.wolfram.com/news/2002-08-07_primetest/ or original article: http://www.cse.iitk.ac.in/primality.pdf) 6(TSP)-9(chess) are all problems for which no efficient solution has been found it is possible to informally discuss the “try all possibilities” approach that is required to get exact solutions to such problems 10: Towers of Hanoi is a problem that has only exponential-time solutions (simply because the output required is so large) 11: Program termination is undecidable Design and Analysis of Algorithms - Chapter 1

Basic Issues Related to Algorithms Understanding the problem (instances, ranges) Ascertaining the capabilities of a computational device (RAM and parallel machines, speed and amount of memory) Choosing between exact and approximate algorithms Deciding the correct data structure Algorithm design techniques Methods of specifying an algorithm (free language, pseudocode, flowchart) Proving an algorithm’s correctness Analyzing an algorithm (efficiency, theoretical and empirical analysis, optimality) Coding an algorithm Design and Analysis of Algorithms - Chapter 1

Algorithm design strategies Brute force Divide and conquer Decrease and conquer Transform and conquer Greedy approach Dynamic programming Backtracking and Branch and bound Space and time tradeoffs Design and Analysis of Algorithms - Chapter 1

Analysis of Algorithms How good is the algorithm? Correctness Time efficiency Space efficiency Simple (recursive, iterative) General Does there exist a better algorithm? Lower bounds Optimality Design and Analysis of Algorithms - Chapter 1