CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 25 There.

Slides:



Advertisements
Similar presentations
Models of Computation Prepared by John Reif, Ph.D. Distinguished Professor of Computer Science Duke University Analysis of Algorithms Week 1, Lecture 2.
Advertisements

Register Allocation COS 320 David Walker (with thanks to Andrew Myers for many of these slides)
P3 / 2004 Register Allocation. Kostis Sagonas 2 Spring 2004 Outline What is register allocation Webs Interference Graphs Graph coloring Spilling Live-Range.
Register Allocation CS 320 David Walker (with thanks to Andrew Myers for most of the content of these slides)
Michael Alves, Patrick Dugan, Robert Daniels, Carlos Vicuna
1 Overview Assignment 5: hints  Garbage collection Assignment 4: solution.
CSCI 3160 Design and Analysis of Algorithms Tutorial 4
Register Allocation CS 671 March 27, CS 671 – Spring Register Allocation - Motivation Consider adding two numbers together: Advantages: Fewer.
Order Statistics Sorted
Algorithms Analysis Lecture 6 Quicksort. Quick Sort Divide and Conquer.
Lecture 10: Heap Management CS 540 GMU Spring 2009.
Fall 2010 UVa David Evans cs2220: Engineering Software Class 24: Garbage Collection flickr cc: kiksbalayon.
“Devo verificare un’equivalenza polinomiale…Che fò? Fò dù conti” (Prof. G. Di Battista)
CS420 lecture one Problems, algorithms, decidability, tractability.
Randomized Algorithms Randomized Algorithms CS648 Lecture 1 1.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 7: Greedy Algorithms
Randomized Algorithms Kyomin Jung KAIST Applied Algorithm Lab Jan 12, WSAC
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 21: Garbage Collection.
CSL758 Instructors: Naveen Garg Kavitha Telikepalli Scribe: Manish Singh Vaibhav Rastogi February 7 & 11, 2008.
WS Algorithmentheorie 03 – Randomized Algorithms (Overview and randomised Quicksort) Prof. Dr. Th. Ottmann.
1 Lecture 8: Genetic Algorithms Contents : Miming nature The steps of the algorithm –Coosing parents –Reproduction –Mutation Deeper in GA –Stochastic Universal.
1 Algorithms for Large Data Sets Ziv Bar-Yossef Lecture 8 May 4, 2005
Efficiency of Algorithms
Recent Development on Elimination Ordering Group 1.
MAE 552 – Heuristic Optimization Lecture 27 April 3, 2002
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Lecture 4 Sept 4 Goals: chapter 1 (completion) 1-d array examples Selection sorting Insertion sorting Max subsequence sum Algorithm analysis (Chapter 2)
Study Group Randomized Algorithms Jun 7, 2003 Jun 14, 2003.
Randomized Algorithms Morteza ZadiMoghaddam Amin Sayedi.
Approximating the MST Weight in Sublinear Time Bernard Chazelle (Princeton) Ronitt Rubinfeld (NEC) Luca Trevisan (U.C. Berkeley)
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
EECS 203: It’s the end of the class and I feel fine. Graphs.
The Best Algorithms are Randomized Algorithms N. Harvey C&O Dept TexPoint fonts used in EMF. Read the TexPoint manual before you delete this box.: A AAAA.
1 Chapter 1 Analysis Basics. 2 Chapter Outline What is analysis? What to count and consider Mathematical background Rates of growth Tournament method.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 2: Orders of Growth
Randomized Turing Machines
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
Some Uses of Probability Randomized algorithms –for CS in general –for games and robotics in particular Testing Simulation Solving probabilistic problems.
Télécom 2A – Algo Complexity (1) Time Complexity and the divide and conquer strategy Or : how to measure algorithm run-time And : design efficient algorithms.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 4: Dynamic Programming, Trees
Computation Model and Complexity Class. 2 An algorithmic process that uses the result of a random draw to make an approximated decision has the ability.
More Computational Complexity Shirley Moore CS4390/5390 Fall August 29,
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 17: Garbage Collection.
CSE332: Data Abstractions Lecture 24.5: Interlude on Intractability Dan Grossman Spring 2012.
PROBABILISTIC COMPUTATION By Remanth Dabbati. INDEX  Probabilistic Turing Machine  Probabilistic Complexity Classes  Probabilistic Algorithms.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 23: Review.
Announcements Project 4: Ghostbusters Homework 7
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 3: Levels of Abstraction
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 21: Calling.
Ensemble Methods in Machine Learning
ICS 353: Design and Analysis of Algorithms
CS 127 Exceptions and Decision Structures. Exception Handling This concept was created to allow a programmer to write code that catches and deals with.
Lossless Decomposition and Huffman Codes Sophia Soohoo CS 157B.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 8: Crash Course in Computational Complexity.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 12: Automating Memory Management
Theory of Computational Complexity Probability and Computing Ryosuke Sasanuma Iwama and Ito lab M1.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Approximating the MST Weight in Sublinear Time
Randomized Algorithm (Lecture 2: Randomized Min_Cut)
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
December 1st – Graph Madness
CS216: Program and Data Representation
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Randomized Algorithms CS648
Advanced Analysis of Algorithms
Class 24: Garbage Collection
David Kauchak CS158 – Spring 2019
Time Complexity and the divide and conquer strategy
Presentation transcript:

