Randomized Algorithms Introduction Rom Aschner & Michal Shemesh.

Slides:



Advertisements
Similar presentations
©2001 by Charles E. Leiserson Introduction to AlgorithmsDay 9 L6.1 Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 6 Prof. Erik Demaine.
Advertisements

Comp 122, Spring 2004 Order Statistics. order - 2 Lin / Devi Comp 122 Order Statistic i th order statistic: i th smallest element of a set of n elements.
Order Statistics Sorted
Theory of Computing Lecture 3 MAS 714 Hartmut Klauck.
1 More Sorting; Searching Dan Barrish-Flood. 2 Bucket Sort Put keys into n buckets, then sort each bucket, then concatenate. If keys are uniformly distributed.
“Devo verificare un’equivalenza polinomiale…Che fò? Fò dù conti” (Prof. G. Di Battista)
Lecture 3: Randomized Algorithm and Divide and Conquer II: Shang-Hua Teng.
1 Today’s Material Medians & Order Statistics – Ch. 9.
Randomized Algorithms Kyomin Jung KAIST Applied Algorithm Lab Jan 12, WSAC
CSC-2259 Discrete Structures
Randomized Algorithms Randomized Algorithms CS648 Lecture 6 Reviewing the last 3 lectures Application of Fingerprinting Techniques 1-dimensional Pattern.
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different approaches –Probabilistic analysis of a deterministic algorithm –Randomized.
CSL758 Instructors: Naveen Garg Kavitha Telikepalli Scribe: Manish Singh Vaibhav Rastogi February 7 & 11, 2008.
Median/Order Statistics Algorithms
WS Algorithmentheorie 03 – Randomized Algorithms (Overview and randomised Quicksort) Prof. Dr. Th. Ottmann.
1 Sorting Problem: Given a sequence of elements, find a permutation such that the resulting sequence is sorted in some order. We have already seen: –Insertion.
1 Introduction to Randomized Algorithms Md. Aashikur Rahman Azim.
Probability theory 2010 Order statistics  Distribution of order variables (and extremes)  Joint distribution of order variables (and extremes)
Probabilistic (Average-Case) Analysis and Randomized Algorithms Two different but similar analyses –Probabilistic analysis of a deterministic algorithm.
Data Structures, Spring 2006 © L. Joskowicz 1 Data Structures – LECTURE 4 Comparison-based sorting Why sorting? Formal analysis of Quick-Sort Comparison.
Tirgul 4 Sorting: – Quicksort – Average vs. Randomized – Bucket Sort Heaps – Overview – Heapify – Build-Heap.
Chapter 4: Divide and Conquer The Design and Analysis of Algorithms.
Prune-and-search Strategy
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Quicksort!. A practical sorting algorithm Quicksort  Very efficient Tight code Good cache performance Sort in place  Easy to implement  Used in older.
Study Group Randomized Algorithms Jun 7, 2003 Jun 14, 2003.
Tirgul 4 Order Statistics Heaps minimum/maximum Selection Overview
DAST 2005 Week 4 – Some Helpful Material Randomized Quick Sort & Lower bound & General remarks…
Ch. 8 & 9 – Linear Sorting and Order Statistics What do you trade for speed?
1 Introduction to Randomized Algorithms Srikrishnan Divakaran DA-IICT.
1 Introduction to Randomized Algorithms Srikrishnan Divakaran DA-IICT.
Chapter 14 Randomized algorithms Introduction Las Vegas and Monte Carlo algorithms Randomized Quicksort Randomized selection Testing String Equality Pattern.
Order Statistics The ith order statistic in a set of n elements is the ith smallest element The minimum is thus the 1st order statistic The maximum is.
© The McGraw-Hill Companies, Inc., Chapter 6 Prune-and-Search Strategy.
Order Statistics. Order statistics Given an input of n values and an integer i, we wish to find the i’th largest value. There are i-1 elements smaller.
The Selection Problem. 2 Median and Order Statistics In this section, we will study algorithms for finding the i th smallest element in a set of n elements.
Introduction to Algorithms Jiafen Liu Sept
1 Prune-and-Search Method 2012/10/30. A simple example: Binary search sorted sequence : (search 9) step 1  step 2  step 3  Binary search.
Optimal Bayes Classification
Randomized Algorithms CSc 4520/6520 Design & Analysis of Algorithms Fall 2013 Slides adopted from Dmitri Kaznachey, George Mason University and Maciej.
Princeton University COS 423 Theory of Algorithms Spring 2001 Kevin Wayne Average Case Analysis.
Deterministic and Randomized Quicksort Andreas Klappenecker.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
Instructor Neelima Gupta Expected Running Times and Randomized Algorithms Instructor Neelima Gupta
ICS 353: Design and Analysis of Algorithms
Master Method (4. 3) Recurrent formula T(n) = a  T(n/b) + f(n) 1) if for some  > 0 then 2) if then 3) if for some  > 0 and a  f(n/b)  c  f(n) for.
CSC317 1 Quicksort on average run time We’ll prove that average run time with random pivots for any input array is O(n log n) Randomness is in choosing.
Sorting Lower Bounds n Beating Them. Recap Divide and Conquer –Know how to break a problem into smaller problems, such that –Given a solution to the smaller.
01/16/2008 Randomized Quick Sort Algorithm Lecture Note – 1 Prepared By: Muhammed Miah.
Advanced Algorithms Analysis and Design
Quick-Sort 2/18/2018 3:56 AM Selection Selection.
Parameter Estimation 主講人:虞台文.
Randomized Algorithms
Lecture 8 Randomized Algorithms
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
Randomized Algorithms
Medians and Order Statistics
Master Method (4. 3) Recurrent formula T(n) = aT(n/b) + f(n)
CS200: Algorithm Analysis
Chapter 5: Probabilistic Analysis and Randomized Algorithms
Order Statistics Def: Let A be an ordered set containing n elements. The i-th order statistic is the i-th smallest element. Minimum: 1st order statistic.
Tomado del libro Cormen
Quick-Sort 5/7/2019 6:43 PM Selection Selection.
The Selection Problem.
Chapter 5: Probabilistic Analysis and Randomized Algorithms
Quick-Sort 5/25/2019 6:16 PM Selection Selection.
Randomized Algorithms
Lecture 9 Randomized Algorithms
Randomized Algorithms
Chapter 11 Sets, and Selection
Presentation transcript:

