1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 5 Instructor: Paul Beame TA: Gidon Shavit.

Slides:



Advertisements
Similar presentations
A simple example finding the maximum of a set S of n numbers.
Advertisements

Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
CSE 373: Data Structures and Algorithms Lecture 5: Math Review/Asymptotic Analysis III 1.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 4 Instructor: Paul Beame TA: Gidon Shavit.
Divide-and-Conquer The most-well known algorithm design strategy:
Divide and Conquer Strategy
Algorithm Design Paradigms
Lecture 4: Divide-and-Conquer. Steps in Divide and Conquer As its name implies divide-and-conquer involves dividing a problem into smaller problems that.
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.
CS4413 Divide-and-Conquer
Chapter 4: Divide and Conquer Master Theorem, Mergesort, Quicksort, Binary Search, Binary Trees The Design and Analysis of Algorithms.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Chapter 4 Divide-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
CS38 Introduction to Algorithms Lecture 7 April 22, 2014.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 4 Some of the sides are exported from different sources.
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Algorithm Design Strategy Divide and Conquer. More examples of Divide and Conquer  Review of Divide & Conquer Concept  More examples  Finding closest.
Chapter 4 Divide-and-Conquer Copyright © 2007 Pearson Addison-Wesley. All rights reserved.
Functional Design and Programming Lecture 4: Sorting.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Instructor: Paul Beame TA: Gidon Shavit.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Instructor: Paul Beame TA: Gidon Shavit.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 6 Instructor: Paul Beame TA: Gidon Shavit.
Chapter 7 (Part 2) Sorting Algorithms Merge Sort.
Design and Analysis of Algorithms – Chapter 51 Divide and Conquer (I) Dr. Ying Lu RAIK 283: Data Structures & Algorithms.
1 CSE 417: Algorithms and Computational Complexity Winter 2001 Instructor: Paul Beame TA: Gidon Shavit.
Design and Analysis of Algorithms - Chapter 41 Divide and Conquer The most well known algorithm design strategy: 1. Divide instance of problem into two.
Computer Algorithms Lecture 10 Quicksort Ch. 7 Some of these slides are courtesy of D. Plaisted et al, UNC and M. Nicolescu, UNR.
Divide-and-Conquer 7 2  9 4   2   4   7
Copyright © 2007 Pearson Addison-Wesley. All rights reserved. A. Levitin “ Introduction to the Design & Analysis of Algorithms, ” 2 nd ed., Ch. 1 Chapter.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3rd ed., Ch. 5 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 3 Prof. Erik Demaine.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
CMPT 438 Algorithms. Why Study Algorithms? Necessary in any computer programming problem ▫Improve algorithm efficiency: run faster, process more data,
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.
Lecture 28 CSE 331 Nov 9, Mini project report due WED.
Divide and Conquer Andreas Klappenecker [based on slides by Prof. Welch]
Divide and Conquer Strategy
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
Chapter 4, Part II Sorting Algorithms. 2 Heap Details A heap is a tree structure where for each subtree the value stored at the root is larger than all.
Introduction to Algorithms: Divide-n-Conquer Algorithms
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Chapter 4 Divide-and-Conquer
Divide-and-Conquer 6/30/2018 9:16 AM
Lecture 4 Divide-and-Conquer
Chapter 4 Divide-and-Conquer
Divide-and-Conquer The most-well known algorithm design strategy:
CSCE 411 Design and Analysis of Algorithms
Divide and Conquer / Closest Pair of Points Yin Tat Lee
Divide-and-Conquer 7 2  9 4   2   4   7
Topic: Divide and Conquer
Lecture 27 CSE 331 Nov 3, 2017.
CSE 373 Data Structures and Algorithms
Divide-and-Conquer The most-well known algorithm design strategy:
Chapter 4 Divide-and-Conquer
Divide and Conquer Algorithms Part I
Divide-and-Conquer The most-well known algorithm design strategy:
Divide-and-Conquer 7 2  9 4   2   4   7
CSC 380: Design and Analysis of Algorithms
CSC 380: Design and Analysis of Algorithms
Lecture 30 CSE 331 Nov 12, 2012.
Lecture 15, Winter 2019 Closest Pair, Multiplication
Algorithms Recurrences.
Topic: Divide and Conquer
Divide-and-Conquer 7 2  9 4   2   4   7
Lecture 27 CSE 331 Nov 4, 2016.
Divide and Conquer Merge sort and quick sort Binary search
Presentation transcript:

1 CSE 417: Algorithms and Computational Complexity Winter 2001 Lecture 5 Instructor: Paul Beame TA: Gidon Shavit

2 Fixing a Misunderstanding  We have looked at  type of complexity analysis  worst-case, best-case, average-case  types of function bounds  O, ,   These two considerations are orthogonal to each other  one can do any type of function bound with any type of complexity analysis

3 Complexity analysis overview Alg A different running time for each input string Type of Complexity Analysis Function mapping input length to running time Type of Bound T(n) grows like nlog 2 n Nice formula approximating runtime of A Usually we represent the function in the middle using a recurrence relation rather than explicitly

4 Quicksort Analysis  Partition does n-1 comparisons on a list of length n  pivot is compared to each other element  If pivot is i th largest then two subproblems are of size i-1 and n-i  Pivot is equally likely to be any one of 1 st through n th largest

5 Quicksort analysis

6

7 Algorithm Design Techniques  General overall idea  Reduce solving a problem to a smaller problem or problems of the same type  Greedy algorithms  Used when one needs to build something a piece at a time  Repeatedly make the greedy choice - the one that looks the best right away e.g. closest pair in TSP search  Usually fast if they work

8 Algorithm Design Techniques  Divide & Conquer  Reduce problem to one or more sub-problems of the same type  Each sub-problem is at most a constant fraction of the size of the original problem  e.g. Mergesort, Binary Search, Strassen’s Algorithm, Quicksort (kind of)

9 Fast exponentiation  Power(a,n)  Input: integer n and number a  Output: a n  Obvious algorithm  n-1 multiplications  Observation:  if n is even, n=2m, then a n =a m  a m

10 Divide & Conquer Algorithm  Power(a,n) if n=0 then return(1) else x  Power(a,  n/2  ) if n is even then return(x  x) else return(a  x  x)

11 Analysis  Worst-case recurrence  T(n)=T(  n/2  )+2  By master theorem  T(n)=O(log n)  More precise analysis:  T(n)=  log 2 n  + # of 1’s in n’s binary representation

12 A Practical Application- RSA  Instead of a n want a n mod N  a i+j mod N = ((a i mod N)  (a j mod N)) mod N  same algorithm applies with each x  y replaced by  ((x mod N)  (y mod N)) mod N  In RSA cryptosystem (widely used for security)  need a n mod N where a, n, N each typically have 1024 bits  Power: at most 2048 multiplies of 1024 bit numbers  relatively easy for modern machines  Naive algorithm: multiplies

13 Binary search for roots (bisection method)  Given:  continuous function f and two points a 0  Find:  approximation to c s.t. f(c)=0 and a<c<b