CS1022 Computer Programming & Principles

Slides:



Advertisements
Similar presentations
CS1022 Computer Programming & Principles
Advertisements

Great Theoretical Ideas in Computer Science.
Counting Principles The Fundamental Counting Principle: If one event can occur m ways and another can occur n ways, then the number of ways the events.
Counting and Probability The outcome of a random process is sure to occur, but impossible to predict. Examples: fair coin tossing, rolling a pair of dice,
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
Discrete Structures & Algorithms Counting Counting I: One-To-One Correspondence and Choice Trees.
Today Today: Reading: –Read Chapter 1 by next Tuesday –Suggested problems (not to be handed in): 1.1, 1.2, 1.8, 1.10, 1.16, 1.20, 1.24, 1.28.
1 Section 5.1 Discrete Probability. 2 LaPlace’s definition of probability Number of successful outcomes divided by the number of possible outcomes This.
Combinations We should use permutation where order matters
Statistics Lecture 5. Last class: measures of spread and box-plots Last Day - Began Chapter 2 on probability. Section 2.1 These Notes – more Chapter.
Chapter 5 Section 5 Counting Techniques.
5.5 Counting Techniques. More Challenging Stuff  The classical method, when all outcomes are equally likely, involves counting the number of ways something.
4. Counting 4.1 The Basic of Counting Basic Counting Principles Example 1 suppose that either a member of the faculty or a student in the department is.
Discrete Math for CS Chapter 6: Combinatorics. Discrete Math for CS How to Count: Combinatorics is about counting. Pigeonhole was about counting too.
Section 2: The Multiplication Rule Consider the game of tossing a coin, then rolling a die, then picking a card. One possible event would be (H, 2, 2clubs).
Counting and Probability Sets and Counting Permutations & Combinations Probability.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Combinatorics.
NA387 Lecture 5: Combinatorics, Conditional Probability
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Copyright © Cengage Learning. All rights reserved. CHAPTER 9 COUNTING AND PROBABILITY.
Topics to be covered: Produce all combinations and permutations of sets. Calculate the number of combinations and permutations of sets of m items taken.
Binomial Coefficients, Inclusion-exclusion principle
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
10.3 – Using Permutations and Combinations Permutation: The number of ways in which a subset of objects can be selected from a given set of objects, where.
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
March 10, 2015Applied Discrete Mathematics Week 6: Counting 1 Permutations and Combinations How many different sets of 3 people can we pick from a group.
Permutations, Combinations, and Counting Theory AII.12 The student will compute and distinguish between permutations and combinations and use technology.
1 Lecture 4 (part 1) Combinatorics Reading: Epp Chp 6.
March 10,  Counting  Fundamental Counting principle  Factorials  Permutations and combinations  Probability  Complementary events  Compound.
Chapter 7 Logic, Sets, and Counting Section 4 Permutations and Combinations.
Simple Arrangements & Selections. Combinations & Permutations A permutation of n distinct objects is an arrangement, or ordering, of the n objects. An.
Lesson  The numerator and denominator of a theoretical probability are numbers of possibilities.  Sometimes those possibilities follow regular.
Sullivan Algebra and Trigonometry: Section 14.2 Objectives of this Section Solve Counting Problems Using the Multiplication Principle Solve Counting Problems.
Quiz Plot the point: (-4, 2, -3) in the Cartesian space. Find the midpoint between the 2 points: P(1, 5, -7) and Q(-5, 3, -3) 3. Find the distance.
Permutations and Combinations
Discrete Mathematics Lecture # 25 Permutation & Combination.
Discrete Mathematics, 1st Edition Kevin Ferland Chapter 6 Basic Counting 1.
Permutations, Combinations, and Counting Theory
Counting Techniques Tree Diagram Multiplication Rule Permutations Combinations.
HAWKES LEARNING Students Count. Success Matters. Copyright © 2015 by Hawkes Learning/Quant Systems, Inc. All rights reserved. Section 7.2 Counting Our.
 Counting  Fundamental Counting principle  Factorials  Permutations and combinations  Probability  Complementary events  Compound events  Independent.
