MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.

Slides:



Advertisements
Similar presentations
COMP 170 L2 Page 1 L06: The RSA Algorithm l Objective: n Present the RSA Cryptosystem n Prove its correctness n Discuss related issues.
Advertisements

Chapter 5 Decrease and Conquer. Homework 7 hw7 (due 3/17) hw7 (due 3/17) –page 127 question 5 –page 132 questions 5 and 6 –page 137 questions 5 and 6.
Chapter 5: Decrease and Conquer
Chapter 6: Transform and Conquer
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 6 Ack : Carola Wenk nad Dr. Thomas Ottmann tutorials.
Data Structures Data Structures Topic #13. Today’s Agenda Sorting Algorithms: Recursive –mergesort –quicksort As we learn about each sorting algorithm,
Lecture 8 Jianjun Hu Department of Computer Science and Engineering University of South Carolina CSCE350 Algorithms and Data Structure.
Algorithm Design Techniques: Induction Chapter 5 (Except Section 5.6)
6/20/2015 5:05 AMNumerical Algorithms1 x x1x
Chapter 10: Algorithm Design Techniques
Permutations. Motivation Shuffling – Games – Music players Brute-force algorithms.
CSC 2300 Data Structures & Algorithms January 30, 2007 Chapter 2. Algorithm Analysis.
Recursion Chapter 7. Chapter 7: Recursion2 Chapter Objectives To understand how to think recursively To learn how to trace a recursive method To learn.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Important Problem Types and Fundamental Data Structures
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
COMP 170 L2 Page 1 L05: Inverses and GCDs l Objective: n When does have an inverse? n How to compute the inverse? n Need: Greatest common dividers (GCDs)
MA/CSSE 473 Day 22 Binary Heaps Heapsort Answers to student questions Exam 2 Tuesday, Nov 4 in class.
MA/CSSE 473 Day 12 Insertion Sort quick review DFS, BFS Topological Sort.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Course Web Page Most information about the course (including the syllabus) will be posted on the course wiki:
MA/CSSE 473 Day 23 Transform and Conquer. MA/CSSE 473 Day 23 Scores on HW 7 were very high (class average was 93%). Good job! (Score was not included.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
MA/CSSE 473 Day 15 BFS Topological Sort Combinatorial Object Generation Intro.
Hashing Chapter 20. Hash Table A hash table is a data structure that allows fast find, insert, and delete operations (most of the time). The simplest.
MA/CSSE 473 Day 11 Primality testing summary Data Encryption RSA.
RAIK 283: Data Structures & Algorithms
Elementary Sorting Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
MA/CSSE 473 Day 18 Permutations by lexicographic order number.
FUNCTIONS Definition Let A = {1, 2, 3,..., n}, and f : A → A be a bijective function; then f is called a permutation on n. QUESTION: for a set with N elements.
MA/CSSE 473 Day 10 Primality testing summary Data Encryption RSA.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
+ Review CS302 Spring 2013 David Kauchak. + Admin Final posted on the course web page on Monday due Sunday at 11:59pm time-boxed (3-4 hours) You may use:
INTRODUCTION. What is an algorithm? What is a Problem?
MA/CSSE 473 Day 19 Exam Prep. MA/CSSE 473 Day 19 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various.
MA/CSSE 473 Day 28 Dynamic Programming Binomial Coefficients Warshall's algorithm Student questions?
Reading and Writing Mathematical Proofs Spring 2015 Lecture 4: Beyond Basic Induction.
1 Sorting Algorithms Sections 7.1 to Comparison-Based Sorting Input – 2,3,1,15,11,23,1 Output – 1,1,2,3,11,15,23 Class ‘Animals’ – Sort Objects.
CS 61B Data Structures and Programming Methodology July 21, 2008 David Sun.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
1 CS 430: Information Discovery Lecture 4 Files Structures for Inverted Files.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 7.
+ David Kauchak cs312 Review. + Midterm Will be posted online this afternoon You will have 2 hours to take it watch your time! if you get stuck on a problem,
MA/CSSE 473 Day 08 Extended Euclid's Algorithm Modular Division Fermat's little theorem.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
CSE 340: Review (at last!) Measuring The Complexity Complexity is a function of the size of the input O() Ω() Θ() Complexity Analysis “same order” Order.
MA/CSSE 473 Day 34 MST details: Kruskal's Algorithm Prim's Algorithm.
1 Chapter 4 Generating Permutations and Combinations.
Now, Chapter 5: Decrease and Conquer Reduce problem instance to smaller instance of the same problem and extend solution Solve smaller instance Extend.
MA/CSSE 473 Day 07 Euclid's Algorithm. MA/CSSE 473 Day 07 Student Questions Review topics not covered in class Euclid's algorithm (if there is time) extended.
MA/CSSE 473 Day 19 Subset Generation. MA/CSSE 473 Day 19 HW 7 due today Exam 1 Thursday There will be significant time for your questions in tomorrow's.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
Chapter 1 Algorithms with Numbers. Bases and Logs How many digits does it take to represent the number N >= 0 in base 2? With k digits the largest number.
MA/CSSE 473 Day 09 Modular Division Revisited Fermat's Little Theorem Primality Testing.
MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.
MA/CSSE 473 Day 14 Strassen's Algorithm: Matrix Multiplication Decrease and Conquer DFS.
MA/CSSE 473 Day 05 More induction Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 11 Knuth interview Amortization (growable Array) Brute Force Examples.
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 9 Primality Testing Encryption Intro.
MA/CSSE 473 Day 15 Return Exam Student questions Towers of Hanoi
MA/CSSE 473 Day 12 Interpolation Search Insertion Sort quick review
MA/CSSE 473 Day 05 Factors and Primes Recursive division algorithm.
MA/CSSE 473 Day 13 Finish Topological Sort Permutation Generation
MA/CSSE 473 Day 10 Data Encryption RSA.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis
Chapter 6: Transform and Conquer
Presentation transcript:

MA/CSSE 473 Day 13 Permutation Generation

MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation

Exam 1 If you want additional practice problems for Tuesday's exam: –The "not to turn in" problems from various assignments –Feel free to post your solutions in a Piazza discussion forum and ask your classmates if they think it is correct Allowed for exam: Calculator, one piece of paper (1 sided, handwritten) See the exam specification document, linked from the exam day on the schedule page.

About the exam Mostly it will test your understanding of things in the textbook and things we have discussed in class. Will not require a lot of creativity (it's hard to do much of that in 50 minutes). Many short questions, a few calculations. –Perhaps some T/F/IDK questions (example: 5/0/3) You may bring a calculator. And a piece of paper (handwritten on one side). I will give you the Master Theorem if you need it. Time will be a factor! First do the questions you can do quickly

Possible Topics for Exam Formal definitions of O, , . Master Theorem Fibonacci algorithms and their analysis Efficient numeric multiplication Proofs by induction (ordinary, strong) Trominoes Extended Binary Trees Modular multiplication, exponentiation Extended Euclid algorithm Modular inverse Fermat's little theorem Rabin-Miller test Random Prime generation RSA encryption What would Donald (Knuth) say?

Possible Topics for Exam Brute Force algorithms Selection sort Insertion Sort Amortized efficiency analysis Analysis of growable array algorithms Binary Search Binary Tree Traversals Basic Data Structures (Section 1.4) Graph representations BFS, DFS, DAGs & topological sort

COMBINATORIAL OBJECT GENERATION Permutations Subsets

Combinatorial Object Generation Generation of permutations, combinations, subsets. This is a big topic in CS We will just scratch the surface of this subject. –Permutations of a list of elements (no duplicates) –Subsets of a set

Permutations We generate all permutations of the numbers 1..n. –Permutations of any other collection of n distinct objects can be obtained from these by a simple mapping. How would a "decrease by 1" approach work? –Find all permutations of 1.. n-1 –Insert n into each position of each such permutation –We'd like to do it in a way that minimizes the change from one permutation to the next. –It turns out we can do it so that we always get the next permutation by swapping two adjacent elements.

First approach we might think of for each permutation of 1..n-1 –for i=0..n-1 insert n in position i That is, we do the insertion of n into each smaller permutation from left to right each time However, to get "minimal change", we alternate: –Insert n L-to-R in one permutation of 1..n-1 –Insert n R-to-L in the next permutation of 1..n-1 –Etc.

Example Bottom-up generation of permutations of 123 Example: Do the first few permutations for n=4

Johnson-Trotter Approach integrates the insertion of n with the generation of permutations of 1..n-1 Does it by keeping track of which direction each number is currently moving The number k is mobile if its arrow points to an adjacent element that is smaller than itself In this example, 4 and 3 are mobile

Johnson-Trotter Approach The number k is mobile if its arrow points to an adjacent element that is smaller than itself. In this example, 4 and 3 are mobile To get the next permutation, exchange the largest mobile number (call it k) with its neighbor Then reverse directions of all numbers that are larger than k. Initialize: All arrows point left Work with a partner on Q1

Johnson-Trotter Driver

Johnson-Trotter background code

Johnson-Trotter major methods

Lexicographic Permutation Generation Generate the permutations of 1..n in "natural" order. Let's do it recursively.

Lexicographic Permutation Code

Permutations and order Given a permutation of 0, 1, …, n-1, can we directly find the next permutation in the lexicographic sequence? Given a permutation of 0..n-1, can we determine its permutation sequence number? numberpermutationnumberpermutation Given n and i, can we directly generate the i th permutation of 0, …, n-1?

Discovery time (with a partner) Which permutation follows each of these in lexicographic order? – –Try to write an algorithm for generating the next permutation, with only the current permutation as input. If the lexicographic permutations of the numbers [0, 1, 2, 3, 4, 5] are numbered starting with 0, what is the number of the permutation 14032? –General form? How to calculate efficiency? In the lexicographic ordering of permutations of [0, 1, 2, 3, 4, 5], which permutation is number 541? –How to calculate efficiently?