Lecture Notes (Original)

  • Upload
    salitha

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

  • 7/25/2019 Lecture Notes (Original)

    1/28

    ArsDigita UniversityMonth 2: Discrete Mathematics - Professor Shai Simonson

    Lecture Notes

    What is Discrete Math?

    Example of continuous math Given a fixed surface area, what are the dimensions of a cylinderthat maximizes volume?

    Example of Discrete Math Given a fixed set of characters, and a length, how many different passwords can you construct? ow many edges in graph with n vertices? ow many ways tochoose a team of two people from a group of n? ow many different !inary trees "is it worthchec#ing them all to find a minimum spanning tree of a graph a tree that includes all the verticesof a weighted edge graph, with minimum sum of weights$? ow many ways to arrange n arrays

    for multiplication? ow many ways to draw n pairs of !alanced parens?

    %ote that the last & examples have the same answers "not o!vious$'

    %ote the second and third examples have the same answer "o!vious$'

    (ounting is an important tool in discrete math as we will see later'

    What are proofs?

    )ormal definitions and logic versus*+ proof is a clear explanation, accepted !y the mathematical community, of why something is true'

    Examples*'

    +ncient a!ylonian and Egyptian mathematics had no proofs, -ust examples and methods'.roofs in the way we use them today !egan with the Gree#s and Euclid'

    /' 0he s1uare root of two is irrational 2 + proof !y contradiction from +ristotle'

    +ssume that a3! 4 5, where a and ! are relatively prime' 61uaring !oth sides of the e1uationgives a753!75 4 5' 0hen a75 4 5!75, and since an even num!er is any num!er that can !e writtenas 5#, a75 must !e even' y a separate lemma, we #now that if a75 is even, then a must also !eeven' 6o write a 4 5m' 0hen a75 4 "5m$75 and a75 4 8m75, and 5!75 4 8m75, so !75 is even, and

    ! is even'' ut we assumed without any loss of generality that a and ! were relatively prime, andnow we have deduced that !oth are even9 0his is a contradiction, hence our assumption that a3! 45 cannot !e right'

  • 7/25/2019 Lecture Notes (Original)

    2/28

    5' 0here are an infinite num!er of prime num!ers + proof !y contradiction !y Euclid'

    +ssume that there is a finite num!er of prime num!ers' (onstruct their product and add one'

    %one of the prime num!ers divide this new num!er evenly, !ecause they will all leave a remainder of one' ence, the num!er is either prime itself, or it is divisi!le !y another prime not on theoriginal list' Either way we get a prime num!er not in the original list' 0his is a contradiction tothe assumption that there is a finite num!er of prime num!ers' ence our assumption cannot !ecorrect'

    Discovering theorems is as important as proving them'

    Examples:

    /' ow many pairs of people are possi!le given a group of n people?(onstructive counting method: 0he first person can pair up with n2/ people' 0henext person can pair up with n25 people etc, giving "n2/$ ; "n25$ ; * ; 5 ; /

    (ounting argument: Each person of n people can pair up with n2/ other people, !utcounting pairs this way, counts each pair twice, once from each end' ence we geta total of n"n2/$35'

    5' Define the triangle num!ers' ow !ig is the nth triangle num!er?

    Geometric argument >' 0he teacher had hoped this would #eep Gauss

    !usy for a few minutes' Gauss presuma!ly derived this formula on the spot and !lurted !ac# > >' %ote that later in his life it is well documented that Gauss was1uite proud of his proof that any integer can !e written as a sum of at most threetriangle num!ers'

    &' ow many pieces do you get from cutting a circle with n distinct cuts? "ma#e surewe define distinct carefully$'

    0he first few num!ers of cuts and pieces can !e listed !elow as we experiment:

    (uts .ieces

  • 7/25/2019 Lecture Notes (Original)

    3/28

    / 55 8& @8 //

    We can argue that the .A"n;/$ 4 .An ; n;/' Every new cut intersects each of theold cuts in one uni1ue place' ence each new cut creates / more region than thenum!er of cuts already made, !ecause it creates a region as it exits the circle' 0hisis called a recurrence e1uation and we can solve it directly "see wee# & in sylla!us$'

    %ote that 0A"n;/$ 4 0An ; n;/' 0his is the same e1uation, !ut .An does not e1ual0An9 What gives? 0he difference is that .A/ 4 5 and 0A/ 4 /'

    We #now that 0An 4 "n$"n;/$35 and it seems that .An 4 0An ; /'

    (an we prove this last fact, namely .An 4 0An ; /?

  • 7/25/2019 Lecture Notes (Original)

    4/28

    )ormal .roof, ogic and oolean +lge!ra

    We can represent facts !y oolean varia!les, varia!les whose values are true or false "/ or >$' We

    can com!ine these varia!les using various operators, +%D, HF and %H0' We can specify all sortsof logical statements using other operators, !ut they can always !e transformed !ac# to a formulacontaining -ust +%D, HF and %H0'

    Example:et W 4 wet outside' et F 4 raining'

    / // > >/ / /

    0his idea of a truth ta!le is a sure fire to show the e1uivalence of oolean expressions'

  • 7/25/2019 Lecture Notes (Original)

    5/28

    F W F W> > /> / >/ > >/ / /

    0he +lge!ra of its oolean +lge!ra

    ere we treat the manipulation of oolean expressions syntactically and note the analogy toaddition and multiplication, where true is the value / and false is the value >' +%D, HF arecommutative, and they are mutually distri!utive' 0here are two rules called DeMorgan s aws thatrelate %H0 to +%D and HF'

    ere is a summary of the rules of oolean +lge!ra' 0hey all can !e verified !y truth ta!les and thedefinitions of the operators'

    . ; true 4 true .. 4 false

    ."true$ 4 . . ; . 4 true

    . ; false 4 . ." ;F$ 4 . ; .F

    ."false$ 4 false . ; F 4 ".;F$" ;F$"note that this last !eautiful dual rule is not true for regular addition and multiplication'$'DeMorgan s aws: ". ; $ 4 . ". $ 4 . ;

    oolean alge!ra is useful not only in logic !ut more importantly in the design of digital circuits atthe heart of ma#ing a computer wor#'

  • 7/25/2019 Lecture Notes (Original)

    6/28

    .roof !y example a!ove'

    0he resulting expression is an HF of a collection of varia!les or their negations that are +%Dedtogether' 0his is called Dis-unctive %ormal )orm' 0he (on-unctive %ormal form of a oolean

    expression can also always !e constructed and it is an +%D of a collection of varia!les or theirnegations that are HFed together' %ote again the intense symmetry in oolean +lge!ra'

    (omplete Hperators

    + set of operators that can descri!e an ar!itrary oolean function is called complete' 0he setL+%D, HF, %H0 is complete' 0here are certain operators that alone can descri!e any ooleanfunction' Hne example is the %HF operator ' . is defined to !e ".; $' Kou can verify that . 4 ". .$. 4 ". $ ". $.; 4 ". .$ " $

    0hese three e1uations imply that %HF is complete'

    Fecitation .redicates and higher order ogic' uantifiers and rules for su!stitution and pushingthrough of negations'

    +pplications in (omputer 6cience:

    Example: 0he 6atisfia!ility pro!lem and %.2(ompleteness'

    Feductions

    =2x'

    Feductions are crucial to showing that a pro!lem is hard' We cannot in general prove that a pro!lem is hard' We would have to show that no algorithm is efficient, and there are a lot ofalgorithms9 Hn the other hand, we can show that a pro!lem is easy !ut exhi!iting -ust one goodalgorithm' What computer scientists can do, is to prove that a pro!lem is %.2(omplete' 0his does

  • 7/25/2019 Lecture Notes (Original)

    7/28

    %H0 mean it is definitely hard, !ut it means it is at least as hard as a whole host of other well#nown difficult pro!lems'

    %. is the set of all pro!lems solva!le in polynomial time !y a non2deterministic program' Ki#es,what does that mean? Wait until the algorithms course' ut !asically, it means that you can verify

    a guess of the solution in polynomial time' %on2determinism gives you lots of power' %o one#nows how to simulate non2deterministic programs efficiently with deterministic "normal$ programs' +ny general simulation #nown re1uires an exponential growth in time re1uirements'

    +n %.2(omplete pro!lem is a pro!lem in %. to which all the pro!lems in %. can !e reduced in polynomial time' 0his means that if you could solve the %.2(omplete pro!lem in polynomialtime, then you could solve all the pro!lems in %. in polynomial time' 6o if your !oss gives you ahard pro!lem, you can t say B6orry !oss, it can t !e done efficientlyC, !ut at least you can say Bs, gave us away to compare infinite sets' e suggested that two sets would have the same BsizeC if and only if

  • 7/25/2019 Lecture Notes (Original)

    14/28

    there is a /2/ correspondence !etween the elements in the two sets'

  • 7/25/2019 Lecture Notes (Original)

    15/28

    )unctions, especially those with finite domain and range, are sometimes represented !y a picturewith arrows showing the mapping'

    to prove thatcertain functions are ig2H of other functions'

    5n7& n75 ; =n ; S is H"n7&$' et c 4 /@' 5n7& n75 ; =n ; S R4 5n7& ; n7& ; =n7& ; Sn7& 4/@n7&, for all n >'

    u!!le sort gives a time complexity of n"n2/$35' 0his is Hmega"n75$ !ecause n"n2/$35 4 "/3&$n75 for all n &'

    0he minimum of steps to sort n items is lg "n9$' We prove that this is ig0heta"nlogn$'lg n9 is H"nlogn$ !y setting c4/, and noting that lg n9 R4 lg n7n 4 nlgn'lg n9 is Hmega"n lgn$ can !e seen !y writing n9 4 n "n2/$ * "n35$ 4 "n35$7"n35$' ence lg n9 4"n35$"lg n35$ 4 n35"lgn$ n35 R4 n38 "log n$ for all n 8'

  • 7/25/2019 Lecture Notes (Original)

    16/28

    0here are other techni1ues for estimating growth including integration, and example of which will !e discussed in recitation, where we show that the sum of /3< for < 4 / to n is ig theta log n'

    Wor#ing with sums'

  • 7/25/2019 Lecture Notes (Original)

    17/28

    Fecurrence Felations and Geometric 6ums

    (ompound

  • 7/25/2019 Lecture Notes (Original)

    18/28

    +s# if your guess is higher or lower to guess my secret num!er !etween / and n' Each guessthat you ma#e halves the possi!le remaining secret num!ers' 0he time for this algorithm is:0"n$ 4 0"n35$ ; / and 0"/$ 4 >'

    Tsing our su!stitution method we get:

    0"n$ 4 0"n357r$ ; r, after r iterations'

    et r 4 lg n and this !ecomes 0"n$ 4 lgn

    0owers of anoi 22 the legend is only />> years old or so

    Define 0o "n, )rom, 0o, Tsing$

    L

    0o "n2/, )rom, Tsing, 0o$IDisplay "Vmove dis# from )rom Vto 0o$I0o "n2/, Tsing, 0o, )rom$I

    et s analyze the time complexity, solve the resulting recurrence e1uation, and loo# at somespecial cases' 0hen we loo# at a graph that will give us a !ird s eye view of the anoi recursive

    -ungle' 0he power of graphs will !e seen in this example, and throughout the pset'

    0"n$ 4 50"n2/$ ; / 0">$ 4 >

    +fter / iteration 0"n$ 4 575 0"n25$ ; 5 ; /

    +fter r iterations 0"n$ 4 57r 0"n2r$ ; 57"r2/$ ; 57"r25$ ; * ; 8 ; 5 ; /

    etting r 4 n, we get 6um i 4 / to n2/ of 57i'

    0his is called a geometric series'

  • 7/25/2019 Lecture Notes (Original)

    19/28

    5x x 4 x 4 57n /

    ence for 0o , 0"n$ 4 57n /

    %ow that we have opened the !ox of geometric series, let s review /357i'

    et s also consider the sum of i"57i$, or i75"57i$, or i7#"57i$' %one of these are geometric series !ut they can all !e handled !y the same tric# in an especially inductive way, where the next casereduces to the simpler case, and finally to the original geometric series'

    Example:

    et x 4 /P5 ; 5P575 ; &P57& ; * ; nP57n

    ere 5x x 4 x 4 nP57"n;/$ 5 " 575 ; 57& ; * ; 57n$We get a formula with a geometric series in it' 0his formula e1uals nP57"n;/$ 5 "57"n;/$ 8$4 "n2/$ 57"n;/$ ;5

    Many other !asic sums can !e managed with repeated use of this one tric#'

    0he anoi Graph

    0he anoi graph will !e shown and discussed in class' Kou can loo# for a picture on thewe! on Eric Weisstein s math site mathworld'wolfram'com'

  • 7/25/2019 Lecture Notes (Original)

    20/28

    0he next example of recursion is an excellent one for motivating induction' We will discover thetruth a!out the seven rings puzzle, and discover its connection to amiltonian circuits inhypercu!es, and to Gray (odes'

    An Example of Motivating MathematicalInduction for Computer Science

    The Chinese Rings or Patience Puzzle

  • 7/25/2019 Lecture Notes (Original)

    21/28

  • 7/25/2019 Lecture Notes (Original)

    22/28

    A Recursive Method to RemoveRings and Unloc the Puzzle

    To Remove the n rings!Reduce the puzzle to an n"# ring puzzle$Remove the leftmost n"# rings$

    End

    To Reduce the puzzle to an n"# ring puzzle!Remove the leftmost n"% rings$Remove the nth ring$Replace the leftmost n"% rings$

    End

    Resulting Recurrence Equation

    T&n' ( # ) T&n"#' ) %T&n"%'

    T' ( # T&%' ( %

  • 7/25/2019 Lecture Notes (Original)

    23/28

    Analysis and Solution

    *or To+ers of ,anoi T&n' ( %T&n"#' ) #- T'( #-+e solved the recurrence ./ repeatedsu.stitution$

    Su.stituting T&n"#' ( %T&n"%' ) # .ac into T&n' (%T&n"#' ) # implies T&n' ( 0T&n"%' ) # ) %

    After r su.stitutions +e get!

    T&n' ( %r T&n"r' ) ) % ) 0 ) 1 ) %r"#'- andT&n' ( %n"#) %n"# 2 # ( %n 2 #

    3ut here1T&n' ( # ) T&n"#' ) %T&n"%'

    T' ( # T&%' ( %

    The same techni4ue after one iteration +ouldimpl/!

    T&n' ( # ) # ) % ) T&n"%' ) 0T&n"5' ) 0T&n"0'

  • 7/25/2019 Lecture Notes (Original)

    24/28

    Should +e continue6 Ugh777

    Lets Experiment&Recursion versus 8/namic Programming'

    T&n' ( # ) T&n"#' ) %T&n"%'T' ( # T&%' ( %

    n T&n'# #% %5 90 #:

    9 %#; 0%< =9

    >et?s @uess1

    hen n is even! T&n' ( %T&n"#'hen n is odd! T&n' ( %T&n"#' ) #

  • 7/25/2019 Lecture Notes (Original)

    25/28

    Proving this directl/ is not o.vious$ ,o+ever- aproof ./ induction is natural and eas/$

  • 7/25/2019 Lecture Notes (Original)

    26/28

    Logo Program to Experiment

    to chinese !n B an inefficient recursive programif &( !n #' op #if &( !n %' op %op &) # &chinese &" !n #'' & % chinese &" !n %''

    end

    to chinese% !n B a fast computation of the closed formif &( !n #' op #

    if &( !n %' op %if &even6 !n' op &D& % &"&exp % !n' #'' 5'op &D &"&exp % &) !n #'' #' 5'

    end

    to exp !a !.ma e x #repeat !. Fma e x & !a !x'G

    op !xend

    to even6 !an/ to odd6 !an/op &( &remainder !an/ %' :' op &not &even6 !an/'

    end end

    Exercises!

    rite an Iterative Hersion$rite a Tail Recursive Hersion$

  • 7/25/2019 Lecture Notes (Original)

    27/28

    Solution and Closed *orm

    T&n' ( # ) T&n"#' ) %T&n"%'T' ( # T&%' ( %

    hen n is even! T&n' ( %T&n"#'

    hen n is odd! T&n' ( %T&n"#' ) #

    o+ +e can use repeated su.stitution to get!

    T&n' ( 0T&n"%' ) %- +hen n is even$T&n' ( 0T&n"%' ) #- +hen n is odd$

    Continuing our su.stitutions gives!

    T&n' ( %D5 &%n 2#'- +hen n is even$

    T&n' ( #D5 &%n)#

    2#'- +hen n is odd$

  • 7/25/2019 Lecture Notes (Original)

    28/28

    The Chinese Ring Puzzle motivates!

    #$ An Understanding of Recursion$

    %$ Iatural proofs ./ induction$

    5$ Construction- anal/sis and solution ofrecurrence e4uations$

    0$ Complexit/ anal/sis of recursiveprogramming versus d/namic programming$

    9$ 3inar/ @re/ Codes$

    ;$ @raph Representations and data structures$