MA/CSSE 473 Day 18 Permutations by lexicographic order number.

Slides:



Advertisements
Similar presentations
Foundations of Cryptography Lecture 10 Lecturer: Moni Naor.
Advertisements

Order Analysis of Algorithms Debdeep Mukhopadhyay IIT Madras.
Sub Exponential Randomize Algorithm for Linear Programming Paper by: Bernd Gärtner and Emo Welzl Presentation by : Oz Lavee.
Analysis & Design of Algorithms (CSCE 321)
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
Review for midterm exam Dilshad M. Shahid Spring NYU.
1 Lecture 23 Decision problems about regular languages –Programs can be inputs to other programs FSA’s, NFA’s, regular expressions –Basic problems are.
Colored Necklace Bisection Victor Kostyuk Advisor: Michael Capalbo.
1.7 Arrays academy.zariba.com 1. Lecture Content 1.Basic Operations with Arrays 2.Console Input & Output of Arrays 3.Iterating Over Arrays 4.List 5.Cloning.
MA/CSSE 473 Day 22 Gray Code More Decrease and Conquer Algorithms No class Day 22 in because of Abby's broken arm.
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.
Patterns I CAN use algebraic expressions to solve numeric and geometric patterns.
PYTHON PROGRAMMING Week 10 – Wednesday. TERMS – CHAPTER 1 Write down definitions for these terms:  Computation  Computability  Computing  Artificial.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
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.
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
MA/CSSE 473 Day 17 Permutations by lexicographic order number.
Combinatorial Algorithms Reference Text: Kreher and Stinson.
CSCI 115 Chapter 3 Counting. CSCI 115 §3.1 Permutations.
RAIK 283: Data Structures & Algorithms
Design of Algorithms using Brute Force Approach. Primality Testing (given number is n binary digits)
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
5.6 Generating Permutations and Combinations Generating Permutations Many different algorithms have been developed to generate the n! permutations of this.
Happy Birthday Julia Courier New. USACO December Contest - Congratulations to Jon+Julia+Andy for promoting to gold And Johnny - 2th place in gold among.
Fall 2002CMSC Discrete Structures1 … and now for… Sequences.
Greedy Algorithms Input: Output: Objective: - make decisions “greedily”, previous decisions are never reconsidered Optimization problems.
1 Programming for Engineers in Python Autumn Lecture 12: Dynamic Programming.
Recursion. Math Review Given the following sequence: a 1 = 1 a n = 2*a n-1 OR a n+1 = 2*a n What are the values of the following? a 2 = a 3 = a 4 =
Sequences and Summations Section 2.4. Section Summary Sequences. – Examples: Geometric Progression, Arithmetic Progression Recurrence Relations – Example:
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Dynamic programming vs Greedy algo – con’t Input: Output: Objective: a number W and a set of n items, the i-th item has a weight w i and a cost c i a subset.
A. Levitin “Introduction to the Design & Analysis of Algorithms,” 3 rd ed., Ch. 1 ©2012 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved.
Combinatorics University of Akron Programming Team 9/23/2011.
8. DECISION STRUCTURES Rocky K. C. Chang October 18, 2015 (Adapted from John Zelle’s slides)
Lower bounds on data stream computations Seminar in Communication Complexity By Michael Umansky Instructor: Ronitt Rubinfeld.
Analysis & Design of Algorithms (CSCE 321)
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
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 21 In , Day 21 was the exam.
MA/CSSE 473 Day 16 Combinatorial Object Generation Permutations.
MA/CSSE 473 Day 10 Primality Testing. MA/CSSE 473 Day 10 In-class exam: Friday, Sept 28 –You may bring a two-sided 8.5x11 inch piece of paper containing.
3/16/20161 … and now for… Sequences. 3/16/20162 Sequences Sequences represent ordered lists of elements. A sequence is defined as a function from a subset.
MA/CSSE 473 Day 12 Amortization (growable Array) Knuth interview Brute Force Examples.
Domain & Range. Two Types of Relations Discrete Continuous.
Programming Training Main Points: - More Fundamental algorithms on Arrays. - Reading / Writing from files - Problem Solving.
Theory of Computational Complexity Probability and Computing Ryosuke Sasanuma Iwama and Ito lab M1.
Ch3 /Lecture #4 Brute Force and Exhaustive Search 1.
CompSci Today’s Topics Computer Science Noncomputability Upcoming Special Topic: Enabled by Computer -- Decoding the Human Genome Reading Great.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Advanced Algorithms Analysis and Design By Dr. Nazir Ahmad Zafar Dr Nazir A. Zafar Advanced Algorithms Analysis and Design.
Efficient Huffman Decoding Aggarwal, M. and Narayan, A., International Conference on Image Processing, vol. 1, pp. 936 – 939, 2000 Presenter :Yu-Cheng.
Generating Permutations and Combinations “Traveling Salesman Problem” – A salesman must visit 6 cities; what’s the best order in which to visit them? Assume.
Introduction to Algorithms: Brute-Force Algorithms.
MA/CSSE 473 Day 15 Return Exam Student questions Towers of Hanoi
Data Structures and Algorithm Analysis Lecture 24
An Iterative FFT We rewrite the loop to calculate nkyk[1] once
MA/CSSE 473 Day 13 Finish Topological Sort Permutation Generation
Introduction Algorithms Order Analysis of Algorithm
Data Structures and Algorithms
What is an algorithm? An algorithm is a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate.
Introduction to The Design & Analysis of Algorithms
Main Points: - More Fundamental Algorithms on Arrays.
Time Series Filtering Time Series
Design & Analysis of Algorithms Combinatorial optimization
CSE 2010: Algorithms and Data Structures Algorithms
Recall Brute Force as a Problem Solving Technique
4-9问题的形式化描述.
Challenge Guide Grade Code Type Slides
Terminology and Symbols
Presentation transcript:

