CS161 Design and Analysis of Algorithms. Administrative

Similar documents
Advanced Course of Algorithm Design and Analysis

Algorithm Analysis. Chapter 3

Design and Analysis of ALGORITHM (Topic 2)

CS 270 Algorithms. Oliver Kullmann. Growth of Functions. Divide-and- Conquer Min-Max- Problem. Tutorial. Reading from CLRS for week 2

Analysis of Algorithms. Introduction. Contents

Algorithm Analysis. Algorithms that are equally correct can vary in their utilization of computational resources

Ch3. Asymptotic Notation

Data Structures and Algorithm. Xiaoqing Zheng

CSI 5163 (95.573) ALGORITHM ANALYSIS AND DESIGN

CS583 Lecture 02. Jana Kosecka. some materials here are based on E. Demaine, D. Luebke slides

Sorting Algorithms. Algorithms Kyuseok Shim SoEECS, SNU.

Examples: data compression, path-finding, game-playing, scheduling, bin packing

COMP26120: Introducing Complexity Analysis (2018/19) Lucas Cordeiro

Classification of problem & problem solving strategies. classification of time complexities (linear, logarithmic etc)

Lecture 3: Asymptotic Analysis + Recurrences

CS 332: Algorithms. Linear-Time Sorting. Order statistics. Slide credit: David Luebke (Virginia)

ITEC 360 Data Structures and Analysis of Algorithms Spring for n 1

Design and Analysis of Algorithms

Chapter 22 Developing Efficient Algorithms

Model of Computation and Runtime Analysis

Mathematical Foundation. CSE 6331 Algorithms Steve Lai

Model of Computation and Runtime Analysis

CS:3330 (Prof. Pemmaraju ): Assignment #1 Solutions. (b) For n = 3, we will have 3 men and 3 women with preferences as follows: m 1 : w 3 > w 1 > w 2

4.3 Growth Rates of Solutions to Recurrences

OPTIMAL ALGORITHMS -- SUPPLEMENTAL NOTES

CS161 Handout 05 Summer 2013 July 10, 2013 Mathematical Terms and Identities

CSE 4095/5095 Topics in Big Data Analytics Spring 2017; Homework 1 Solutions

CS / MCS 401 Homework 3 grader solutions

Lecture 9: Hierarchy Theorems

This Lecture. Divide and Conquer. Merge Sort: Algorithm. Merge Sort Algorithm. MergeSort (Example) - 1. MergeSort (Example) - 2

COMP285 Midterm Exam Department of Mathematics

Let us give one more example of MLE. Example 3. The uniform distribution U[0, θ] on the interval [0, θ] has p.d.f.

This is an introductory course in Analysis of Variance and Design of Experiments.

CS 332: Algorithms. Quicksort

Sums, products and sequences

A recurrence equation is just a recursive function definition. It defines a function at one input in terms of its value on smaller inputs.

The Growth of Functions. Theoretical Supplement

Test One (Answer Key)

CSE Introduction to Parallel Processing. Chapter 3. Parallel Algorithm Complexity

2. ALGORITHM ANALYSIS

A Probabilistic Analysis of Quicksort

CIS 121 Data Structures and Algorithms with Java Spring Code Snippets and Recurrences Monday, February 4/Tuesday, February 5

CS166 Handout 02 Spring 2018 April 3, 2018 Mathematical Terms and Identities

Analysis of Algorithms -Quicksort-

Infinite Sequences and Series

Chapter 2. Asymptotic Notation

Design and Analysis of Algorithms

Spectral Partitioning in the Planted Partition Model

Machine Learning Brett Bernstein

Lecture 19: Convergence

SYDE 112, LECTURE 2: Riemann Sums

Merge and Quick Sort

Hand Out: Analysis of Algorithms. September 8, Bud Mishra. In general, there can be several algorithms to solve a problem; and one is faced

Algorithms and Data Structures Lecture IV

CS 171 Lecture Outline October 09, 2008

Hashing and Amortization

WRITTEN ASSIGNMENT 1 ANSWER KEY

w (1) ˆx w (1) x (1) /ρ and w (2) ˆx w (2) x (2) /ρ.

Lecture 2 February 8, 2016

Sequences A sequence of numbers is a function whose domain is the positive integers. We can see that the sequence

Notes for Lecture 11

Machine Learning Theory Tübingen University, WS 2016/2017 Lecture 12

Homework 5 Solutions

Average-Case Analysis of QuickSort

Data Structures Lecture 9

Notes for Lecture 5. 1 Grover Search. 1.1 The Setting. 1.2 Motivation. Lecture 5 (September 26, 2018)

