DOC PREVIEW
Penn CIT 594 - Counting

This preview shows page 1-2-19-20 out of 20 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 20 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CountingPhilosophyNumber systemsCounting in various basesPowersCounting subsetsGroupingPermutationsCounting permutationsArray permutationsComputing permutationsPermutations of non-unique valuesMore permutationsSubset permutationsComputational common senseChoicesCounting problemsYet more counting problemsSummaryThe EndJan 14, 2019Counting2PhilosophyThis set of slides is about counting thingsMuch of it is a branch of mathematics called combinatoricsI believe:Mathematics is logical and makes senseIf you understand the math, you don’t need to memorize a bunch of equationsSome people believe:If you memorize a bunch of equations, you don’t need to understand the mathThe second approach works a lot of the time, but…Real-life problems don’t come with a little tag attached telling you what equation to use3Number systemsA number system base B is a set of B “digits” representing the numbers 0 through B-1Example: Decimal (base 10) uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9Example: Ternary (base 3) uses the digits 0, 1, and 2If the base isn’t obvious from context, it is written as a subscript of the numberExample: 21203 means “2120 base 3”Bases used in computer programming:DecimalBinary (base 2) uses the binary digits (bits) 0 and 1Octal (base 8) uses the octal digits 0, 1, 2, 3, 4, 5, 6, and 7Hexadecimal, or “hex” (base 16) uses the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F4Counting in various basesThe rule for getting the “next number” (adding one) in any system is always the same: If a digit is the largest possible, reset it to zero and add 1 to the digit on the leftDecimal examples: 9  10, 1299  1300, 83989  83990Octal examples: 7  10, 1277  1300, 75767  75770Hex examples: F  10, A2FF  A300, F5FEF  F5FF0Binary examples: 1  10, 1011  1100, 110111  111000The same number is usually represented different ways in different number systemsExample: 4810 = 3016 = 608 = 1100002But: 510 = 516 = 58 = 10125PowersIn any base B, the digits of a number represent a multiplier of a power of BExample: 402510 = 4*103 + 0*102 + 2*101 + 5*100Example: 40258 = 4*83 + 0*82 + 2*81 + 5*80 = 4*512 + 0*64 + 2*8 + 5*1 = 206910It is useful to learn the powers of 2: 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384It is especially useful to remember that 210 = 1024 is approximately equal to 103 = 1000In any base B, you can represent BK different numbers (0 through BK-1) with K digits6Counting subsetsGiven a set of N distinct values, {A, B, C}, there are exactly 2N possible subsets of those valuesYou can show this by counting in binary: A 1 means it’s in the subset, a 0 means it’s not{ A, B, C } 0 0 0  { } (the empty subset) 0 0 1  { C } 0 1 0  { B } 0 1 1  { B, C } 1 0 0  { A } 1 0 1  { A, C } 1 1 0  { A, B } 1 1 1  { A, B, C } (the “improper” subset)7GroupingSuppose we have a collection of N unique items, and we want to sort them into two pilesThe piles don’t need to be equal in sizeIn fact, it’s OK for one of the piles to be emptyHow many different ways can we sort the items into two piles?Suppose we have a collection of N unique items, and we want to sort them into three pilesThe piles don’t need to be equal in sizeIn fact, it’s OK for one, or even two, of the piles to be emptyHow many different ways can we sort the items into three piles?8PermutationsGiven a set of N distinct values, a permutation is a possible ordering of those valuesExample: There are two permutations of the set {A, B}: AB and BAExample: There are six permutations of the set {A, B, C}: ABC, ACB, BAC, BCA, CAB, CBAExample: There are 24 permutations of the set {A, B, C, D}: ABCD, ACBD, BACD, BCAD, CABD, CBAD, ABDC, ACDB, BADC, BCDA, CADB, CBDA, ADBC, ADCB, BDAC, BDCA, CDAB, CDBA, DABC, DACB, DBAC, DBCA, DCAB, DCBA9Counting permutationsTo find the permutations of {A, B, C, D, E}, there are:Five possible choices for the first itemFour possible choices for the second itemThree remaining possible choices for the third itemTwo remaining possible choices for the fourth item, andOnly one possible “choice” for the final itemFor any positive integer N, we define N! (“N factorial”) as the product of all the positive integers up to and including NExample: 5! = 1 * 2 * 3 * 4 * 5 = 120Given any N distinct items, there are N! possible permutations of those items10Array permutationsSorting an array is finding a particular permutation of the elements in the array that satisfies some conditionIf you have an array of 50 elements, there can be as many as 50! possible ways to order those valuesThis is an extremely large number!If some of the elements are the same, there are fewer possible orderingsFor example, if all the elements in the array are equal, there is only one possible ordering11Computing permutationsIt’s easy to describe a recursive procedure for finding all permutations (it’s not so easy to implement):There is only one permutation of one object (base case): AGiven all the permutations of N objects, find the permutations of N+1 objects by inserting the new object in each possible position of each permutation of N objectsExample: From A, get BA and ABExample: From BA and AB, get CBA, BCA, BAC, CAB, ACB, ABC12Permutations of non-unique valuesHow many possible permutations are there of the valuesA, A, A, B, C ?If the values were all distinct, there would be 5! possible permutations--but they aren’t all distinctWe can’t distinguish one ABAAC from another ABAACBut if we pretend that we can tell one A from another, we find that there are 3! = 6 possible ways to get ABAAC:ABAAC, ABAAC, ABAAC, ABAAC, ABAAC, ABAACIn fact, every other permutation, such as ACABA, is represented in six different waysThis is because there are six ways to permute the As: AAA, AAA, AAA, AAA, AAA, AAAHence, there are really only 5!/3! = 120/6 = 20 possible permutations:AAABC, AABAC, AABCA, ABAAC, ABACA, ABCAA, BAAAC, BAACA, BACAA, BCAAA, AAACB, AACAB, AACBA, ACAAB, ACABA, ACBAA, CAAAB, CAABA, CABAA, CBAAA13More permutationsHow many possible permutations are there of the values A, A, A, B, C, C


View Full Document

Penn CIT 594 - Counting

Documents in this Course
Trees

Trees

17 pages

Searching

Searching

24 pages

Pruning

Pruning

11 pages

Arrays

Arrays

17 pages

Stacks

Stacks

30 pages

Recursion

Recursion

25 pages

Hashing

Hashing

24 pages

Recursion

Recursion

24 pages

Graphs

Graphs

25 pages

Storage

Storage

37 pages

Trees

Trees

21 pages

Arrays

Arrays

24 pages

Hashing

Hashing

24 pages

Recursion

Recursion

25 pages

Graphs

Graphs

23 pages

Graphs

Graphs

25 pages

Stacks

Stacks

25 pages

Recursion

Recursion

25 pages

Quicksort

Quicksort

21 pages

Quicksort

Quicksort

21 pages

Graphs

Graphs

25 pages

Recursion

Recursion

25 pages

Searching

Searching

24 pages

HTML

HTML

18 pages

Recursion

Recursion

24 pages

Pruning

Pruning

11 pages

Graphs

Graphs

25 pages

Load more
Download Counting
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Counting and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Counting 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?