21 Permutations and Combinations

  • View
    212

  • Download
    0

Embed Size (px)

Text of 21 Permutations and Combinations

  • 8/2/2019 21 Permutations and Combinations

    1/27

    11

    Permutations andPermutations and

    CombinationsCombinationsCS/APMA 202CS/APMA 202

    Rosen section 4.3Rosen section 4.3Aaron BloomfieldAaron Bloomfield

  • 8/2/2019 21 Permutations and Combinations

    2/27

    22

    Permutations vs. CombinationsPermutations vs. Combinations

    BothBoth areare waysways toto countcount thethe possibilitiespossibilities

    TheThe differencedifference betweenbetween themthem isis whetherwhether orderordermattersmatters oror notnot

    ConsiderConsider aa pokerpoker handhand:: AA,, 55,, 77,, 1010,, KK

    IsIs thatthat thethe samesame handhand asas:: KK,, 1010,, 77,, 55,, AA

    DoesDoes thethe orderorder thethe cardscards areare handedhanded outoutmatter?matter? IfIf yes,yes, thenthen wewe areare dealingdealing withwith permutationspermutations

    IfIf no,no, thenthen wewe areare dealingdealing withwith combinationscombinations

  • 8/2/2019 21 Permutations and Combinations

    3/27

    33

    PermutationsPermutations

    AA permutationpermutation isis anan orderedordered arrangementarrangement ofof thetheelementselements ofof somesome setset SS LetLet SS== {a,{a, b,b, c}c}

    c,c, b,b, aa isis aa permutationpermutation ofof SS b,b, c,c, aa isis aa differentdifferent permutationpermutation ofof SS

    AnAn rr--permutationpermutation isis anan orderedordered arrangementarrangement ofofrrelementselements ofof thethe setset

    AA,, 55,, 77,, 1010,, KK isis aa 55--permutationpermutation ofof thethe setset ofofcardscards

    TheThe notationnotation forfor thethe numbernumber ofof rr--permutationspermutations::PP((nn,,rr)) TheThe pokerpoker handhand isis oneone ofof P(P(5252,,55)) permutationspermutations

  • 8/2/2019 21 Permutations and Combinations

    4/27

    44

    PermutationsPermutations

    NumberNumber ofof pokerpoker handshands ((55 cards)cards)::

    PP((5252,,55)) == 5252**5151**5050**4949**4848 == 311311,,875875,,200200

    NumberNumber ofof (initial)(initial) blackjackblackjack handshands ((22 cards)cards)::

    PP((5252,,22)) == 5252**5151 == 22,,652652rr--permutationpermutation notationnotation:: PP((nn,,rr))

    TheThe pokerpoker handhand isis oneone ofof P(P(5252,,55)) permutationspermutations

    )1)...(2)(1(),( ! rnnnnrnP

    )!(

    !

    rn

    n

    !

    !

    !

    n

    rni

    i

    1

  • 8/2/2019 21 Permutations and Combinations

    5/27

    55

    rr--permutations examplepermutations example

    HowHow manymany waysways areare therethere forfor55 peoplepeople inin

    thisthis classclass toto givegive presentations?presentations?

    ThereThere areare 2727 studentsstudents inin thethe classclass

    P(P(2727,,55)) == 2727**2626**2525**2424**2323 == 99,,687687,,600600

    NoteNote thatthat thethe orderorder theythey gogo inin doesdoes mattermatter ininthisthis example!example!

  • 8/2/2019 21 Permutations and Combinations

    6/27

    66

    Permutation formula proofPermutation formula proof

    ThereThere areare nn waysways toto choosechoose thethe firstfirst

    elementelement

    nn--11 waysways toto choosechoose thethe secondsecond nn--22 waysways toto choosechoose thethe thirdthird

    nn--rr++11 waysways toto choosechoose thethe rrthth elementelement

    ByBy thethe productproduct rule,rule, thatthat givesgives usus::

    PP((nn,,rr)) == nn((nn--11)()(nn--22))((nn--rr++11))

  • 8/2/2019 21 Permutations and Combinations

    7/27

    77

    Permutations vs.Permutations vs. rr--permutationspermutations

    rr--permutationspermutations:: ChoosingChoosing anan orderedordered 55

    cardcard handhand isis PP((5252,,55))

    When

    When peoplepeople saysay permutations,permutations, theythey almostalmostalwaysalways meanmean rr--permutationspermutations

    ButBut thethe namename cancan referrefer toto bothboth

    PermutationsPermutations:: ChoosingChoosing anan orderorder forfor allall 5252

    cardscards isis PP((5252,,5252)) == 5252!!

    Thus,Thus, PP((nn,,nn)) == nn!!

  • 8/2/2019 21 Permutations and Combinations

    8/27

    88

    Rosen, section 4.3, question 3Rosen, section 4.3, question 3

    HowHow manymany permutationspermutations ofof {a,{a, b,b, c,c, d,d, e,e, f,f, g}g}endend withwith a?a? NoteNote thatthat thethe setset hashas 77 elementselements

    TheThe lastlast charactercharacter mustmust bebe aa TheThe restrest cancan bebe inin anyany orderorder

    Thus,Thus, wewe wantwant aa 66--permutationpermutation onon thethe setset {b,{b, c,c,

    d,d, e,e, f,f, g}g}P(P(66,,66)) == 66!! == 720720

    WhyWhy isis itit notnot P(P(77,,66)?)?

  • 8/2/2019 21 Permutations and Combinations

    9/27

    99

    CombinationsCombinations

    WhatWhat ifif orderorderdoesntdoesnt matter?matter?

    InIn poker,poker, thethe followingfollowing twotwo handshands areare equivalentequivalent::

    AA,, 55,, 77,, 1010,, KK

    KK,, 1010,, 77,, 55,, AA

    TheThe numbernumber ofof rr--combinationscombinations ofof aa setset withwith nn

    elements,elements, wherewhere nn isis nonnon--negativenegative andand 00rrnn isis::

    )!(!

    !),(

    rnr

    nrnC

    !

  • 8/2/2019 21 Permutations and Combinations

    10/27

    1010

    Combinations exampleCombinations example

    HowHow manymany differentdifferent pokerpoker handshands areare therethere

    ((55 cards)?cards)?

    HowHow manymany differentdifferent (initial)(initial) blackjackblackjack

    handshands areare there?there?

    2,598,960!47*1*2*3*4*5

    !47*48*49*50*51*52!47!5!52

    )!552(!5!52)5,52( !!!

    !C

    1,3261*2

    51*52

    !50!2

    !52

    )!252(!2

    !52)2,52( !!!

    !C

  • 8/2/2019 21 Permutations and Combinations

    11/27

    1111

    Combination formula proofCombination formula proof

    LetLet CC((5252,,55)) bebe thethe numbernumber ofof waysways toto generategenerate

    unorderedunordered pokerpoker handshands

    TheThe numbernumber ofof orderedordered pokerpoker handshands isis PP((5252,,55)) ==

    311311,,875875,,200200

    TheThe numbernumber ofof waysways toto orderorder aa singlesingle pokerpoker

    handhand isis PP((55,,55)) == 55!! == 120120

    TheThe totaltotal numbernumber ofof unorderedunordered pokerpoker handshands isisthethe totaltotal numbernumber ofof orderedordered handshands divideddivided byby thethe

    numbernumber ofof waysways toto orderorder eacheach handhand

    Thus,Thus, CC((5252,,55)) == PP((5252,,55)/)/PP((55,,55))

  • 8/2/2019 21 Permutations and Combinations

    12/27

    1212

    Combination formula proofCombination formula proof

    LetLet CC((nn,,rr)) bebe thethe numbernumber ofof waysways toto generategenerateunorderedunordered combinationscombinations

    TheThe numbernumber ofof orderedordered combinationscombinations (i(i..ee.. rr--

    permutations)permutations) isis PP((nn,,rr))TheThe numbernumber ofof waysways toto orderorder aa singlesingle oneone ofofthosethose rr--permutationspermutations PP((r,rr,r))

    TheThe totaltotal numbernumber ofof unorderedunordered combinationscombinations isis

    thethe totaltotal numbernumber ofof orderedordered combinationscombinations (i(i..ee.. rr--permutations)permutations) divideddivided byby thethe numbernumber ofof waysways totoorderorder eacheach combinationcombination

    Thus,Thus, CC((n,rn,r)) == PP((n,rn,r)/)/PP((r,rr,r))

  • 8/2/2019 21 Permutations and Combinations

    13/27

    1313

    Combination formula proofCombination formula proof

    NoteNote thatthat thethe textbooktextbook explainsexplains itit slightlyslightlydifferently,differently, butbut itit isis samesame proofproof

    )!(!

    !

    )!/(!

    )!/(!

    ),(

    ),(),(

    rnr

    n

    rrr

    rnn

    rrP

    rnPrnC

    !

    !!

  • 8/2/2019 21 Permutations and Combinations

    14/27

    1414

    Computer bugsComputer bugs

  • 8/2/2019 21 Permutations and Combinations

    15/27

    1515

    Rosen, section 4.3, question 11Rosen, section 4.3, question 11

    HowHow manymany bitbit stringsstrings ofof lengthlength 1010 containcontain::

    a)a) exactlyexactly fourfour 11s?s?FindFind thethe positionspositions ofof thethe fourfour 11ss

    DoesDoes thethe orderorder ofof thesethese positionspositions matter?matter?Nope!Nope!PositionsPositions 22,, 33,, 55,, 77 isis thethe samesame asas positionspositions 77,, 55,, 33,, 22

    Thus,Thus, thethe answeranswer isis CC((1010,,44)) == 210210

    b)b) atat mostmost fourfour 11s?s?

    ThereThere cancan bebe 00,, 11,, 22,, 33,, oror 44 occurrencesoccurrences ofof 11Thus,Thus, thethe answeranswer isis::

    CC((1010,,00)) ++ CC((1010,,11)) ++ CC((1010,,22)) ++ CC((1010,,33)) ++ CC((1010,,44))

    == 11++1010++4545++120120++210210

    == 386386

  • 8/2/2019 21 Permutations and Combinations

    16/27

    1616

    End of lecture on 30 March 2005End of lecture on 30 March 2005

  • 8/2/2019 21 Permutations and Combinations

    17/27

    1717

    Rosen, section 4.3, question 11Rosen, section 4.3, question 11

    HowHow manymany bitbit stringsstrings ofof lengthlength 1010 containcontain::

    c)c) atat leastleast fourfour 11s?s?ThereThere cancan bebe 44,, 55,, 66,, 77,, 88,, 99,, oror 1010 occurrencesoccurrences ofof 11

    Thus,Thus, thethe answeranswer isis::CC((1010,,44)) ++ CC((1010,,55)) ++ CC((1010,,66)) ++ CC((1010,,77)) ++ CC((1010,,88)) ++ CC((1010,,99))++ CC((1010,,1010))

    == 210210++252252++210210++120120++4545++1010++11

    == 848848

    AlternativeAlternative answeranswer:: subtractsubtract fromfrom 221010 thethe numbernumber ofof

    stringsstrings