CS1022 Computer Programming & Principles

Slides:



Advertisements
Similar presentations
You have been given a mission and a code. Use the code to complete the mission and you will save the world from obliteration…
Advertisements

Fundamentals of Probability
Introductory Mathematics & Statistics for Business
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Multiplying binomials You will have 20 seconds to answer each of the following multiplication problems. If you get hung up, go to the next problem when.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
Addition Facts
CS1512 Foundations of Computing Science 2 Week 3 (CSD week 32) Probability © J R W Hunter, 2006, K van Deemter 2007.
5.1 Probability of Simple Events
4-1 Chapter 4 Counting Techniques.
1 Combination Symbols A supplement to Greenleafs QR Text Compiled by Samuel Marateck ©2009.
Chris Morgan, MATH G160 January 30, 2012 Lecture 9 Chapter 4.1: Combinations 1.
Chris Morgan, MATH G160 January 25, 2012 Lecture 7 Chapter 4.1: Combinatorics and Basic Counting Rules 1.
1 Learning Objectives for Section 7.3 Basic Counting Principles After this lesson, you should be able to apply and use the addition principle. draw and.
ABC Technology Project
9.5 Counting Subsets of a Set: Combinations
Hash Tables.
Copyright © 2002 by Radhika Nagpal and Charles E. Leiserson. All rights reserved. October 30, L9-2.1 Mathematics for Computer Science MIT 6.042J/18.062J.
Business and Economics 6th Edition
1 Combinations & Counting II Samuel Marateck © 2009.
Basic Permutations and Combinations
Chapter 2.3 Counting Sample Points Combination In many problems we are interested in the number of ways of selecting r objects from n without regard to.
The Fundamental Counting Principle & Permutations
O X Click on Number next to person for a question.
Discrete Mathematics Math 6A Homework 5 Solution.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Do you have the Maths Factor?. Maths Can you beat this term’s Maths Challenge?
CS1022 Computer Programming & Principles Lecture 9.2 Boolean Algebra (2)
CS1022 Computer Programming & Principles Lecture 8.1 Digraphs (1)
CS1022 Computer Programming & Principles
CS1022 Computer Programming & Principles Lecture 7.1 Graphs (1)
Quantitative Methods Session – Permutation & Combination Pranjoy Arup Das.
Chapter 5 Test Review Sections 5-1 through 5-4.
Addition 1’s to 20.
25 seconds left…...
MATHCOUNTS TOOLBOX Facts, Formulas and Tricks
Week 1.
We will resume in: 25 Minutes.
Lecture 12 Permutations and Combinations CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine.
O X Click on Number next to person for a question.
Copyright © 2010, 2007, 2004 Pearson Education, Inc. Chapter 14 From Randomness to Probability.
Chapter 4 Systems of Linear Equations; Matrices
The Pigeonhole Principle Alan Kaylor Cline. The Pigeonhole Principle Statement Children’s Version: “If k > n, you can’t stuff k pigeons in n holes without.
CS Discrete Mathematical Structures
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.
Multiplication Rule. A tree structure is a useful tool for keeping systematic track of all possibilities in situations in which events happen in order.
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.
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.
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,
Set, Combinatorics, Probability & Number Theory Mathematical Structures for Computer Science Chapter 3 Copyright © 2006 W.H. Freeman & Co.MSCS Slides Set,
Fall 2002CMSC Discrete Structures1 One, two, three, we’re… Counting.
1 Lecture 4 (part 1) Combinatorics Reading: Epp Chp 6.
CSNB143 – Discrete Structure
Permutations and Combinations
Discrete Mathematics, 1st Edition Kevin Ferland Chapter 6 Basic Counting 1.
HAWKES LEARNING Students Count. Success Matters. Copyright © 2015 by Hawkes Learning/Quant Systems, Inc. All rights reserved. Section 7.2 Counting Our.
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.
Quiz: Draw the unit circle: Include: (1)All “nice” angles in degrees (2) All “nice” angles in radians (3) The (x, y) pairs for each point on the unit circle.
COCS DISCRETE STRUCTURES
Section 8.3 PROBABILITY.
CS1022 Computer Programming & Principles
COUNTING AND PROBABILITY
Set, Combinatorics, Probability & Number Theory
Presentation transcript:

CS1022 Computer Programming & Principles Lecture 6.1 Combinatorics (1)

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