Algorithms. Elementary Sorting. Dong Kyue Kim Hanyang University

CSI 2101 Discrete Structures Winter Homework Assignment #4 (100 points, weight 5%) Due: Thursday, April 5, at 1:00pm (in lecture)

Algorithms 演算法. Multi-threaded Algorithms

Discrete Mathematics for CS Spring 2007 Luca Trevisan Lecture 22

Lecture 11: Pseudorandom functions

1 Review and Overview

CS 253: Algorithms. Syllabus. Chapter 1. Appendix A

1 Hash tables. 1.1 Implementation

Intro to Learning Theory

Lecture 2: Uncomputability and the Haling Problem

Divide and Conquer. 1 Overview. 2 Multiplying Bit Strings. COMPSCI 330: Design and Analysis of Algorithms 1/19/2016 and 1/21/2016

An Introduction to Randomized Algorithms

Some examples of vector spaces

Understanding Samples

MA131 - Analysis 1. Workbook 2 Sequences I

Department of Informatics Prof. Dr. Michael Böhlen Binzmühlestrasse Zurich Phone:

STAT 350 Handout 19 Sampling Distribution, Central Limit Theorem (6.6)

Lecture Note 8 Point Estimators and Point Estimation Methods. MIT Spring 2006 Herman Bennett

A New Method to Order Functions by Asymptotic Growth Rates Charlie Obimbo Dept. of Computing and Information Science University of Guelph

Lecture 5: April 17, 2013

Introduction to Algorithms 6.046J/18.401J LECTURE 3 Divide and conquer Binary search Powering a number Fibonacci numbers Matrix multiplication

Skip Lists. Presentation for use with the textbook, Algorithm Design and Applications, by M. T. Goodrich and R. Tamassia, Wiley, 2015 S 3 S S 1

Lecture 16: Monotone Formula Lower Bounds via Graph Entropy. 2 Monotone Formula Lower Bounds via Graph Entropy

Divide & Conquer. Divide-and-conquer algorithms. Conventional product of polynomials. Conventional product of polynomials.

Matriculation number: You have 90 minutes to complete the exam of InformatikIIb. The following rules apply:

Mechatronics. Time Response & Frequency Response 2 nd -Order Dynamic System 2-Pole, Low-Pass, Active Filter

18.440, March 9, Stirling s formula

Read through these prior to coming to the test and follow them when you take your test.

Randomized Algorithms I, Spring 2018, Department of Computer Science, University of Helsinki Homework 1: Solutions (Discussed January 25, 2018)

6.046 Recitation 5: Binary Search Trees Bill Thies, Fall 2004 Outline

Vector Quantization: a Limiting Case of EM

Simple Random Sampling!

Power and Type II Error

6.3 Testing Series With Positive Terms

Transcription:

CS161 Desig ad Aalysis of Algorithms Da Boeh 1 Admiistrative Lecture 1, April 3, 1 Web page http://theory.staford.edu/~dabo/cs161» Hadouts» Aoucemets» Late breakig ews Gradig ad course requiremets» Midterm/fial/hw» Project» Late HW policy» Importace of readable HW» Collaboratio Probability - Ch. 6., pp 14-115 READ NOW! 1

Why Study Algorithms? (why cs161?) Bag of tricks» Sortig» Data structures: queues/stacks/heaps/trees» Search Methodology - how to desig algorithms» Divide & coquer» Recursive algorithms» Radomized algorithms» Dyamic programmig Useful abstractios.» Schedulig classes graphs.» Job assigmet balls ad boxes. Higher-level way of approachig problems 3 How to compare algorithms? Code ad ru - experimet» Iputs?» Parameters?» Bad implemetatios? Average case» what is average iput?? Worst case» Asymptotics» rough idea o performace» aalytical depedece betwee parameters 4

Example from Ch. Isertio sort: for j = to key = A(j) i=j-1 while i > ad A(i) > key A(i+1) = A(i) A(i) = key i-- ed ed Example: 7 3 5 8 1 3 7 3 5 7 3 5 7 8 1 3 5 7 8 1 3 5 7 8 5 About Pseudo-Code Not really a program, just a outlie Eough details to establish the ruig time ad correctess. No error-hadlig mechaisms. Eve pseudo-code is too complicated! Note that for a trivial algorithms it obscures what is really goig o... The i-place part is a optimizatio. We could start by a simpler descriptio:» Go over the umbers oe-by-oe, startig from the first, copy to ew array.» Each time copy to the correct place i the ew array.» I order to create empty space, shift the umbers that are larger tha the curretly cosidered umber oe cell to the right. 6 3