CS216: Program and Data Representation University of Virginia Computer Science Spring 2006 David Evans Lecture 25 There will be no more scheduled Small Hall hours or Sections next week. I will have my regular office hours Today (2), Thursday (1:30), and Friday (10:30).

2 UVa CS216 Spring Lecture 25: Randomized Algorithms Question 10 FirstTop 3 Improved Tree Data Structures 113 Partner Assignment Algorithms 114 Graph and Network Algorithms 1237 Randomized Algorithms 938.NET’s VM 524 Instruction set 218 Review 5464 We will discuss some Exam 2 questions today. We might do a review Monday, but only if enough good questions are sent by Sunday afternoon.

3 UVa CS216 Spring Lecture 25: Randomized Algorithms Question 10 FirstTop 3 Improved Tree Data Structures 113 Partner Assignment Algorithms 114 Graph and Network Algorithms 1237 Randomized Algorithms 938.NET’s VM 524 Instruction set 218 Review 5464 Close vote here…luckily there are many interesting randomized graph and network algorithms…

4 UVa CS216 Spring Lecture 25: Randomized Algorithms Exam 2: Question 2 In Class 16, we saw that the floating point imprecision in representing 0.1 led to an error of seconds per hour in the Patriot missile time calculations. What clock tick unit would maximize the error accumulated per hour? What is the error? This was the easiest question, but no one got it right!

5 UVa CS216 Spring Lecture 25: Randomized Algorithms Question 2 What is the smallest value the 24-bit mantissa register can represent? … What if the clock tick is < seconds? Option 1: 0…01 = 2-24 (error > per tick) Option 2: 0…00 = 0 (error = tick length per tick) So, error per hour is 1 hour!

6 UVa CS216 Spring Lecture 25: Randomized Algorithms Is this possible? Modern Penium ~ 4GHz –Clock tick = 1/4B s = 1/2 32 –2 7 times faster than we need!

7 UVa CS216 Spring Lecture 25: Randomized Algorithms Question 4 Explain two reasons why it is easier to write a garbage collector for Python than it is to write a garbage collector for C?

8 UVa CS216 Spring Lecture 25: Randomized Algorithms Mark and Sweep Stack Bottom of Stack “Duck” “CATAG” root: Species name: genome: String[]: args ss: SpeciesSet “in.spc” els: Garbage Collection Top of Stack active = all objects on stack while (!active.isEmpty ()) newactive = { } foreach (Object a in active) mark a as reachable (non-garbage) foreach (Object o that a points to) if o is not marked newactive = newactive U { o } active = newactive Class 12

9 UVa CS216 Spring Lecture 25: Randomized Algorithms Question 9 Consider modifying the x86 calling convention to put the return value on the top of the stack when a routine returns instead of using EAX to hold the return value. What are the advantages and disadvantages of this change?

10 UVa CS216 Spring Lecture 25: Randomized Algorithms Where could it go? parameter 3 parameter 2 parameter 1 return address Stack Growth ESP C calling convention: state before ret

11 UVa CS216 Spring Lecture 25: Randomized Algorithms Where could it go? parameter 3 parameter 2 parameter 1 return address Stack Growth ESP Modified calling convention: state before ret result Yikes! ret expects [esp] to be return address

12 UVa CS216 Spring Lecture 25: Randomized Algorithms Puts it before RA parameter 1 return address Stack Growth ESP Implications: Caller: must reserve enough space on stack to hold results result

13 UVa CS216 Spring Lecture 25: Randomized Algorithms Is this a good idea? Advantages: –Frees up EAX for other things –Allows longer return values Multiple results (Python) Return arrays, structures Disadvantages: –Stack access can be a lot slower than registers –If caller uses result, it probably needs to copy it into a register anyway

14 UVa CS216 Spring Lecture 25: Randomized Algorithms Sample Programs … x = f(a); y = g(b); z = f(x + y); … x = f (g (h (a))) … Which code fragment could be faster with the new convention?

15 UVa CS216 Spring Lecture 25: Randomized Algorithms Randomized Algorithms

16 UVa CS216 Spring Lecture 25: Randomized Algorithms Why use randomness? Avoid worst-case behavior: randomness can (probabilistically) guarantee average case behavior Efficient approximate solutions to intractable problems