Randomized Algorithms Introduction Rom Aschner & Michal Shemesh

Today Probability theory Randomized Algorithms: Quick Sort Min Cut Las Vegas and Monte Carlo Binary Planar Partitions

Probability theory - Reminder A Random variable is a variable whose values are random but whose statistical distribution is known. Example: The expectation of a random variable X with density function p is defined as:

Probability theory - Reminder Linearity of Expectation Let X1, …,Xk be arbitrary random variables, and h(X1, …,Xk) a linear function. Then: Example:

Probability theory - Reminder Independent Events A collection of events is independent if for all subsets S in I: Conditional Probability The conditional probability of given is given by: Bayes Rule

Quick Sort 1st step: 2nd step:

Randomized Quick Sort Quick sort – a reminder

Randomized Quick Sort Consider sorting a set S of n numbers in ascending order (elements of S 1 in ascending order), y, (elements of S 2 in ascending order) This way the total number of steps in our sorting would be given by the recurrence:

Randomized Quick Sort So what is the problem? The running of O(nlogn) can be obtained even if ! We have n/2 candidate splitters, but how do we easily find one? Choose an element at random! Paradigm: Random sampling In randomized algorithms we assume we can take a random sample of the population - representing the population! The choice is made in O(1).

RandQS – running time Algorithm RandQS: Input: A set of numbers S = {n 1,n 2,…,n n }. Output: The elements of S sorted in increasing order. 1.Choose an element y uniformly at random from S. 2.By comparing each element of S with y, determine the set S1 of elements smaller than y and the set S2 of elements larger than y. 3.Recursively sort S1 and S2. Output the sorted version of S1, y and S2. What is the total number of comparisons?