Aalysis Correctess ad termiatio. Ruig time:» Depeds o iput size» iput properties Wat a upper boud o:» Worst case: max T(), ay iput.» Expected: E[T()], iput take from a distributio. which?? example: sortig arrivig TCP/IP packets they are mostly sorted already.» Best case: Ca be used to argue that the algorithm is really bad. (ay algorithm ca be rewritte to have a excellet best case performace) 7 Back to isertio sort Isertio sort: for j = to key = A(j) i=j-1 while i > ad A(i) > key A(i+1) = A(i) A(i) = key i-- ed ed Simplified algorithm:» Go over the umbers oe-by-oe, startig from the first, copy to ew array.» Each time copy to the correct place i the ew array.» I order to create empty space, shift the umbers that are larger tha the curretly cosidered umber oe cell to the right. -1... Â( t j -1) j= times t j each 8 4

Aalysis Best ruig time: Outer loop always executed, Ier loop - ot executed if iput already sorted. Assume each operatio takes 1 time uit - approximatio. + ( - 1) + ( - 1) + t + ( t - 1) + ( - 1) t j worst case ª j  fi t = j j= Would like to formalize this statemet!  ( + 1) -1 14 43 This domiates!  j j j= j= Do we really eed to pay close attetio to all the idices i the summatios? Maybe some or them are ot really importat?? 9 Formalizatio ( +1) How to formalize that was the mai issue?? The aswer is asymptotic aalysis:» Igore machie-depedet costats.» Look at growth of T() as Ituitio: drop low-order terms eg: 54+ 1-3+ =Θ( 4) Idea: as, Θ( ) becomes better (faster) tha Θ( 4) 1 5

Back to isertio sort aalysis Ier loop was Q(j) T () Θ ( t ) ( ) ( j =Θ tj =Θ ) Is this formal? NO! Example, usig the same logic: Θ (1) +Θ (1) =Θ(1) seems to imply that Θ (1) =Θ(1) Icorrect! i= 1 We eed formalizatio!?? Aother example: log ~ 1/1 11 Asymptotics big-oh otatio: f ( ) = O( g( )) cost c, s.t. : f ( ) cg( ) Example: = O( 6 ) but ot vice versa!! = is ot equality but membership i a set. Set otatio is cumbersome: O( g( )) = { f ( ) cost c, s.t. : f ( ) cg( )} What do we mea by f ( ) = O( ) + h( ) = O( ), f ( ) = h( ) + We are too lazy to specify h() exactly! 1 6

Asymptotics Small-oh otatio: f ( ) = o( g( )) cost c, s.t. : f ( ) < cg( ) Differeces from big-oh Prove that = o( ): Give c, lets take = / c for, c c c ( c ) = > QED g() f() Factor f() g() f=o(g) i both cases! 13 Omega otatio Big-Omega: f ( ) = Ω( g( )) cost c, s.t. : cg( ) f ( ) Small-omega: f ( ) = ω( g( )) cost c, s.t. : cg( ) < f ( ) O: o: < W: : > 14 7

Trasitivity etc. Most rules apply: Example: trasitivity a b, b c a c f = Og ( ), g= Oh () f = Oh () Proof: f = Og ( ) cost c1, 1 s.t. 1 : f() cg 1 () g= Oh () cost c, s.t. : g () ch () Take 3= max( 1, ), c3= cc 1 The: 3: f() cg 1 () cch 1 () = ch 3 () f() = Og ( ( )) QED Not all rules apply! f, g s.t. f O( g) ad g O( f ) example: f =, g = 1 + si 15 Theta otatio Theta: f ( ) = Θ( g( )) cost c, c, s.t. : c g( ) f ( ) c g( ) 1 1 Ofte cofused with Big-Oh otatio! Example: / = Θ( ) Proof: take = 8, the for : / / 4+ 8 / 4 = / 4 O the other had, we have: / < / Thus: / 4 / / i.e. c = 1/ 4, c = 1/. 1 Claim: Low order terms do ot matter. Needs a proof! (HW?) 16 8

Simple Theorem Claim f = O g ad g = O f f = Θ g ( ) ( ( )) ( ) ( ( )) ( ) ( ( )) Proof: 1, c1 s.t. 1: f ( ) c1 g( ), c s.t. : g( ) c f ( ) max( 1, ): 1 c g ( ) f ( ) c 1 g ( ) QED 17 Summary Remember the defiitios. Formally prove from defiitios. Use ituitio from the properties of,, etc. 18 9