2/24/20161 One, two, three, we’re… Counting. 2/24/20162 Basic Counting Principles Counting problems are of the following kind: “How many different 8-letter.
Copyright © Peter Cappello 2011 Simple Arrangements & Selections.
COUNTING Permutations and Combinations. 2Barnett/Ziegler/Byleen College Mathematics 12e Learning Objectives for Permutations and Combinations  The student.
EXIT NEXT Click one of the buttons below or press the enter key BACKTOPICSEXIT NEXT Click one of the buttons below or press the enter key BACKTOPICS.
SECTION 5.4 COUNTING. Objectives 1. Count the number of ways a sequence of operations can be performed 2. Count the number of permutations 3. Count the.
13 Lesson 1 Let Me Count the Ways Fundamental Counting Principle, Permutations & Combinations CP Probability and Statistics FA 2014 S-ID.1S-CP.3S-CP.5.
Example A standard deck of 52 cards has 13 kinds of cards, with four cards of each of kind, one in each of the four suits, hearts, diamonds, spades, and.
CS1022 Computer Programming & Principles
The Multiplication Rule
The Pigeonhole Principle
MATH 2311 Section 2.1.
COCS DISCRETE STRUCTURES
Section 8.3 PROBABILITY.
Chapter 0.4 Counting Techniques.
CS100: Discrete structures
COUNTING AND PROBABILITY
8.3 Counting Apply the fundamental counting principle
Set, Combinatorics, Probability & Number Theory
Chapter 7 Logic, Sets, and Counting
Counting I: One-To-One Correspondence and Choice Trees
Basic Counting.
COUNTING AND PROBABILITY
Permutations and Combinations
Representations of Integers
QUANTITATIVE METHODS 1 SAMIR K. SRIVASTAVA.
Using Permutations and Combinations
Applied Combinatorics, 4th Ed. Alan Tucker
Counting I: Choice Trees and Correspondences
10.3 – Using Permutations and Combinations
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 1 Combinatorics

Plan of lecture Motivation Addition principle Multiplication principle Analysing selection problems k-Samples k-Permutations k-Combinations k-Selections Examples CS1022

Why combinatorics? We sometimes need to consider the question How many elements are there in set A? If too many elements in a set, and we need to process the set, then this might take too long What’s “too long”? Example: how many outfits can one wear? Blue trousers and yellow shirt Black trousers and yellow shirt Etc. When we are proposing a computational solution we need to think of feasible solutions In realistic situations, will the program finish in “good time”? CS1022

A scenario: timetabling Every term we organise your timetable Day/time for lectures, practicals, etc. Compulsory modules must be allowed Not all choices possible, though How many ways are there to Arrange lecture, practical and lab times For all modules, for the whole university, Using up all time slots, 9AM-5PM? Answer: many! A program to compute a timetable needs to consider every option It is going to take a long time... International timetabling competition! CS1022

Addition principle Disjoint choices/events don’t influence one another Choice of cakes in a shop – first choice influences second one as there will be fewer cakes Throwing a die twice – 2nd time not influenced by 1st time Suppose A and B disjoint choices/events The number of options/outcomes for A is n1 The number of options/outcomes for B is n2 Total number of options/outcomes for A or B is n1  n2 CS1022

Multiplication principle Suppose a sequence of k choices/events With n1 options/outcomes for 1st choice/event With n2 options/outcomes for 2nd choice/event ... With nk options/outcomes for kth choice/event Total number of possible options/outcomes for the sequence is n1  n2  ...  nk CS1022

Addition principle with sets Suppose A is the set of n1 options/outcomes Suppose B is the set of n2 options/outcomes Sets A and B are disjoint, that is, A  B   So |A  B| |A|  |B| That is, A  B contains n1  n2 elements There are n1  n2 possible outcomes for A or B CS1022

Multiplication principle with sets We can “interpret” multiplication principle in terms of sets too Let A1 be set of n1 options/outcomes for 1st choice/event Let A2 be set of n2 options/outcomes for 2nd choice/event ... Let Ak be set of nk options/outcomes for kth choice/event Sequence of k events is an element of Cartesian product A1  A2  ...  Ak Set has cardinality |A1|  |A2|  ...  |Ak| CS1022

Analysing information needs Suppose we need to create a way to identify cars What kind of licence plate would you propose? Some ways are better than others How many cars could we licence with a 6-digit licence? Answer: 1,000,000, that is from 000000 to 999999 UK: 40,000,000 vehicles so we need more digits... Alternative – licence with 4 letters and 3 digits Examples: ABCD 123, GHHH 234, etc. How many cars can we licence? Answer: 26  26  26  26  10  10  10 = 456,976,000 CS1022

Analysing selection problems (1) Suppose we are offered 3 kinds of sweets Aniseed drops (A) Butter mints (B) and Cherry drops (C) How many ways can we choose 2 sweets? Can we choose the same sweet twice? (AA, BB or CC?) Does the order matter? (Is BA the same as AB?) CS1022

Analysing selection problems (2) Cases to consider Repeats allowed and order matters 9 possibilities: AA, AB, AC, BA, BB, BC, CA, CB, CC Repeats allowed and order does not matter 6 possibilities: AA, AB, AC, BB, BC, CC Repeats not allowed and order matters 6 possibilities: AB, AC, BA, BC, CA, CB Repeats not allowed and order does not matter 3 possibilities: AB, AC, BC CS1022

n  n  ...  n = nk possible k-samples Consider Selection of k objects from a set of n objects where Order matters and repetition is allowed Any such selection is called a k-sample Since repetition is allowed, There are n ways of choosing the 1st object, and There are n ways of choosing the 2nd object, and so on Until all k objects have been selected By the multiplication principle this gives n  n  ...  n = nk possible k-samples k CS1022

