Randomized Algorithms Pasi Fränti 1.10.2014. Treasure island Treasure worth 20.000 awaits 5000 DAA expedition 5000 ? ? Map for sale: 3000.

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

Analysis of Algorithms CS Data Structures Section 2.6.
Order Statistics Sorted
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
WS Algorithmentheorie 03 – Randomized Algorithms (Primality Testing) Prof. Dr. Th. Ottmann.
1 Today’s Material Medians & Order Statistics – Ch. 9.
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
DIVIDE AND CONQUER APPROACH. General Method Works on the approach of dividing a given problem into smaller sub problems (ideally of same size).  Divide.
Spring 2015 Lecture 5: QuickSort & Selection
Randomized Algorithms Kyomin Jung KAIST Applied Algorithm Lab Jan 12, WSAC
25 May Quick Sort (11.2) CSE 2011 Winter 2011.
Data Structures, Search and Sort Algorithms Kar-Hai Chu
Updated QuickSort Problem From a given set of n integers, find the missing integer from 0 to n using O(n) queries of type: “what is bit[j]
WS Algorithmentheorie 03 – Randomized Algorithms (Overview and randomised Quicksort) Prof. Dr. Th. Ottmann.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Algorithmic Complexity Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Sorting Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Insertion sort, Merge sort COMP171 Fall Sorting I / Slide 2 Insertion sort 1) Initially p = 1 2) Let the first p elements be sorted. 3) Insert the.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu.
Sorting Algorithms Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Quicksort.
Randomized Algorithms Prof. Dr. Th. Ottmann University of Freiburg
This material in not in your text (except as exercises) Sequence Comparisons –Problems in molecular biology involve finding the minimum number of edit.
Study Group Randomized Algorithms Jun 7, 2003 Jun 14, 2003.
CSC 2300 Data Structures & Algorithms March 20, 2007 Chapter 7. Sorting.
Theory I Algorithm Design and Analysis (9 – Randomized algorithms) Prof. Dr. Th. Ottmann.
Randomized Algorithms. Introduction Algorithm uses a random number to make at least one decision Running time depends on input and random numbers generated.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
10 Algorithms in 20th Century Science, Vol. 287, No. 5454, p. 799, February 2000 Computing in Science & Engineering, January/February : The Metropolis.
Clustering Methods: Part 2d Pasi Fränti Speech & Image Processing Unit School of Computing University of Eastern Finland Joensuu, FINLAND Swap-based.
CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
Stochastic Algorithms Some of the fastest known algorithms for certain tasks rely on chance Stochastic/Randomized Algorithms Two common variations – Monte.
Randomized Turing Machines
1 Lecture 16: Lists and vectors Binary search, Sorting.
Complexity of algorithms Algorithms can be classified by the amount of time they need to complete compared to their input size. There is a wide variety:
Jessie Zhao Course page: 1.
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 19: Searching and Sorting.
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.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
CSC 211 Data Structures Lecture 13
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
Prabhas Chongstitvatana1 Las Vegas algorithm The answer obtained is always correct but sometime no answer. Modified deterministic algorithm by using randomness.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Sorting Data Structures and Algorithms (60-254). Sorting Sorting is one of the most well-studied problems in Computer Science The ultimate reference on.
Sorting Algorithm Analysis. Sorting  Sorting is important!  Things that would be much more difficult without sorting: –finding a phone number in the.
CS 2430 Day 30. Announcements Quiz #5: 4/19 Agenda Big O Searching –Linear search.
ICS 353: Design and Analysis of Algorithms
Data Structures and Algorithms Searching Algorithms M. B. Fayek CUFE 2006.
2IS80 Fundamentals of Informatics Fall 2015 Lecture 7: Sorting and Directed Graphs.
Experimental Study on the Five Sort Algorithms You Yang, Ping Yu, Yan Gan School of Computer and Information Science Chongqing Normal University Chongqing,
Intro. to Data Structures Chapter 7 Sorting Veera Muangsin, Dept. of Computer Engineering, Chulalongkorn University 1 Chapter 7 Sorting Sort is.
329 3/30/98 CSE 143 Searching and Sorting [Sections 12.4, ]
INTRO2CS Tirgul 8 1. Searching and Sorting  Tips for debugging  Binary search  Sorting algorithms:  Bogo sort  Bubble sort  Quick sort and maybe.
1 compares each element of the array with the search key. works well for small arrays or for unsorted arrays works for any table slow can put more commonly.
Subject Name: Design and Analysis of Algorithm Subject Code: 10CS43
Data Structures I (CPCS-204)
COP 3503 FALL 2012 Shayan Javed Lecture 15
Random Swap algorithm Pasi Fränti
Sit-In Lab 1 Ob-CHESS-ion
Quick Sort (11.2) CSE 2011 Winter November 2018.
Random Swap algorithm Pasi Fränti
8/04/2009 Many thanks to David Sun for some of the included slides!
Sorting … and Insertion Sort.
Linked List and Selection Sort
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Randomized Algorithms
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
CS 583 Analysis of Algorithms
Presentation transcript:

Randomized Algorithms Pasi Fränti

Treasure island Treasure worth awaits 5000 DAA expedition 5000 ? ? Map for sale: 3000

