Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms
Advertisements

CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
Algorithm Design Paradigms
1 Divide-and-Conquer The most-well known algorithm design strategy: 1. Divide instance of problem into two or more smaller instances 2. Solve smaller instances.
1 Potential for Parallel Computation Module 2. 2 Potential for Parallelism Much trivially parallel computing  Independent data, accounts  Nothing to.
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture.
Lecture 5COMPSCI.220.FS.T Worst-Case Performance Upper bounds : simple to obtain Lower bounds : a difficult matter... Worst case data may be unlikely.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
CSE 326 Asymptotic Analysis David Kaplan Dept of Computer Science & Engineering Autumn 2001.
Introduction to Analysis of Algorithms
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Notes on the analysis of multiplication algorithms.. Dr. M. Sakalli, Marmara University.
Algorithmic Complexity 2 Nelson Padua-Perez Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Analysis of Algorithms
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Algorithmic Complexity 3 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Dynamic Programming Introduction to Algorithms Dynamic Programming CSE 680 Prof. Roger Crawfis.
Grade School Revisited: How To Multiply Two Numbers Great Theoretical Ideas In Computer Science S. Rudich V. Adamchik CS Spring 2006 Lecture 18March.
DATA STRUCTURES AND ALGORITHMS Lecture Notes 1 Prepared by İnanç TAHRALI.
CSE373: Data Structures and Algorithms Lecture 4: Asymptotic Analysis Aaron Bauer Winter 2014.
MA/CSSE 473 Day 03 Asymptotics A Closer Look at Arithmetic With another student, try to write a precise, formal definition of “t(n) is in O(g(n))”
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2013 Lecture 12.
Bold Stroke January 13, 2003 Advanced Algorithms CS 539/441 OR In Search Of Efficient General Solutions Joe Hoffert
CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea Algorithm Analysis II Reading: Weiss, chap. 2.
CS 3343: Analysis of Algorithms
Iterative Algorithm Analysis & Asymptotic Notations
COMP 232 Intro Lecture. Introduction to Course Me – Dr. John Sigle Purpose/goals of the course Purpose/goals Prerequisites - COMP 132 (Java skill & Eclipse)
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Dynamic Programming. Well known algorithm design techniques:. –Divide-and-conquer algorithms Another strategy for designing algorithms is dynamic programming.
CSCI-256 Data Structures & Algorithm Analysis Lecture Note: Some slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. 4.
2.1 Computational Tractability. 2 Computational Tractability Charles Babbage (1864) As soon as an Analytic Engine exists, it will necessarily guide the.
Great Theoretical Ideas in Computer Science.
Object-Oriented Design CSC 212. Announcements Ask more questions!  Your fellow students have the same questions (remember, I grade the daily quizzes)
1 COMP3040 Tutorial 1 Analysis of algorithms. 2 Outline Motivation Analysis of algorithms Examples Practice questions.
Algorithms  Al-Khwarizmi, arab mathematician, 8 th century  Wrote a book: al-kitab… from which the word Algebra comes  Oldest algorithm: Euclidian algorithm.
CSE332: Data Abstractions Lecture 14: Beyond Comparison Sorting Dan Grossman Spring 2012.
Major objective of this course is: Design and analysis of modern algorithms Different variants Accuracy Efficiency Comparing efficiencies Motivation thinking.
CSC 413/513: Intro to Algorithms NP Completeness.
Introduction to Analysis of Algorithms COMP171 Fall 2005.
1 CPSC 320: Intermediate Algorithm Design and Analysis July 28, 2014.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CSCI 3160 Design and Analysis of Algorithms Tutorial 10 Chengyu Lin.
MS 101: Algorithms Instructor Neelima Gupta
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Umans Complexity Theory Lectures Lecture 1a: Problems and Languages.
COMPSCI 102 Introduction to Discrete Mathematics.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
Chapter 7 Analysis of Algorithms © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner
Lecture 5 Today, how to solve recurrences We learned “guess and proved by induction” We also learned “substitution” method Today, we learn the “master.
CSE 373: Data Structures and Algorithms
CES 592 Theory of Software Systems B. Ravikumar (Ravi) Office: 124 Darwin Hall.
1 How to Multiply Slides by Kevin Wayne. Copyright © 2005 Pearson-Addison Wesley. All rights reserved. integers, matrices, and polynomials.
Course Review Fundamental Structures of Computer Science Margaret Reid-Miller 28 April 2005.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis Catie Baker Spring 2015.
CS 3343: Analysis of Algorithms
Chapter 4 Divide-and-Conquer
Great Theoretical Ideas in Computer Science
Algorithm Analysis (not included in any exams!)
Objective of This Course
Data Structures Review Session
Lecture 15, Winter 2019 Closest Pair, Multiplication
David Kauchak cs161 Summer 2009
Divide and Conquer Merge sort and quick sort Binary search
Introduction to Discrete Mathematics
Presentation transcript:

Design & Analysis of Algorithms COMP 482 / ELEC 420 John Greiner

Pragmatics Prerequisites Textbook Wikipedia, … OWL-Space Assignments, late policy, exams 2 [CLRS] 1-2 Policies #0 Start #1 To do:

Solving Interesting Problems 1.Create algorithms & data structures to solve problems. 2.Prove algorithms work. Buggy algorithms are worthless! 3.Examine properties of algorithms. Running time, space needed, simplicity, … 3 Alg. efficiency depends on data structure. Two parts of the same idea.

