Discrete Structures & Algorithms EECE 320 : UBC : Spring 2009 Matei Ripeanu 1.

Slides:



Advertisements
Similar presentations
Great Theoretical Ideas in Computer Science
Advertisements

CISC1400: Discrete Structure Introduction 1 Dr. Zhang, Fall 2011, Fordham Univ.
Today’s Daily Quiz will be given at the end of the hour. Please close your laptops and turn off and put away your cell phones, and get out your note-taking.
Lecture 12: Lower bounds By "lower bounds" here we mean a lower bound on the complexity of a problem, not an algorithm. Basically we need to prove that.
CSC 2300 Data Structures & Algorithms March 16, 2007 Chapter 7. Sorting.
Cooking for Computer Scientists. I understand that making pancakes can be a dangerous activity and that, by doing so, I am taking a risk that I.
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 23, 2009.
Bioinformatics Chromosome rearrangements Chromosome and genome comparison versus gene comparison Permutations and breakpoint graphs Transforming Men into.
1 Greedy Algorithms. 2 2 A short list of categories Algorithm types we will consider include: Simple recursive algorithms Backtracking algorithms Divide.
Welcome to MAT 170. Basic Course Information Instructor Office Office Hours Beth Jones PSA 725 Wednesday and Friday 10:40 am – 11:30 am and by appointment.
Introduction to Bioinformatics Algorithms Greedy Algorithms And Genome Rearrangements.
Genome Rearrangements CSCI : Computational Genomics Debra Goldberg
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2004 Lecture 1 Jan 13, 2004 Carnegie Mellon University.
MATH 330: Ordinary Differential Equations Fall 2014.
CSE115/ENGR160 Discrete Mathematics 01/17/12 Ming-Hsuan Yang UC Merced 1.
Pancakes With A Problem Steven Rudich The chef at our place is sloppy, and when he prepares a stack of pancakes they come out all different sizes.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Vince Conitzer COMPSCI 102 Fall 2007 Lecture 1 August 27, 2007 Duke University.
Cooking for Computer Scientists. I understand that making pancakes can be a dangerous activity and that, by doing so, I am taking a risk that I.
Spring 2012 MATH 250: Calculus III. Course Topics Review: Parametric Equations and Polar Coordinates Vectors and Three-Dimensional Analytic Geometry.
CHAPTER 7: SORTING & SEARCHING Introduction to Computer Science Using Ruby (c) Ophir Frieder at al 2012.
COMP 151: Computer Programming II Spring Course Topics Review of Java and basics of software engineering (3 classes. Chapters 1 and 2) Recursion.
CHEMISTRY 10123/10125 Spring 2007 Instructor: Professor Tracy Hanna Phone: Office: SWR 418
Lecture 23. Greedy Algorithms
MATH 310, FALL 2003 (Combinatorial Problem Solving) MoWeFr 1:20 McGregory 214.
CompSci 102 Spring 2012 Prof. Rodger January 11, 2012.
CS 103 Discrete Structures Lecture 01 Introduction to the Course
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS Fall 2O05 Lecture 1 Aug 29 th, 2OO5 Aug 29 th, 2OO5 Carnegie.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Anupam Gupta CS Fall 2006 Lecture 1 Aug 29 th, 2OO6 Aug 29 th, 2OO6 Carnegie.
Great Theoretical Ideas in Computer Science.
1 My Experiences as Faculty Member and Researcher Dr. Kalim Qureshi.
Chapter 3 Sec 3.3 With Question/Answer Animations 1.
Teaching Thermodynamics with Collaborative Learning Larry Caretto Mechanical Engineering Department June 9, 2006.
Genome Rearrangements Unoriented Blocks. Quick Review Looking at evolutionary change through reversals Find the shortest possible series of reversals.
Greedy Algorithms And Genome Rearrangements An Introduction to Bioinformatics Algorithms (Jones and Pevzner)
1 Chapter 7: Sorting (Insertion Sort, Shellsort) CE 221 Data Structures and Algorithms Izmir University of Economics Text: Read Weiss, § 7.1 – 7.4.
Genome Rearrangements [1] Ch Types of Rearrangements Reversal Translocation
Greedy Algorithms And Genome Rearrangements
Discrete Mathematics CS204 Spring CS204 Discrete Mathematics Instructor: Professor Chin-Wan Chung (Office: Rm 3406, Tel:3537) 1.Lecture 1)Time:
TECH Computer Science Problem: Selection Design and Analysis: Adversary Arguments The selection problem >  Finding max and min Designing against an adversary.
CPSC 121: Models of Computation Unit 0 Introduction George Tsiknis Based on slides by Patrice Belleville and Steve Wolfman.
Andrew’s Leap 2011 Pancakes With A Problem Steven Rudich.
Mathematical Proofs And how they are applied to Computer Olympiads.
Graph Colouring L09: Oct 10. This Lecture Graph coloring is another important problem in graph theory. It also has many applications, including the famous.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
David Luebke 1 11/29/2015 CS 332: Algorithms Introduction Proof By Induction Asymptotic notation.
Analysis of Algorithms CS 477/677 Instructor: Monica Nicolescu Lecture 7.
Lecture 5.4: Paths and Connectivity CS 250, Discrete Structures, Fall 2011 Nitesh Saxena *Adopted from previous lectures by Zeph Grunschlag.
Pancakes With A Problem! Great Theoretical Ideas In Computer Science Steven Rudich CS Spring 2005 Lecture 3 Jan 18, 2005 Carnegie Mellon University.
Chapter 8 Maximum Flows: Additional Topics All-Pairs Minimum Value Cut Problem  Given an undirected network G, find minimum value cut for all.
Introduction to Bioinformatics Algorithms Chapter 5 Greedy Algorithms and Genome Rearrangements By: Hasnaa Imad.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
1 Chapter 7: Sorting (Insertion Sort, Shellsort) CE 221 Data Structures and Algorithms Izmir University of Economics Text: Read Weiss, § 7.1 – 7.4.
CIS 313: Analysis and Design of Algorithms Assoc. Prof Hassan Aly Department of Computer Science and Information College of Science at AzZulfi Al-Majmaah.
The material in this lecture should be review. If you have not seen it before, you should be able to learn it quickly – and on your own. So we are going.
Chapter 7: Sorting (Insertion Sort, Shellsort)
Greedy Algorithms.
Welcome to CMSC 203 – Discrete Structures Spring 2003
Pancakes With A Problem!
Data Structures Algorithms: (Slides to be Adopted from Goodrich and aligned with Weiss' book) Instructor: Ganesh Ramakrishnan
Introduction Dr. X. Zhang, Fordham Univ. 1.
Pancakes With A Problem!
Jeremy Bolton, PhD Assistant Teaching Professor
Welcome to Physics 1D03.
Data Structures and Algorithms CSCE 221H
Advanced Analysis of Algorithms
Cooking for Computer Scientists.
CSE 373 Sorting 2: Selection, Insertion, Shell Sort
Bounds for Sorting by Prefix Reversal -- Pancake Problem
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

Discrete Structures & Algorithms EECE 320 : UBC : Spring 2009 Matei Ripeanu 1

URL: Instructor: Matei Ripeanu Office: KAIS 4033 Office hours: after class (Thu 8:00pm -- …) Teaching assistants Sarah Motiee

3 Sorting pancakes

4 He does this by grabbing several from the top and flipping them over, repeating this (varying the number he flips) as many times as necessary. The chefs at ubc hop are sloppy: when they prepare pancakes, they come out all different sizes. When the waiter delivers them to a customer, he rearranges them (so that smallest is on top, and so on, down to the largest at the bottom).

5 Treating pancakes as numbers

6 How do we sort this stack? How many flips do we need?

7 4 flips suffice

8 What is the best way to sort? X = Smallest number of flips required to sort: ?  X  ? Upper Bound Lower Bound 4

9 4 flips are necessary Flip 2 must bring 4 to top (if it didn’t, we would spend more than 3) Flip 1 has to put 5 on bottom If we could do it in three flips:

10 X = 4 Upper Bound Lower Bound 4  X  4 X = 4

11 Pancake numbers MAX over all s { MIN # of flips to sort s }; s is a stack of 5 pancakes P 5 = X1X1 X2X2 X3X3 X 119 X Number of flips required to sort the worst case stack of 5 pancakes P 5 =

12 The 5th pancake number ?  P 5  ? Upper Bound Lower Bound 4

13 Defining the pancake number Two ways to define P n P n = maximum over all s { minimum number of flips needed to sort stack s }; where s is one of n! stacks P n = the number of flips required to sort the worst-case stack of n pancakes

14 P n for small n How do we reason about P n for n=0, 1, 2, 3?

15 Initial values of P n n0123 PnPn

16 Initial values of P n n0123 PnPn 0013

17 P 3 = requires 3 flips, hence ANY stack of 3 can be done by getting the big one to the bottom (≤ 2 flips), and then using ≤ 1 flips to handle the top two. P 3 ≥ 3

18 The n th pancake number Number of flips required to sort the worst case stack of n pancakes. P n = ?  P n  ? Upper Bound Lower Bound

19 ?  P n  ? Try to find upper and lower bounds on P n, for n > 3.

20 Bracketing (bounding) ≤ f(x) ≤ [ ]

21 Procedure: Bring to top Bring biggest to top Place it on bottom. Bring next largest to top Place second from bottom. And so on…

22 Upper bound on P n Use the bring to top method for n pancakes. If n=1: no work is needed Else: flip pancake n to the top and then flip it to position n. Then: use the bring to top method for the remaining n-1 pancakes. Number of flips: 2(n-1)

23 A better upper bound Using the bring to top method, we noted that we need at most 2(n-1) flips. When n=2, however, we need only 1 flip. Therefore, we need 2(n-2) flips for the biggest n-2 items and then 1 flip. Total number of flips: 2(n-2)+1 = 2n-3.

?  P n  2n-3

25 Bring to top is not optimal Bring-to-top takes 5 flips, but we need only 4 flips

26 Obtaining a lower bound The breaking apart argument. Suppose a stack S has a pair of adjacent pancakes that will not be adjacent in the sorted stack. Any sequence of flips that sorts stack S must have one flip that inserts the spatula between that pair and breaks them apart. Furthermore, this is true of the “pair” formed by the bottom pancake of S and the plate. 9 16

27 n  P n n n-1 S S contains n pairs that will need to be broken apart during any sequence that sorts it. Suppose n is even: 2121 Detail: This construction only works when n>2

28 n  P n n n-1 S S contains n pairs that will need to be broken apart during any sequence that sorts it. Suppose n is odd: Detail: This construction only works when n>3

29 n  P n  2n – 3 for n > 3 Bring-to-top is within a factor of 2 of the optimal sorting scheme!

30 Starting from ANY stack we can get to the sorted stack using no more than P n flips. n  P n  2n – 3 (for n  3)

31 From ANY stack to the sorted stack in · P n. Reverse the sequences we use to sort. From the sorted stack to ANY stack in ·… ? ((( ))) P n How?

32 From ANY stack to sorted stack in · P n. From sorted stack to ANY stack in · P n. Hence, From ANY stack to ANY stack in · 2P n. Q: From ANY stack to ANY stack in … ?

33 From ANY stack to ANY stack in · 2P n. Can you find a faster way than 2P n flips to go from ANY to ANY? ((( )))

34 From ANY Stack S to ANY stack T in · P n Rename the pancakes in S to be 1,2,3,..,n. Rewrite T using the new naming scheme that you used for S. T will be some list:  (1),  (2),..,  (n). The sequence of flips that brings the sorted stack to  (1),  (2),..,  (n) will bring S to T. S: 4,3,5,1,2T: 5,2,4,3,1 1,2,3,4,53,5,1,2,4

35 Starting from ANY stack we can get to the sorted stack using no more than P n flips. Recap: n  P n  2n – 3 (for n  3)

36 Known pancake numbers nPnPn

37 P 14 is unknown 1 x 2 x 3 x... x 14 = 14! orderings for 14 pancakes. 14! = 87,178,291,200.

38 Computer engineering?

39 Sorting by prefix reversal Posed in American Mathematical Monthly, Vol. 82 (1), 1975, “Harry Dweighter” a.k.a. Jacob Goodman

40 (17/16)n  P n  (5n+5)/3 William Gates and Christos Papadimitriou. Bounds For Sorting By Prefix Reversal. Discrete Mathematics, vol 27, pp 47-57, 1979.

41 (15/14)n  P n  (5n+5)/3 H. Heydari and H. I. Sudborough. On the Diameter of the Pancake Network. Journal of Algorithms, vol 25, pp 67-94, 1997.

42 Pancake networks Assume a network with n! nodes: For each node, assign it the name of one of the n! stacks of n pancakes. Put a wire between two nodes if they are one flip apart.

43 Pancake network for n=

44 Pancake network for n=4

45 Pancake network: routing PnPn What is the maximum distance between two nodes in the pancake network?

46 Pancake network: reliability If up to k nodes get hit by lightning does the network remain connected? The pancake network is optimally reliable for its number of edges and nodes.

47 Mutation distance

48 One “simple problem” A host of problems and applications at the frontiers of science.

49 Motivating this course Computer science and engineering is not merely about computers and programming … ways to solve problems … it is about (mathematically) modeling our world and about finding better ways to solve problems Today’s example is a microcosm of this exercise.

50 Mechanics for the course

51 For questions and general discussion No discussion about assignments other than to clarify problem statements Mailing list

52 Assessment & grading 20% Assignments 20% Programming project 30% Quizzes 30% Final exam Participation bonus: up to 5%

53 Homework & Quizzes 6 homework assignments over the course of the term Work in groups of three Typically assigned on a Thursday, due in a week Late policy: 33% penalty per late day Each homework is worth about 3.5% 4 quizzes over the term Individual 30 minutes or so, in class Each quiz is worth about 6%

54 ((( ))) Ask questions Participation bonus: up to 5% 54

55 Summary so far Pancake sorting A problem with many applications Bracketing (bounding a function) Proving bounds for pancake sorting You can make money solving such problems (Bill Gates!) Illustrated many concepts that we will learn in this course Proofs Sets Counting Performance of algorithms