To buy or not to buy Buy the map: Take a change: – 5000 – 3000 = – 5000 = – 5000 – 5000 =

To buy or not to buy Buy the map: Take a change: – 5000 – 3000 = – 5000 = – 5000 – 5000 = Expected result: 0.5 ∙ ∙ =

Three type of randomization 1.Las Vegas -Output is always correct result -Result is not always found -Probability of success p 2.Monte Carlo -Result is always found -Result can be inaccurate (or even false!) -Probability of success p 3.Sherwood -Balancing the worst case behavior

Las Vegas

Eating philosophizes Who eats?

Las Vegas Input:Binary vector A[1, n] Output:Index of any 1-bit from A LV(A, n) REPEAT k ← RAND(1, n); UNTIL A[k]=1; RETURN k Revise

8-Queens puzzle INPUT: Eight chess queens and an 8×8 chessboard OUTPUT: Setup where no queens attack each other

8-Queens brute force Brute force Try all positions Mark illegal squares Backtrack if dead-end 114 setups in total Random Select positions randomly If dead-end, start over Randomized Select k rows randomly Rest rows by Brute Force … Where next…?

Pseudo code 8-Queens(k) FOR i=1 TO k DO// k Queens randomly r  Random[1,8]; IF Board[i,r]=TAKEN THEN RETURN Fail; ELSE ConquerSquare(i,r); FOR i=k+1 TO 8 DO // Rest by Brute Force r  1; found  NO; WHILE (r≤8) AND (NOT found) DO IF Board[i,r] NOT TAKEN THEN ConquerSquare(i,r); found  YES; IF NOT found THEN RETURN Fail; ConquerSquare(i,j) Board[i,j]  QUEEN; FOR z=i+1 TO 8 DO Board[z,j]  TAKEN; Board[z,j-(z-i)]  TAKEN; Board[z,j+(z-i)]  TAKEN;

Probability of success s = processing time in case of success e = processing time in case of failure p = probability of success q = 1-p = probability of failure Example: s=e=1, p=1/6  t=1+5/1∙1=6

Experiments with varying k KSETP % % % % % % % % % Fastest expected time

Swap-based clustering

Clustering by Random Swap RandomSwap(X) → C, P C ← SelectRandomRepresentatives(X); P ← OptimalPartition(X, C); REPEAT T times (C new, j) ← RandomSwap(X, C); P new ← LocalRepartition(X, C new, P, j); C new, P new ← Kmeans(X, C new, P new ); IF f(C new, P new ) < f(C, P) THEN (C, P) ← C new, P new ; RETURN (C, P); P. Fränti and J. Kivijärvi, "Randomised local search algorithm for the clustering problem", Pattern Analysis and Applications, 3 (4), , Select random neighbor Accept only if it improves

1. Random swap: 2. Re-partition vectors from old cluster: 3. Create new cluster: Clustering by Random Swap

Choices for swap O(M) clusters to be removed O(M) clusters where to add O(M 2 ) different choices in total  =

Select a proper centroid for removal: – M clusters in total: p removal =1/M. Select a proper new location: – N choices: p add =1/N – M of them significantly different: p add =1/M In total: – M 2 significantly different swaps. – Probability of each is p swap =1/M 2 – Open question: how many of these are good – Theorem: α are good for add and removal. Probability for successful Swap

Probability of not finding good swap: Estimated number of iterations: Clustering by Random Swap Iterated T times

Upper limit: Lower limit similarly; resulting in: Bounds for the iterations

Number of iterations needed (T): t = O(αN) Total time: Time complexity of single step (t): Total time complexity

Monte Carlo

Input: A bit vector A[1, n], iterations I Output: An index of any 1 bit from A LV(A, n, I) i ← 0; DO k ← RAND(1, n); i ← i + 1; WHILE (A[k]≠1 AND i ≤ I) RETURN k Revise

Monte Carlo Potential problems to be considered: Detecting prime numbers Calculating integral of a function To appear in 2014… maybe…

Sherwood

Selection of pivot element Something about Quicksort and Selection: Practical example of re-sorting Median selection Add material for 2014 N-11N-21 N-3 1 … O(N 2 )

Simulated dynamic linked list 1.Sorted array -Search efficient: O(logN) -Insert and Delete slow: O(N) 2.Dynamically linked list -Insert and Delete fast: O(1) -Search inefficient: O(N)

Simulated dynamic linked list Example i Value Next Head Linked list: Head=4 Simulated by array:

SEARCH (A, x) i := A.HEAD; max := A[i].VALUE; FOR k:=1 TO  N DO j:=RANDOM(1, N); y:=A[j].VALUE; IF (max<y) AND (y≤x) THEN i:=j; max:=y; RETURN LinearSearch(A, x, i); Simulated dynamic linked list Divide-and-conquer with randomization  N random breakpoints Biggest breakpoint ≤ x Value searched Full search from breakpoint i

Analysis of the search max search for (on average) Divide into  N segments Each segment has N/  N =  N elements Linear search within one segment. Expected time complexity =  N +  N = O(  N)

Experiment with students Data (N=100) consists of numbers from : Select  N breaking points:

Searching for… 42

Empty space for notes