17 UVa CS216 Spring Lecture 25: Randomized Algorithms Randomized Algorithm Deterministic Computer Input Output Random bits (doesn’t use lava lamps anymore)

18 UVa CS216 Spring Lecture 25: Randomized Algorithms Types of Algorithms Monte Carlo –Running time bounded by input size, but answer may be wrong –Decision problems: If there is no solution, always returns “no”. If there is a solution, finds it with some probability >= ½. –Value problems: run for a bounded number of steps, produce an answer that is correct approximation with a bounded probability (function of number of steps)

19 UVa CS216 Spring Lecture 25: Randomized Algorithms Types of Random Algorithms Las Vegas –Guaranteed to produce correct answer, but running time is probabilistic Atlantic City –Running time bounded by input –Can return either “yes” or “no” regardless of correct answer. Correct with probability >= 2/3. How could this be useful?

20 UVa CS216 Spring Lecture 25: Randomized Algorithms Determining  0,1 1,1 1,00,0 Square = 1 Circle = /4 The probability a random point in square is in circle: = /4  = 4 * points in circle/points

21 UVa CS216 Spring Lecture 25: Randomized Algorithms Find  def findPi (points): incircle = 0 for i in range (points): x = random.random () y = random.random () if (square (x - 0.5) + square (y - 0.5) \ < 0.25): # 0.25 = r^2 incircle = incircle + 1 return 4.0 * incircle / points

22 UVa CS216 Spring Lecture 25: Randomized Algorithms Monte Carlo or Las Vegas?

23 UVa CS216 Spring Lecture 25: Randomized Algorithms Results n: n: n: n: n: n: n: n: If we wait long enough will it produce an arbitrarily accurate value?

24 UVa CS216 Spring Lecture 25: Randomized Algorithms Minimum Cut Problem Input: an undirected, connected multigraph G = (V,E) Output: A cut ( V 1,V 2 where V 1∩  V 2 = V and V 1  V 2 = ) such that number of edges between V 1 and V 2 is the fewest possible. Why might this be useful? Equivalent: fewest edges that can be removed to disconnect G.

25 UVa CS216 Spring Lecture 25: Randomized Algorithms Minimum Cut A B C D Size of the min cut must be no larger than the smallest node degree in graph

26 UVa CS216 Spring Lecture 25: Randomized Algorithms Internet Minimum Cut June 1999 Internet graph, Bill Cheswick

27 UVa CS216 Spring Lecture 25: Randomized Algorithms Randomized Algorithm While |V| > 2: –Pick a random edge (x, y) from E –Contract the edge: Keep multi-edges, remove self-loops Combine nodes The two remaining nodes represent reasonable choices for the minimum cut sets

28 UVa CS216 Spring Lecture 25: Randomized Algorithms Analysis Suppose C is a minimum cut (set of edges that disconnects G ) When we contract edge e : –Unlikely that e  C –So, C is likely to be preserved What is the probability a randomly choosen edge is in C ?

29 UVa CS216 Spring Lecture 25: Randomized Algorithms Analysis Is the final result a cut of G? What is the probability we find a minimum cut?

30 UVa CS216 Spring Lecture 25: Randomized Algorithms Random Edge in C ? | C | must be  degree of every node in G How many edges in G: | E | = sum of all node degrees / 2  n |C| / 2 Probability a random edge is in C  2/n

31 UVa CS216 Spring Lecture 25: Randomized Algorithms Iteration How many iterations? Probability for first iteration: Prob(e 1  C)  1 – 2/n Probability for second iteration: Prob(e 2  C | e 1  C)  1 – 2/(n-1)... Probability for last iteration: Prob(e n-2  C)  1 – 2/(n-(n-2-1))  1 – 2/3 n - 2

32 UVa CS216 Spring Lecture 25: Randomized Algorithms Probability of finding C?  (1 – 2/n) * (1 – 2/(n – 1)) * (1 – 2/(n – 2))... * (1 – 2/3) = (n – 2 / n) * (n – 3/(n – 1)) * (n – 4/(n – 2)) *...* (2/4) * (1/3) = 2 / (n * (n – 1)) Probability of not finding C = 1 – 2/(n*(n-1))

33 UVa CS216 Spring Lecture 25: Randomized Algorithms Is this good enough? Probability of not finding C on one trial:  1 – 2/(n*(n-1))  1 – 2/n 2 Probability of not finding C on k trials:  [1 – 2/n 2 ] k If k = cn 2, Prob failure  (1/e) c Recall: lim (1 – 1/x) x = 1/e x  

34 UVa CS216 Spring Lecture 25: Randomized Algorithms Charge Monday is last class: it will be mostly review if enough good review questions are sent in No section or Small Hall hours next week