The Beauty and Joy of Computing Lecture #7 Algorithms II minors-delete-activity/story?id=20361045/

Slides:



Advertisements
Similar presentations
Intro to Analysis of Algorithms. Algorithm “A sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any.
Advertisements

The Theory of NP-Completeness
1 NP-Complete Problems. 2 We discuss some hard problems:  how hard? (computational complexity)  what makes them hard?  any solutions? Definitions 
CS10 The Beauty and Joy of Computing Lecture #7 Algorithmic Complexity One million Wi-Fi devices isn’t cool. You know what’s cool? A Billion.
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Tyler Robison Summer
CSE332: Data Abstractions Lecture 2: Math Review; Algorithm Analysis Dan Grossman Spring 2010.
CSE332: Data Abstractions Lecture 27: A Few Words on NP Dan Grossman Spring 2010.
CS 206 Introduction to Computer Science II 09 / 10 / 2008 Instructor: Michael Eckmann.
Introduction to Analysis of Algorithms
1 CSE1301 Computer Programming Lecture 31: List Processing (Search)
Analysis of Algorithms CS 477/677
1 Algorithm Efficiency, Big O Notation, and Role of Data Structures/ADTs Algorithm Efficiency Big O Notation Role of Data Structures Abstract Data Types.
Algorithm Analysis CS 201 Fundamental Structures of Computer Science.
1 Discrete Mathematics Summer 2004 By Dan Barrish-Flood originally for Fundamental Algorithms For use by Harper Langston in D.M.
CS10 The Beauty and Joy of Computing Lecture #23 : Limits of Computing Thanks to the success of the Kinect, researchers all over the world believe.
Analysis of Algorithm.
Elementary Data Structures and Algorithms
CS107 Introduction to Computer Science Lecture 7, 8 An Introduction to Algorithms: Efficiency of algorithms.
Analysis of Algorithms COMP171 Fall Analysis of Algorithms / Slide 2 Introduction * What is Algorithm? n a clearly specified set of simple instructions.
CS10: The Beauty and Joy of Computing Lecture #7: Algorithm Complexity TA Jon Kotker ( ) LEDs + Math = Art Leo Villareal combines modern LED control.
The Beauty and Joy of Computing Lecture #6 Algorithms Alan Turing ( ) would have turned 100 this year. He was a brilliant British mathematician.
Abstract Data Types (ADTs) Data Structures The Java Collections API
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
HOW TO SOLVE IT? Algorithms. An Algorithm An algorithm is any well-defined (computational) procedure that takes some value, or set of values, as input.
1 Complexity Lecture Ref. Handout p
Week 2 CS 361: Advanced Data Structures and Algorithms
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved ADT Implementation:
CSC 201 Analysis and Design of Algorithms Lecture 04: CSC 201 Analysis and Design of Algorithms Lecture 04: Time complexity analysis in form of Big-Oh.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
Tonga Institute of Higher Education Design and Analysis of Algorithms IT 254 Lecture 8: Complexity Theory.
Chapter 12 Recursion, Complexity, and Searching and Sorting
Analysis of Algorithms
Algorithm Analysis PS5 due 11:59pm Wednesday, April 18 Final Project Phase 2 (Program Outline) due 1:30pm Tuesday, April 24 Wellesley College CS230.
Searching. RHS – SOC 2 Searching A magic trick: –Let a person secretly choose a random number between 1 and 1000 –Announce that you can guess the number.
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
Analysis of Algorithms These slides are a modified version of the slides used by Prof. Eltabakh in his offering of CS2223 in D term 2013.
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
CSC 413/513: Intro to Algorithms NP Completeness.
Algorithm Analysis (Algorithm Complexity). Correctness is Not Enough It isn’t sufficient that our algorithms perform the required tasks. We want them.
The Beauty and Joy of Computing Lecture #6 Algorithms MIT researchers recently created an algorithm which they say will be able to predict what topics.
Cliff Shaffer Computer Science Computational Complexity.
1 The Theory of NP-Completeness 2 Cook ’ s Theorem (1971) Prof. Cook Toronto U. Receiving Turing Award (1982) Discussing difficult problems: worst case.
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
NP-COMPLETE PROBLEMS. Admin  Two more assignments…  No office hours on tomorrow.
3.3 Complexity of Algorithms
Time Complexity of Algorithms (Asymptotic Notations)
Beauty and Joy of Computing Limits of Computing Ivona Bezáková CS10: UC Berkeley, April 14, 2014 (Slides inspired by Dan Garcia’s slides.)
The Beauty and Joy of Computing Lecture #6 Algorithms I UC Berkeley EECS Sr Lecturer SOE Dan Garcia.
CS10: The Beauty and Joy of Computing Lecture #22 Limits of Computing Warning sign posted at Stern Hall. Also, Apple releases new operating.
1/6/20161 CS 3343: Analysis of Algorithms Lecture 2: Asymptotic Notations.
CS6045: Advanced Algorithms NP Completeness. NP-Completeness Some problems are intractable: as they grow large, we are unable to solve them in reasonable.
The Beauty and Joy of Computing Lecture #23 Limits of Computing Researchers at Facebook and the University of Milan found that the avg # of “friends” separating.
27-Jan-16 Analysis of Algorithms. 2 Time and space To analyze an algorithm means: developing a formula for predicting how fast an algorithm is, based.
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
The Beauty and Joy of Computing Lecture #7 Algorithmic Complexity “Data scientists at Yahoo are using prediction markets – along with polls, sentiment.
UC Berkeley EECS Sr Lecturer SOE Dan Garcia printing-aims-to-prevent-a-piracy-plague/ Quest.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
UC Berkeley EECS Lecturer SOE Dan Garcia The success of Apple’s Siri (only available on the iPhone 4S) has sparked competition, to be sure. Google’s IRIS.
CS10 The Beauty and Joy of Computing Lecture #4 : Functions UC Berkeley EECS Lecturer SOE Dan Garcia Researchers at Microsoft and UW are working.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
UC Berkeley EECS Sr Lecturer SOE Dan Garcia Valve (video game makers of Half-Life) believes the future of video games may not be in the input device (ala.
Yahoo predicts contest already!
COMP108 Algorithmic Foundations Algorithm efficiency
Introduction to complexity
Introduction to Algorithms
David Kauchak CS52 – Spring 2015
Algorithmic Complexity CSE 120 Winter 2018
Algorithm design and Analysis
CS 201 Fundamental Structures of Computer Science
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
Presentation transcript:

The Beauty and Joy of Computing Lecture #7 Algorithms II minors-delete-activity/story?id= / California Law Says All Websites Must Give Minors Option To Delete User Activity Good: More privacy! Bad: How exactly do you delete content from the Internet? UC Berkeley EECS Sr Lecturer SOE Dan Garcia

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (2) Garcia  A block, or function has inputs & outputs  Possibly no inputs  Possibly no outputs (if block is a command)  In this case, it would have a “side effect”, i.e., what it does (e.g., move a robot)  The contract describing what that block does is called a specification or spec Functional Abstraction (review) F x F(x)

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (3) Garcia  Typically they all have  NAME  INPUT(s)  (and types, if appropriate)  Requirements  OUTPUT  Can write “none”  (SIDE-EFFECTS)  EXAMPLE CALLS  Example  NAME : Double  INPUT : n (a number)  OUTPUT: n + n What is IN a spec? (review) Double n Double( n)

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (4) Garcia  How!  That’s the beauty of a functional abstraction; it doesn’t say how it will do its job.  Example: Double  Could be n * 2  Could be n + n  Could be n+1 (n times)  if n is a positive integer  This gives great freedom to author!  You choose Algorithm(s)! What is NOT in a spec?

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (5) Garcia What do YOU think? Which factor below is the most important in choosing the algorithm to use? A. Simplest? B. Easiest to implement? C. Takes less time? D. Uses up less space (memory)? E. Gives a more precise answer? U C B e rk el e y C S 1 0 " T h e B e a ut y a n d J o y of C o m p ut in g " : A lg o rit h m C o m pl e xi ty 5

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (6) Garcia  An algorithm is correct if, for every input, it reports the correct output and doesn’t run forever or cause an error.  Incorrect algorithms may run forever, or may crash, or may not return the correct answer.  They could still be useful!  Consider an approximation…  For now, we’ll only consider correct algorithms Algorithm analysis : the basics Algorithm for managing Vitamin D sterols based on serum calcium levels.

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (7) Garcia How do you know if “it” is correct? - Mathematical proof for algorithms - Empirical verification through testing of programs: - Unit Testing - Debugging

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (8) Garcia  This book launched a generation of CS students into Algorithm Analysis  It’s on everyone’s shelf  It might be hard to grok at this point, but if you go on in CS, remember it & own it!  …but get the most recent vears Reference text

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (9) Garcia  One commonly used criterion in making a decision is running time  how long does the algorithm take to run and finish its task?  How do we measure it? Algorithm analysis : running time U C B e rk el e y C S 1 0 " T h e B e a ut y a n d J o y of C o m p ut in g " : A lg o rit h m C o m pl e xi ty 9 08:23:12

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (10) Garcia  Time w/stopwatch, but…  Different computers may have different runtimes.   Same computer may have different runtime on the same input.   Need to implement the algorithm first to run it.   Solution: Count the number of “steps” involved, not time!  Each operation = 1 step  If we say “running time”, we’ll mean # of steps, not time! Runtime analysis problem & solution U C B e rk el e y C S 1 0 " T h e B e a ut y a n d J o y of C o m p ut in g " : A lg o rit h m C o m pl e xi ty10

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (11) Garcia  Definition  Input size: the # of things in the input.  E.g., # of things in a list  Running time as a function of input size  Measures efficiency  Important!  In CS10 we won’t care about the efficiency of your solutions!  …in CS61B we will CS10CS61ACS61BCS61C Runtime analysis : input size & efficiency U C B e rk el e y C S 1 0 " T h e B e a ut y a n d J o y of C o m p ut in g " : A lg o rit h m C o m pl e xi ty11

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (12) Garcia  Could use avg case  Average running time over a vast # of inputs  Instead: use worst case  Consider running time as input grows  Why?  Nice to know most time we’d ever spend  Worst case happens often  Avg is often ~ worst Runtime analysis : worst or avg case? U C B e rk el e y C S 1 0 " T h e B e a ut y a n d J o y of C o m p ut in g " : A lg o rit h m C o m pl e xi ty12

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (13) Garcia  Instead of an exact number of operations we’ll use abstraction  Want order of growth, or dominant term  In CS10 we’ll consider  Constant  Logarithmic  Linear  Quadratic  Cubic  Exponential  E.g. 10 n log n + n  …is quadratic Runtime analysis: Final abstraction Graph of order of growth curves on log-log plot Constant Logarithmic Linear QuadraticCubicExponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (14) Garcia  Input  Unsorted list of students L  Particular student S  Output  True if S is in L, else False  Pseudocode Algorithm  Go through one by one, checking for match.  If match, true  If exhausted L and didn’t find S, false Example: Finding a student (by ID)  Worst-case running time as function of the size of L? 1. Constant 2. Logarithmic 3. Linear 4. Quadratic 5. Exponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (15) Garcia  Input  Sorted list of students L  Particular student S  Output : same  Pseudocode Algorithm  Start in middle  If match, report true  If exhausted, throw away half of L and check again in the middle of remaining part of L  If nobody left, report false Example: Finding a student (by ID)  Worst-case running time as function of the size of L? 1. Constant 2. Logarithmic 3. Linear 4. Quadratic 5. Exponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (16) Garcia  What if L were given to you in advance and you had infinite storage?  Could you do any better than logarithmic? Example: Finding a student (by ID)  Worst-case running time as function of the size of L? 1. Constant 2. Logarithmic 3. Linear 4. Quadratic 5. Exponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (17) Garcia  Input  Unsorted list L (of size n) of birthdays of team  Output  True if any two people shared birthday, else False  What’s the worst-case running time? Example: Finding a shared birthday  Worst-case running time as function of the size of L? 1. Constant 2. Logarithmic 3. Linear 4. Quadratic 5. Exponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (18) Garcia  Input:  Unsorted list L (of size n) of people  Output  All the subsets  Worst-case running time? (as function of n)  E.g., for 3 people (a,b,c):  1 empty: { }  3 1-person: {a, b, c}  3 2-person: {ab, bc, ac}  1 3-person: {abc} Example: Finding subsets  Worst-case running time as function of the size of L? 1. Constant 2. Logarithmic 3. Linear 4. Quadratic 5. Exponential

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (19) Garcia  We can prove mathematically that some algorithms are never solveable!  We can (almost) prove mathematically that some algorithms will never be efficient!  Famous problem P = NP ?  Example: Travelling Salesman Problem  BUT: Can use heuristics for approximation Limits

UC Berkeley “The Beauty and Joy of Computing” : Algorithms II (20) Garcia  When developing an algorithm, could optimize for  Simplest  Easiest to implement?  Most efficient  Uses up least resources  Gives most precision  …  In CS10 we’ll consider  Constant  Logarithmic  Linear  Quadratic  Cubic  Exponential Summary  There are empirical and formal methods to verify efficienct and correctness  Some algorithms cannot be implemtented efficiently