MA/CSSE 473 Day 18 Permutations by lexicographic order number

MA/CSSE 473 Day 18 Today's in-class quiz is a continuation of yesterday's Tuesday will be another "ask questions prior to the exam" day. Exam details are in previous PowerPoint slides. Today's topics: Permutations by lexicographic order number Generating subsets of a set.

Horner's method 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?

Yesterday's Discovery 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.

Lexicographic Permutation class These are the basics of the class setup. The next() method provides an iterator over the permutations. How should it get from one permutation to the next?

Main permutation method

More discoveries 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] are numbered starting with 0, what is the number of the permutation 14032? –General algorithm? How to calculate efficiency? In the lexicographic ordering of permutations of [0, 1, 2, 3, 4, 5], which permutation is number 541? –General algorithm? How to calculate efficiently? –Application: Generate a random permutation

Memoized factorial function

Find a permutation's sequence #

Find permutation from sequence #

All Subsets of a Set Sample Application: –Solving the knapsack problem –In the brute force approach, we try all subsets If A is a set, the set of all subsets is called the power set of A, and often denoted 2 A If A is finite, then So we know how many subsets we need to generate.

Generating Subsets of {a 1, …, a n } Decrease by one: Generate S n-1, the collection of the 2 n-1 subsets of {a 1, …, a n-1 } Then S n = S n-1  { S n-1  {a n } : s  S n-1 } Another approach: –Each subset of {a 1, …, a n } corresponds to an bit string of length n, where the i th bit it 1 iff a i is in the subset

Another approach: Each subset of {a 1, …, a n } corresponds to an bit string of length n, where the i th bit is 1 if and only if a i is in the subset def allSubsets(a): n = len(a) subsets=[] for i in range(2**n): subset = [] current = i for j in range (n): if current % 2 == 1: subset += [a[j]] current /= 2 subsets += [subset] return subsets Output: [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]