RandQS – running time Define a random variable: (n i - is the i-th smallest number) What is the expected number of comparisons? Total number of comparisons: Expected number of comparisons: p ij - probability that n i and n j are compared

RandQS – running time We view an execution of RandQS as a binary tree: y S2S2 S1S1

RandQS – Example Example: S = {1, 3, 5, 8, 10, 15, 23, 40, 41} 15 S2S2 S1S1 1, 3, 5, 8, 10 23, 40, S2S2 S1S1 1 23, 40, 41 3 S2S2 5, 8, S2S2 S1S1 1 23, 40, 41 3 S2S2 8, Algorithm output: in-order traversal of the tree. T is a (random) binary search tree. T

RandQS – p ij = ? Level order traversal of the nodes: T : 15, 3, 40, 1, 5, 23, 41, 8, n i and n j are compared iff n i or n j occurs earlier in the permutation than any element n l such that i<l<j. 2. Any of the elements n i, n i +1 …, n j is equally likely to be the first of these elements to be chosen as a partitioning element, and hence to appear first in.

RandQS – ? Level order traversal of the nodes: T : 15, 3, 40, 1, 5, 23, 41, 8, 10

RandQS – expected running time The Expected number of comparisons in an execution of RandQS … … is at most

Randomized Quick Sort Paradigm: Foiling an adversary While the adversary may be able to construct an input that foils a deterministic algorithm, it is difficult to devise a single input that is likely to defeat a randomized algorithm. The expected running time holds for every input. We will see that with very high probability the running time of the algorithm is not much more than its expectation. Main principles: Performance Simplicity of description and implementation

A Min-Cut Algorithm Input: A connected, undirected multi-graph (multiple edges, no loops) G with n vertices. G Min-Cut: A set of edges in G whose removal results in G being broken into two or more components with minimum cardinality.

A Min-Cut Algorithm Min-Cut Algorithm: Input: A connected, undirected multi-graph G with n vertices. Output: A min-cut. 1.Repeat the following step until only vertices remain: Pick an edge uniformly at random and contract it: merge the two vertices at its end points. Remove self loops, retain new multi-edges. 2.Return the remaining set of edges.

A Min-Cut Algorithm - Does it always find a min-cut? 4. Min-Cut

Not a Min-Cut A Min-Cut Algorithm - Does it always find a min-cut?

For a set S of vertices of G, the neighborhood of S is the union of the neighborhoods of the constituent vertices. The degree of v is the number of edges incident on v. A Min-Cut Algorithm For any v in G, the neighborhood of v consist all the vertices that are adjacent to v.

A Min-Cut Algorithm - Does it always find a min-cut? Let denote the event of not picking an edge of C at the i-th step for 1 i n-2. At the ith step: … The probability that no edge of C is ever picked in the process is: Let C be a min-cut of size k. Then G has at least k*n/2 edges. At the 1st step: At the 2nd step:

A Min-Cut Algorithm The probability of discovering a particular min-cut is larger than. Repeat it time, making independent choices each time. The probability that a min-cut is never found in any of the (n^2)/2 times attempts is at most: The probability of error is bounded by:

RandQs vs. Min-Cut Algorithm So… What is the difference between the two? We have seen two types of randomized algorithms: Las Vegas - always gives the correct solution. Monte Carlo - gives the correct solution with high probability. Las Vegas algorithm is by definition a Monte Carlo algorithm with error probability of 0.

Monte Carlo Algorithms For decision problems (Yes/No), there are two kinds of Monte Carlo algorithms: Two sided error - there is a non zero probability that it errs when it outputs either Yes or No. One sided error - the probability that it errs is zero for at least one of the outputs that it produces.

