21 Permutations and Combinations

Embed Size (px)

Citation preview

  • 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 withwith 00,, 11,, 22,, oror 33 occurrencesoccurrences ofof 11d)d) anan equalequal numbernumber ofof 11ss andand 00s?s?

    Thus,Thus, therethere mustmust bebe fivefive 00ss andand fivefive 11ss

    FindFind thethe positionspositions ofof thethe fivefive 11ss

    Thus,Thus, thethe answeranswer isis CC((1010,,55)) == 252252

  • 8/2/2019 21 Permutations and Combinations

    18/27

    1818

    Corollary 1Corollary 1

    LetLet nn andand rr bebe nonnon--negativenegative integersintegers withwith

    rr nn.. ThenThen CC((nn,,rr)) == CC((nn,,nn--rr))

    ProofProof::

    )!(!

    !),(

    rnr

    nrnC

    !

    ? A!)()!(

    !),(

    rnnrn

    nrnnC

    !

    )!(!

    !

    rnr

    n

    !

  • 8/2/2019 21 Permutations and Combinations

    19/27

    1919

    Corollary exampleCorollary example

    ThereThere areare C(C(5252,,55)) waysways toto pickpick aa 55--cardcard pokerpoker

    handhand

    ThereThere areare C(C(5252,,4747)) waysways toto pickpick aa 4747--cardcard handhand

    P(P(5252,,55)) == 22,,598598,,960960 == P(P(5252,,4747))

    WhenWhen dealingdealing 4747 cards,cards, youyou areare pickingpicking 55 cardscards

    toto notnot dealdeal AsAs opposedopposed toto pickingpicking 55 cardcard toto dealdeal

    Again,Again, thethe orderorder thethe cardscards areare dealtdealt inin doesdoes mattermatter

  • 8/2/2019 21 Permutations and Combinations

    20/27

    2020

    Combinatorial proofCombinatorial proof

    AA combinatorialcombinatorial proofproof isis aa proofproof thatthat usesuses countingcounting argumentsarguments totoproveprove aa theoremtheorem RatherRather thanthan somesome otherother methodmethod suchsuch asas algebraicalgebraic techniquestechniques

    Essentially,Essentially, showshow thatthat bothboth sidessides ofof thethe proofproof managemanage toto countcount thethe

    samesame objectsobjects

    InIn aa typicaltypical RosenRosen example,example, hehe doesdoes notnot dodo muchmuch withwith thisthis proofproofmethodmethod inin thisthis sectionsection WeWe willwill seesee moremore inin thethe nextnext sectionssections

    MostMost ofof thethe questionsquestions inin thisthis sectionsection areare phrasedphrased as,as, findfind outout howhowmanymany possibilitiespossibilities therethere areare ifif Instead,Instead, wewe couldcould phrasephrase eacheach questionquestion asas aa theoremtheorem::

    ProveProve therethere areare xxpossibilitiespossibilities ifif

    TheThe samesame answeranswer couldcould bebe modifiedmodified toto bebe aa combinatorialcombinatorial proofproof toto thethetheoremtheorem

  • 8/2/2019 21 Permutations and Combinations

    21/27

    2121

    Rosen, section 4.3, question 40Rosen, section 4.3, question 40

    HowHow manymany waysways areare therethere toto sitsit 66 peoplepeople aroundaround aa circularcircular table,table,

    wherewhere seatingsseatings areare consideredconsidered toto bebe thethe samesame ifif theythey cancan bebe

    obtainedobtained fromfrom eacheach otherother byby rotatingrotating thethe table?table?

    First,First, placeplace thethe firstfirst personperson inin thethe northnorth--mostmost chairchair OnlyOnly oneone possibilitypossibility

    ThenThen placeplace thethe otherother55 peoplepeople

    ThereThere areare P(P(55,,55)) == 55!! == 120120 waysways toto dodo thatthat

    ByBy thethe productproduct rule,rule, wewe getget 11**120120 ==120120

    AlternativeAlternative meansmeans toto answeranswer thisthis::

    ThereThere areare P(P(66,,66)=)=720720 waysways toto seatseat thethe 66 peoplepeople aroundaround thethe tabletable

    ForFor eacheach seating,seating, therethere areare 66 rotationsrotations ofof thethe seatingseating

    Thus,Thus, thethe finalfinal answeranswer isis 720720//66 == 120120

  • 8/2/2019 21 Permutations and Combinations

    22/27

    2222

    Rosen, section 4.3, question 42Rosen, section 4.3, question 42

    HowHow manymany waysways areare therethere forfor 44 horseshorses toto finishfinish ifif tiesties areare allowed?allowed? NoteNote thatthat orderorder doesdoes matter!matter!

    SolutionSolution byby casescases NoNo tiesties

    TheThe numbernumber ofof permutationspermutations isis P(P(44,,44)) == 44!! == 2424

    TwoTwo horseshorses tietieThereThere areare CC((44,,22)) == 66 waysways toto choosechoose thethe twotwo horseshorses thatthat tietie

    ThereThere areare PP((33,,33)) == 66 waysways forfor thethe groupsgroups toto finishfinish AA groupgroup isis eithereither aa singlesingle horsehorse oror thethe twotwo tyingtying horseshorses

    ByBy thethe productproduct rule,rule, therethere areare 66**66 == 3636 possibilitiespossibilities forfor thisthis casecase

    TwoTwo groupsgroups ofof twotwo horseshorses tietieThereThere areare CC((44,,22)) == 66 waysways toto choosechoose thethe twotwo winningwinning horseshorses

    TheThe otherother twotwo horseshorses tietie forfor secondsecond placeplace ThreeThree horseshorses tietie withwith eacheach otherother

    ThereThere areare CC((44,,33)) == 44 waysways toto choosechoose thethe twotwo horseshorses thatthat tietie

    ThereThere areare PP((22,,22)) == 22 waysways forfor thethe groupsgroups toto finishfinish

    ByBy thethe productproduct rule,rule, therethere areare 44**22 == 88 possibilitiespossibilities forfor thisthis casecase

    AllAll fourfour horseshorses tietieThereThere isis onlyonly oneone combinationcombination forfor thisthis

    ByBy thethe sumsum rule,rule, thethe totaltotal isis 2424++3636++66++88++11 == 7575

  • 8/2/2019 21 Permutations and Combinations

    23/27

    2323

    A last note on combinationsA last note on combinations

    AnAn alternativealternative (and(and moremore common)common) wayway toto

    denotedenote anan rr--combinationcombination::

    IllIll useuse C(C(nn,,rr)) wheneverwhenever possible,possible, asas itit isiseasiereasier toto writewrite inin PowerPointPowerPoint

    !

    r

    nrnC ),(

  • 8/2/2019 21 Permutations and Combinations

    24/27

    24

    Quick surveyQuick survey

    I felt I understood the material in this slide setI felt I understood the material in this slide set

    a)a) Very wellVery well

    b)b) With some review, Ill be goodWith some review, Ill be goodc)c) Not reallyNot really

    d)d) Not at allNot at all

  • 8/2/2019 21 Permutations and Combinations

    25/27

    25

    Quick surveyQuick survey

    The pace of the lecture for this slide set wasThe pace of the lecture for this slide set was

    a)a) FastFast

    b)b) About rightAbout rightc)c) A little slowA little slow

    d)d) Too slowToo slow

  • 8/2/2019 21 Permutations and Combinations

    26/27

    26

    Quick surveyQuick survey

    How interesting was the material in this slideHow interesting was the material in this slide

    set? Be honest!set? Be honest!

    a)a) Wow!T

    hat was SOOOOOO cool!Wow!T

    hat was SOOOOOO cool!b)b) Somewhat interestingSomewhat interesting

    c)c) Rather bortingRather borting

    d)d) ZzzzzzzzzzzZzzzzzzzzzz

  • 8/2/2019 21 Permutations and Combinations

    27/27