A Quick Example of Interesting Results Roughly how much time for each? 1.Find shortest path between two points in graph. 2.Find shortest path between each pair of points in graph. 3.Find longest path between two points in graph. 4 ? ? 1.O(V  E) 2.O(V  E) 3.No known polynomial-time algorithm.

Abstract vs. Concrete Data Structures 5 Familiar idea, but… people & algorithm textbooks often don’t distinguish. Abstract: What can it do? I.e., its interface – what operations? Queue: enqueue(elt,Q) dequeue(Q) isEmpty(Q) Concrete: How is it implemented? How efficient? Array-Queue: Elements stored circularly, with first & last indices. Constant-time operations.

Mutability 6 Mutable: Operations can change data structure. enqueue(elt,Q) modifies Q to have new elt. Immutable: Operations can’t change data structure. enqueue(elt,Q) creates & returns Q’ to have new elt. Q unchanged. Most algorithm textbooks & this course: mostly mutable.

Outline of Semester Finish course overview – extended example Math background – review & beyond Algorithms & data structures Really hard problems 7 Techniques, as needed: Randomization Probabilistic analysis Amortized analysis Dynamic programming

Extended Example: Multiplication Illustrates some of course’s interesting ideas. Just an overview – not too much detail yet. How to multiply two integers: x  y. Common & familiar. Simple? Suggested algorithms & their efficiency? 8 ? ?

Multiplication Algorithm 1 Single basic machine operation, O(1) time. 9 Only applies to bounded-sized integers. Instead, explicitly assume unbounded-sized integers. Problem with this answer? ? ?

Multiplication Algorithm 2 x  y = x+…+x = y+…+y 10 y copiesx copies Back to multiplication: O(n  x) = O(n  2 n ) How long for each addition? Grade-school algorithm takes time  result length. For simplicity, assume x,y have same length. Length n = log 2 x (choice of base 2 is arbitrary) O(n)

Multiplication Algorithm 3 Grade-school “long-hand” algorithm. 11 x= 38 y=  Basically the same as bit-shifting algorithms. O(n  n + n  n) = O(n 2 ) Much better! ? ? Total? n multiplications of (x by 1 bit of y) + n additions of the resulting products.

Multiplication Algorithm 4: Part 1 Karatsuba, 1962 Break the bit strings of x,y into halves. x = a  2 n/2 + b = a << n/2 + b y = c  2 n/2 + d = c << n/2 + d xy = ac << n + (ad+bc) << n/2 + bd Compute 4 subproducts recursively. Divide-and-conquer x=45 y=28 a=5 c=3 b=5 d=4 0

Multiplication Algorithm 4: Part 1 How long does this take? Form recurrence equation: Solve recurrence equation. How? Discussed next week. T(n) = O(n 2 ) – No better than previous. 13 k = arbitrary constant to fill in for the details 4 subproducts + additions & shifts

Multiplication Algorithm 4: Part 2 Previous: xy = ac << n + (ad+bc) << n/2 + bd Regroup (very non-obvious step!): u = (a+b)  (c+d) v = ac w = bd xy = v << n + (u-v-w) << n/2 + w Only 3 subproducts! But more additions & shifts x=45 y=28 a=5 c=3 b=5 d=4 0

Multiplication Algorithm 4: Part 2 How long does this take? 15 k’ = a new, larger constant More complicated, but asymptotically faster.

Multiplication Algorithm 4: Part 2 Previous: u = (a+b)  (c+d)v = acw = bd xy = v << n + (u-v-w) << n/2 + w An overlooked detail: a+b and c+d can be n/2+1 bit numbers. Doesn’t fit recurrence. 16 Break sums into (n/2+1) th bit & n bits. Solution: a+b = a 1 << n/2 + b 1 c+d = c 1 << n/2 + d 1 (a+b)  (c+d) = (a 1 c 1 ) << n + (a 1 d 1 + b 1 c 1 ) << n/2 + b 1 d 1 O(1) timeO(n/2) time Single bits.

Multiplication Algorithms 5—8 Toom-Cook, 1963,1966: O(n 1+  ) –Generalizes both long-hand & Karatsuba –Based upon polynomial multiplication & interpolation. FFT-based: Karp: O(n log 2 n) Schoenhage & Strassen, 1971: O(n log n log log n) Fürer, 2007: O(n log n 2 O(log* n) ) 17 Approaching the conjectured Ω(n log n) lower bound. log-shaving – slightly improving logarithmic terms

Multiplication Algorithms 9,... Use parallelism. Even serial processors use some bit-level parallelism. Divide-&-conquer & FFT algorithms easily parallelized. 18

Summary 19 Asymptotically-faster often  more complicated, higher constant factors, & slower for typical input sizes. Good ideas lead to more good ideas Karatsuba generalizes to Strassen’s matrix multiplication [CLRS] 4.2 & Toom-Cook. Toom-Cook & FFT generalize to polynomial multiplication.

Algorithm Analysis Summary 1.State problem. 2.Characterize the input size. 3.State algorithm. –Often difficult, of course 4.Prove algorithm correctness. –Necessary! 5.Determine its resource usage. –Often via recurrence equations –Compare algorithms –Decide which algorithm suitable for given application –Guide the search for better algorithms 20 We almost missed an important detail that would have produced incorrect analysis.