CSE 21 Math for Algorithms and Systems Analysis Lecture 2 Lists Without Repe>>on
Review of Last Lecture Sets and Lists Sets are unordered collec>on Lists are ordered collec>ons Rule of product # of lists with c i choices for the ith element is Cartesian Product c 1 c 2...c n S 1 S 2... S n = {x x is an n-list with the ith element x i S i }
Review Problems Construct the set of all possible dis>nct sequences of heads and tails that can be generated by flipping a coin 100 >mes? How many are there? Generate the set of all cards in the standard 52 card deck where each card is represented as a list with the first element being the rank of the card and the second being the suit
Review of Last Lecture Rela>onship between Cartesian Product and rule of Product S 1 S 2...S n = S 1 S 2... S n Lexicographical Ordering (think ordering of integers) for a, b P, a < L b, iff i, a i <b i,a 1 = b 1...,a i 1 = b i 1
Example Problems Con>nued Suppose for a par>cular game you want to organize your cards by suit, construct the set of all cards in the 52 card deck such that lexicographical order arranges cards by suit.
Dic>onary Ordering (not covered last lecture) Defines an ordering over lists. Keep in mind the intui>on of alphabe>cal order over words. x< d y iff ( i s.t. x i < y i and x 1 = y 1,...x i 1 = y i 1 ) or ( x < y and x 1 = y 1,...x x = y x )
Rule of Sum Suppose we want to count the number of elements in a set T. If we can divide the set into n disjoint subsets ( T i T j =,i= j ) subsets such that, T 1... T n = T then the number of elements in T is: T = T 1 +...+ T n
Applying the Rule of Sum A license plate from a state A is composed of 7 digits {0 9} the license plates from state B are composed of 7 le`ers {a z} How many license plates in total are there between the two states: Solu>on: form two sets Set 1: all license plates from state A Set 2: all license plates from state B
Applying the Rule of Sum 2 (example problem) A license plate from a state A is composed of 7 digits {0 9} the license plates from state B are composed of 1 alpha- numeric character {0 9, a z} followed by 6 digits {0 9}. How many license plates in total are there from state A and state B?
Example Problem Construct the set of non- nega>ve integers less than 10,000 where each integer is represented as a list of digits (no leading 0 s allowed). How many elements are in this set?
Example Problem 2 Galac>c Names In a certain distant galaxy, the alphabet contains only five symbols which we will represent as A, E, R, S, T. (A and E are called vowels, while R, S and T are consonants). All names are 5 le`ers long, begin and end with consonants and contain at least two vowels. Adjacent consonants must be the same, while adjacent vowels must be different. How many names are there?
Example Problem 2 (con>nued)
Example Problem College Commi`ees We are making a commi`ee from 4 departments consis>ng of (5, 8, 10, and 20 members). The commi`ee consists of 3 people where each must be from a different department. How many commi`ees can be made?
K- Lists Without Repe>>on There are a total of k- lists that can be made from an n- set with no repeated elements (if k > n then the answer is 0) n! (n k)!
How can we derive this using the rule of product? We have n choices for the first element of the k- list We have n- 1 choices for the second element of the k- list. We have n- k+1 choices for the kth element of the k- list
Example Problems How many ways can we seat 5 people in a row? How many ways can commi`ees consis>ng of a president, vice president, and treasurer can we make from a pool of 10 candidates?
Example Problem 2 How many words with all le`ers dis>nct can be made from the le`ers in the word (SUPERFLUOUS)?
Circular Arrangements Two circular arrangements are dis>nct if and only if there exists an element that has a different lep neighbor in the two arrangements. How many circular arrangements of size n can be made from the elements of an n- set? Can we figure this out using the rule of product?
Circular Arrangements (workspace)
Introduc>on to Lists With a limited Number of Repeated Values How many ways can the le`ers in the word ERROR be rearranged?
Matlab Demo