P(n, k)  n(n – 1)(n – k  1)  n!/ (n – k)! k-Permutations (1) Consider Selection of k objects from a set of n objects where Order matters and repetition is not allowed Any such selection is called a k-permutation Total number of k-permutations is denoted by P(n, k) Since repetition is not allowed, There are n ways of choosing the 1st object There are (n – 1) ways of choosing the 2nd object There are (n – 2) ways of choosing the 3rd object, and so on Up to (n – k  1) ways of choosing the kth object By the multiplication principle this gives P(n, k)  n(n – 1)(n – k  1)  n!/ (n – k)! possible k-permutations CS1022

k-Permutations (2) How many 4-letter “words” can we write with distinct letters from the set a, g, m, o, p, r? Solution: A “word” is any ordered selection of 4 different letters P(n, k)  n! (n – k)! We have in our scenario n  6 and k  4, so we have P(6, 4)  6!/ (6 – 4)!  6!/2!  (6  5  4  3  2  1)/(2  1)  (6  5  4  3  2  1)/(2  1)  360 possible k-permutations CS1022

k-Combinations (1) Consider Selection of k objects from a set of n objects where Order does not matter and repetition is not allowed Any such selection is called a k-combination Total number of k-combinations is denoted by C(n, k) By the multiplication principle: The number of permutations of k distinct objects selected from n objects is The number of unordered ways to select the objects multiplied by the number of ways to order them Hence, P(n, k)  C(n, k)  k! and so there are C(n, k)  P(n, k)  n! k! (n – k)! k! possible k-combinations CS1022

k-Selection (1) Consider Any such selection is called a k-selection Selection of k objects from a set of n objects where Order does not matter and repetition is allowed Any such selection is called a k-selection Since selection is unordered, We arrange the k objects so that like objects grouped together and separate the groups with markers There are n ways of choosing the 2nd object, and so on CS1022

k-Selection (2) Example: unordered selection of 5 letters from collection a, b and c, with repetitions Selection of two a’s, one b and two c’s: aa|b|cc Selection of one a’s, and four c’s: a| |cccc Seven slots: five letters and two markers Different choices: ways to insert 2 markers into 7 slots That is, C(7, 2) CS1022

(n – 1) markers and k objects k-Selection (3) Unordered selection of k objects from a set of n objects with repetition allowed requires (n – 1) markers and k objects Therefore, there are (n – 1)  k slots to fill The number of k-selections is the number of ways of putting (n – 1) markers into the (n – 1)  k slots Therefore number of k-selections from n objects is C((n  k – 1), (n – 1))  (n  k – 1)! ((n  k – 1) – (n – 1))! (n – 1)!  (n  k – 1)! k! (n – 1)! CS1022

k-Selection (4) Five dice are thrown. How many different outcomes are possible? Solution: Each of the dice shows one of six outcomes If 5 dice are thrown, the number of outcomes is the unordered selection of 5 objects with repetition allowed C((n  k – 1), (n – 1)), with n  6 and k  5 This gives C((6  5 – 1), (6 – 1))  C(10, 5)  10!/(5! 5!)  252 CS1022

Summarising... What we have so far can be summarised as We need to analyse the problem to choose formula They all need as input n and k If we choose the wrong formula, we still get a result... But the result will not be the right answer! Order matters Order does not matter Elements repeated k-sample: nk k-selection: Elements not repeated k-permutation: k-combination: CS1022

Example: National Lottery (1) Twice-weekly draw selects 6 different numbers Random selection from {1, 2, ..., 49} People pick their numbers before draw (and pay for this) Let’s calculate the odds of hitting the jackpot Winning numbers: one of the unordered selection of six numbers from 49 possibilities That is, C(49, 6) = 13,983,816 different ways The odds are 1 to 13,983,816 CS1022

Example: National Lottery (2) Smaller prizes for getting 5, 4 or 3 numbers right If you choose exactly 3 numbers right you get £10 What are the odds of getting £10? Pre-selection of numbers means choosing three correct and three incorrect numbers There are C(6,3) ways of selecting 3 correct numbers There are C(43,3) ways of selecting 3 incorrect numbers Total number of winning combinations is Odds of 13,983,816/246,820  57 to 1 CS1022

Example: Choosing people (1) 12 candidates for a committee of 5 people How many committees? Order does not matter Elements not repeated There are possible committees Order matters Order does not matter Elements repeated nk Elements not repeated CS1022

Example: Choosing people (2) We want to know about two people, Mary & Peter How many committees contain both Mary & Peter? Reasoning If Mary & Peter are in the committee, then we need only consider the remaining 3 people to complete the group There are 10 people to fill in the 3 places Order does not matter Elements not repeated There are possible committees with Mary and Peter in them Order matters Order does not matter Elements repeated nk Elements not repeated CS1022

Example: Choosing people (3) How many do not contain neither Mary or Peter? Reasoning If Mary & Peter are excluded, then we have to select 5 people from remaining 10 people Order does not matter Elements not repeated There are possible committees without Mary and Peter Order matters Order does not matter Elements repeated nk Elements not repeated CS1022

Further reading R. Haggarty. “Discrete Mathematics for Computing”. Pearson Education Ltd. 2002. (Chapter 6) Wikipedia’s entry Wikibooks entry CS1022