Binary Space Partitions - Motivation

Painters Algorithm Problem Overlapping polygons with cycles The painters algorithm Sort all the polygons of the scene by their depth Paint the polygons from furthest to closest

Binary Space Partitions (BSP) recursively splitting the plane with a line: 1.Split the entire plane with l 1. 2.Split the half-plane above l 1 with l 2 and the half-plane below l 1 with l The splitting continues until there is only one fragment left in the interior of each region. [de Berg, van Kerveld, Overmars, Schwarzkopf – Computational geometry]

Example s1s1 s2s2 s3s3 L2L2 L1L1 L3L3 L 1 L 2 L 3 s3bs3b s 2 s3as3a s 1 Given a set of 3 non intersecting segments in the plane. We want to build a partition where each part contains at most 1 fragment. a b

Auto Partitions In the plane, A BSP that uses only extensions of the line segments as splitting lines is called an auto-partition. [de Berg et al. – Computational geometry] We will see that auto-partitions can produce reasonably small trees. Once we have the tree, for any given view point the painters algorithm just needs to run over the tree nodes. Therefore the running time of the painters algorithm depends on the size of the BSP tree.

Arbitrary choice of segment (n 2 ) worst-case BSP size if we choose the splitting lines in this order s 1,s 2, …, s n. s1s1 s2s2 s3s3 s n/2 n/2 How to construct small auto-partition ?

Algorithm RandAuto Algorithm RandAuto : Input: A set S = {s 1,s 2,…,s n } of non-intersecting line segments Output: A binary auto-partition P of S. 1.Pick a permutation of {1, 2, …, n} uniformly at random from n! possible permutations. 2.While a region contains more than one segment, cut it with l(s i ) where i is the first in the ordering such that s i cuts that region.

Algorithm Example s1s1 s2s2 s3s3 s2s2 s4as4a s 4b s 3a φ : 2, 1, 3,4 s4s4 L(s 1 ) L(s 2 ) L(s 3 ) s1s1 s 3b s 3a s 4b s 4a

Algorithm RandAuto Algorithm RandAuto : Input: A set S = {s 1,s 2,…,s n } of non-intersecting line segments Output: A binary auto-partition P of S. 1.Pick a permutation of {1, 2, …, n} uniformly at random from n! possible permutations. 2.While a region contains more than one segments, cut it with l(s i ) where i is the first in the ordering such that s i cuts that region. What is the size of the auto-partition produced?

denotes the event that l(u) cuts v in the constructed partition. RandAuto Algorithm – Notations For line segments u and v, define to be i if l(u) intersects i-1 other segments before hitting v. index(u,v)= if l(u) does not hit v. L(u) u v index(u,v)=12 v

The event happens only if u occurs before any of {u 1, u 2, …, u i-1, v} in. RandAuto Algorithm – Expected Size Let index(u,v)=i. We denote {u 1, u 2, …, u i-1 } to be the segments that l(u) intersects before hitting v. The probability for that is: Define a random variable: Therefore,

RandAuto Algorithm – Expected Size The expectation of the size of P : By the linearity of expectations: For any line segment u, there are at most two segments of the same index. i.e. index(u,v)=index(u,w)

RandAuto Algorithm – Expected Size Combining both we get: Is this the smallest tree we can get ?

RandAuto Algorithm – Expected Size There must exist a binary auto-partition of size O(nlogn). Why ? What if the size of the tree is not small enough ? Every set of n disjoint line segments in the plane admits an auto-partition of size θ(n log n/ log log n) [Csaba D. Tóth: SoCG 2009]

References Motwani R., Raghavan P., Randomized Algorithms de Berg M., van Kerveld M., Overmars M., Schwarzkopf O., Computational Geometry. Csaba D. Tóth, Binary Plane Partitions for Disjoint Line Segments, SoCG, 2009.

Thank you!