Atlantis HKOI2005 Final Event (Senior Group). 2 Background 9000 B.C. 9000 B.C. Atlantis Zeus Other gods Destroy!!

Slides:



Advertisements
Similar presentations
Maximum flow Main goals of the lecture:
Advertisements

On allocations that maximize fairness Uriel Feige Microsoft Research and Weizmann Institute.
Lecture 24 MAS 714 Hartmut Klauck
Cs4432concurrency control1 CS4432: Database Systems II Lecture #21 Concurrency Control : Theory Professor Elke A. Rundensteiner.
On the Density of a Graph and its Blowup Raphael Yuster Joint work with Asaf Shapira.
Rare Events, Probability and Sample Size. Rare Events An event E is rare if its probability is very small, that is, if Pr{E} ≈ 0. Rare events require.
Analysis of Algorithms
A sublinear Time Approximation Scheme for Clustering in Metric Spaces Author: Piotr Indyk IEEE FOCS 1999.
Great Theoretical Ideas in Computer Science for Some.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
1 Maximum flow sender receiver Capacity constraint Lecture 6: Jan 25.
Divide and Conquer. Recall Complexity Analysis – Comparison of algorithm – Big O Simplification From source code – Recursive.
Nattee Niparnan. Recall  Complexity Analysis  Comparison of Two Algos  Big O  Simplification  From source code  Recursive.
Lectures on Network Flows
The number of edge-disjoint transitive triples in a tournament.
CPSC 121: Models of Computation
CSL758 Instructors: Naveen Garg Kavitha Telikepalli Scribe: Manish Singh Vaibhav Rastogi February 7 & 11, 2008.
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.
Complexity 16-1 Complexity Andrei Bulatov Non-Approximability.
Great Theoretical Ideas in Computer Science.
Computability and Complexity 23-1 Computability and Complexity Andrei Bulatov Search and Optimization.
1 Discrete Structures & Algorithms Graphs and Trees: II EECE 320.
Advanced Topics in Algorithms and Data Structures Page 1 Parallel merging through partitioning The partitioning strategy consists of: Breaking up the given.
Kavita Math231 Recursion and Iteration. Kavita Math231 We use Recursion when we have to perform a complex task that can be broken into the several subtasks.
More sorting algorithms: Heap sort & Radix sort. Heap Data Structure and Heap Sort (Chapter 7.6)
Parallel Merging Advanced Algorithms & Data Structures Lecture Theme 15 Prof. Dr. Th. Ottmann Summer Semester 2006.
CSE 421 Algorithms Richard Anderson Lecture 4. What does it mean for an algorithm to be efficient?
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
2-Layer Crossing Minimisation Johan van Rooij. Overview Problem definitions NP-Hardness proof Heuristics & Performance Practical Computation One layer:
Job Scheduling Lecture 19: March 19. Job Scheduling: Unrelated Multiple Machines There are n jobs, each job has: a processing time p(i,j) (the time to.
Aligning Alignments Exactly By John Kececioglu, Dean Starrett CS Dept. Univ. of Arizona Appeared in 8 th ACM RECOME 2004, Presented by Jie Meng.
1 Separator Theorems for Planar Graphs Presented by Shira Zucker.
Lecture 11. Matching A set of edges which do not share a vertex is a matching. Application: Wireless Networks may consist of nodes with single radios,
1 Spanning Tree Polytope x1 x2 x3 Lecture 11: Feb 21.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Hellman’s TMTO 1 Hellman’s TMTO Attack. Hellman’s TMTO 2 Popcnt  Before we consider Hellman’s attack, consider simpler Time-Memory Trade-Off  “Population.
Minimal Spanning Trees What is a minimal spanning tree (MST) and how to find one.
10.4 How to Find a Perfect Matching We have a condition for the existence of a perfect matching in a graph that is necessary and sufficient. Does this.
Sorting HKOI Training Team (Advanced)
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
Searching and Sorting Gary Wong.
CSE 421 Algorithms Richard Anderson Lecture 24 Network Flow Applications.
Edge-disjoint induced subgraphs with given minimum degree Raphael Yuster 2012.
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.
Complexity 20-1 Complexity Andrei Bulatov Parallel Arithmetic.
Sorting CS 105 See Chapter 14 of Horstmann text. Sorting Slide 2 The Sorting problem Input: a collection S of n elements that can be ordered Output: the.
Sorting CS 110: Data Structures and Algorithms First Semester,
All Pair Shortest Path IOI/ACM ICPC Training June 2004.
Provinci summer training 2010 June 17: Recursion and recursive decent parser June 24: Greedy algorithms and stable marriage July 1: Holiday July 8: Math.
Discrete Structures & Algorithms More on Methods of Proof / Mathematical Induction EECE 320 — UBC.
Bipartite Matching. Unweighted Bipartite Matching.
UNIT 5.  The related activities of sorting, searching and merging are central to many computer applications.  Sorting and merging provide us with a.
Algorithm Analysis Chapter 5. Algorithm An algorithm is a clearly specified set of instructions which, when followed, solves a problem. –recipes –directions.
Minimum Spanning Trees Featuring Disjoint Sets HKOI Training 2006 Liu Chi Man (cx) 25 Mar 2006.
Storage Centre HKOI 2007 Senior Q1 Kelly Choi. The Problem The COW Team are going to look for treasures in N ruins in a rectangular map. The COW Team.
Chapter 8 Maximum Flows: Additional Topics All-Pairs Minimum Value Cut Problem  Given an undirected network G, find minimum value cut for all.
Graph Algorithms Maximum Flow - Best algorithms [Adapted from R.Solis-Oba]
HKOI 2012 (Senior) Q4 - Gene Mutation Gary Wong For any question, please ask via MSN:
Approximation Algorithms based on linear programming.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
IOI/ACM ICPC Training 4 June 2005.
Great Theoretical Ideas in Computer Science
Various Graph Algorithms
The Taxi Scheduling Problem
Computability and Complexity
Instructor: Shengyu Zhang
15th Scandinavian Workshop on Algorithm Theory
Visual Algebra for Teachers
Presentation transcript:

Atlantis HKOI2005 Final Event (Senior Group)

2 Background 9000 B.C B.C. Atlantis Zeus Other gods Destroy!!

3 Problem There are N pairs of (island + controller) There are N pairs of (island + controller) In each pair, the island is K meters above the controller for some fixed positive integer K In each pair, the island is K meters above the controller for some fixed positive integer K Given the heights of the 2N objects, which of them are controllers? What is K? Given the heights of the 2N objects, which of them are controllers? What is K?

4 Model Two integer sequences Two integer sequences A = (a 1, a 2, …, a N ), B = (b 1, b 2, …, b N ) are parallel if for some positive integer K, a 1 = b 1 +K, a 2 = b 2 +K, …, a N = b N +K Given a collection C of 2N positive integers, partition it into 2 parallel sequences of size N, if possible Given a collection C of 2N positive integers, partition it into 2 parallel sequences of size N, if possible

5 Smaller problems How to determine if two sequences are parallel? How to determine if two sequences are parallel? Trivial – O(N) Trivial – O(N) Given two collections of size N, is it possible to form a sequence of size N from each of the sets such that the two sequences are parallel? Given two collections of size N, is it possible to form a sequence of size N from each of the sets such that the two sequences are parallel? Sorting – O(NlgN) (O(N) for count sort) Sorting – O(NlgN) (O(N) for count sort)

6 Algorithm 1 Idea Idea Partition C into two collections of size N Partition C into two collections of size N Determine if two parallel sequences can be formed from the two collections (previous slide) Determine if two parallel sequences can be formed from the two collections (previous slide) 2N C N ways to partition C 2N C N ways to partition C Exponential Exponential Expected score: 50% Expected score: 50%

7 Observations Out of the 2N C N different partitions, most of them should not be tested, for example Out of the 2N C N different partitions, most of them should not be tested, for example {1, 2, …, 2N}  {1, 4, ??, …, ??}, {2, 3, ??, …, ??} {1, 2, …, 2N}  {1, 4, ??, …, ??}, {2, 3, ??, …, ??} Why? Why? {1, 2, …, 2N}  {1, 2, 4, ??, …, ??}, {3, ??, …, ??} {1, 2, …, 2N}  {1, 2, 4, ??, …, ??}, {3, ??, …, ??} The smallest integer from one collection and the smallest integer from another collection form a pair The smallest integer from one collection and the smallest integer from another collection form a pair

8 Almost there… Suppose we know the smallest pair, can we reconstruct the partition? Suppose we know the smallest pair, can we reconstruct the partition? Fact: The smallest pair must contain the smallest integer in the C Fact: The smallest pair must contain the smallest integer in the C

9 6+2 = 87+2 = 9 67 An Example Given C = {2, 6, 1, 3, 7, 4, 8, 9} and suppose we are told that (1, 3) is the smallest pair Given C = {2, 6, 1, 3, 7, 4, 8, 9} and suppose we are told that (1, 3) is the smallest pair (1, 3) Smallest remaining integer = Its partner = = 4 (2, 4) (6, 8) (7, 9)

10 Algorithm 2 Idea Idea Suppose (a, b) is the smallest pair; let d = b – a Suppose (a, b) is the smallest pair; let d = b – a Repeat N times Repeat N times Let s be the smallest integer in C Let s be the smallest integer in C If s+d is not in C, return failure If s+d is not in C, return failure Otherwise (s, s+d) is a pair, remove s and s+d from C Otherwise (s, s+d) is a pair, remove s and s+d from C For how many times do we need to carry out the above steps? For how many times do we need to carry out the above steps?

11 Algorithm 2 - Analysis How many different “smallest pairs” should be tried? How many different “smallest pairs” should be tried? N (smallest, 2 nd smallest), (smallest, 3 rd smallest), …, (smallest, (n+1) th smallest) (smallest, 2 nd smallest), (smallest, 3 rd smallest), …, (smallest, (n+1) th smallest)

12 Algorithm 2 – Analysis (2) The loop takes O(N 2 ) time The loop takes O(N 2 ) time Overall time complexity is O(N 3 ) Overall time complexity is O(N 3 ) Too slow when N = 1000 Too slow when N = 1000 Observation: The pairs we get are increasing Observation: The pairs we get are increasing Both coordinates are increasing Both coordinates are increasing (1, 3) ≤ (2, 4) ≤ (6, 8) ≤ (7, 9) (1, 3) ≤ (2, 4) ≤ (6, 8) ≤ (7, 9)

= = = 9 7 Algorithm 2A Sort the integers in C Sort the integers in C Keep two pointers (integers) Keep two pointers (integers) (1, 3) Smallest remaining integer = Its partner = (2, 4) (6, 8) (7, 9) AB

14 Algorithm 2A The loop takes O(N) time The loop takes O(N) time Overall time complexity is O(N 2 ) Overall time complexity is O(N 2 ) Not a problem even when N = Not a problem even when N = 10000

15 Algorithm 3 (Out of Syllabus) For trainees with graph theory background For trainees with graph theory background Fix a height difference, construct a graph, then find a maximum bipartite matching Fix a height difference, construct a graph, then find a maximum bipartite matching Example: Height difference = 2 Example: Height difference = 2 Perfect matching Perfect matching  Feasible Overall time complexity: Overall time complexity: O(N 3.5 ) or O(N 3 )

16 Extensions and Mutations Constraints: Constraints: Real numbers instead of integers Real numbers instead of integers Height sums instead of height differences Height sums instead of height differences Height differences can lie in a range instead of a fixed number Height differences can lie in a range instead of a fixed number Objectives: Objectives: Minimize sum of height differences Minimize sum of height differences Minimize maximum height difference Minimize maximum height difference