40
Theory of Computation Lecture #3 Sarmad Abbasi Virtual University Sarmad Abbasi (Virtual University) Theory of Computation 1 / 40

ion Timestamp Ordering Protocol03

Embed Size (px)

DESCRIPTION

Multi Version Timestamp Ordering Protocol

Citation preview

  • Theory of ComputationLecture #3

    Sarmad Abbasi

    Virtual University

    Sarmad Abbasi (Virtual University) Theory of Computation 1 / 40

  • Lecture 3: Overview

    Quickly recall the definition of a Turing machine.Look at some more examples of Turing machines.Define the concept of a configuration.Define what the language accepted by a TM.

    Sarmad Abbasi (Virtual University) Theory of Computation 2 / 40

  • Turing Machines

    Let us once again make sure we understand what a Turing machine is?Formally a Turing machine M is a 7-tuple, (Q,, , ,q0,qa,qr ), whereQ,, are all finite sets.

    1 Q is the set of states.2 is the input alphabet not containing the special blank symbol .3 is the tape or work alphabet. and .4 q0 is the start state.5 qa is the accept state.6 qr is the reject state.7 : Q Q {L,R} is the transition function.

    Sarmad Abbasi (Virtual University) Theory of Computation 3 / 40

  • Example: Turing Machines

    The transition function is given by the following table.state symbol next state replace with moveq0 0 q0 0 Rq0 1 q1 1 Rq0 qr Rq1 0 q0 0 Rq1 1 q1 1 Rq1 qa L

    One again we have not specified what the machine does when itreaches qa or qr . Let us see what this machine does since themachine halts when it reaches the accept or the reject state.

    Sarmad Abbasi (Virtual University) Theory of Computation 4 / 40

  • Turing MachinesLet us intuitively see what each state is doing. Let us look at q0. Whenthe machine is in q0 represents the fact that the last scanned symbolwas not a 1. Note that

    (q0,0) = (q0,0,R)

    so if the machine reads a 0 it simply stays in the state q0 and movesright (without changing the input). However, when the machine sees a1 it changes its state to q1 as

    (q0,1) = (q1,1,R).

    When the machine is in the state q1 that represents the fact that thelast scanned symbol was a 1. Thus if the machine is in the state q1and sees a 1 it stays in q1 and if it sees a 0 it goes back to q0.

    (q1,0) = (q0,0,R) and (q1,1) = (q1,1,R)

    Sarmad Abbasi (Virtual University) Theory of Computation 5 / 40

  • Turing Machines

    Lastly, we look at the transitions

    (q0,) = (qr ,,R)

    which means if the input has ended and the last symbol was not 1 thenreject the input. Whereas,

    (q1,) = (qa,,R)

    if the input has ended and the last symbol was a 1 accept the input.

    Sarmad Abbasi (Virtual University) Theory of Computation 6 / 40

  • Turing machine: State Diagram

    We can represent a Turing machine with a state diagram.

    Sarmad Abbasi (Virtual University) Theory of Computation 7 / 40

  • State Diagrams

    To make a state diagram follow the following rules:

    1 Each state is represented by a node in the state diagram.2 Clearly, mark the initial state, the accept and the reject state. In

    this course we will always mark the accept state with qa and rejectstate with qr .

    3 For each state (other than the accept and reject states) thereshould be as many arrows coming out of the state as there aresymbols in the work alphabet.

    4 Each arrow should be labeled by a replace symbol and a move.

    Sarmad Abbasi (Virtual University) Theory of Computation 8 / 40

  • Configurations

    As a TM computes changes occur in three things:

    1 Its state.2 The tape contents.3 It head position.

    A setting of all these things is called a configuration. Hence aconfiguration tells us what state the machine is in, what is currentlywritten on the tape and where the tape head exactly is.

    Sarmad Abbasi (Virtual University) Theory of Computation 9 / 40

  • Configurations

    We will represent a configuration in a very special way. Suppose isthe tape alphabet. Let u, v and q be a state of the Turingmachine. Then the configuration

    uqv

    denotes1 The current state is q.2 The tape contents are uv .3 The tape head is reading the first symbol of v .

    It is assumed that the tape contents are all blanks after the last symbolof v .Let us look at some examples:

    Sarmad Abbasi (Virtual University) Theory of Computation 10 / 40

  • Configurations

    Let us see the following picture.The machine is in state q7. The tape contents are 101101111 and thetape head is currently reading the fifth symbol with is a 0.

    So in this case, the first four symbols constitute of u and the last fivesymbols constitute of v . So, this configuration will be written as

    1011q701111

    Sarmad Abbasi (Virtual University) Theory of Computation 11 / 40

  • Configurations

    Now, let us go the other way. Suppose I tell you that a machine is inconfiguration

    0abbaq3bba01

    Can you draw a picture? The tape contents are easily recovered byignoring the state in the configuration. So, the tape contents are0abbabba01 and the machine is in state q3. Lastly, it is reading the 6thsymbol on the tape.

    Sarmad Abbasi (Virtual University) Theory of Computation 12 / 40

  • Configurations

    Sarmad Abbasi (Virtual University) Theory of Computation 13 / 40

  • Configurations

    Let us do one more example:Suppose a TM is in the configuration 01q2. What does this mean? Inthis case, v = . So the machine is reading a blank symbol. Thepicture is given here:

    Sarmad Abbasi (Virtual University) Theory of Computation 14 / 40

  • The Yields Relation

    Now, we would like to formalize the way a TM computes or takes asingle step. This is done using the yields relation. Suppose that amachine is in a configuration C1. We say that the configuration C1yields another configuration C2 if the machine can move legally fromC1 to C2 in a single step. Let us be a bit more formal.

    Sarmad Abbasi (Virtual University) Theory of Computation 15 / 40

  • The Yields Relation

    Suppose a,b and u, v and qi ,qj Q.We say that

    uaqibv yields uqjacv

    if (qi ,b) = (qj , c,L).

    Sarmad Abbasi (Virtual University) Theory of Computation 16 / 40

  • The Yields Relation

    This only handles the left moves, for the right moves we define theyields relation as follows: We say that

    uaqibv yields uacqjv

    if (qi ,b) = (qj , c,R).

    Sarmad Abbasi (Virtual University) Theory of Computation 17 / 40

  • The Yields Relation

    There are some special cases left to discuss for the yields relation.What if the head is at one of the ends of the the configuration.Let us discuss what if the head is at the left end.

    qibv yields qjcv

    if (qi ,b) = (qj , c,L).and

    qibv yields cqjv

    if (qi ,b) = (qj , c,R).In this case, we are agreeing that if the machine is at the left most cellit will not move its head further to the left even if the delta functionrequires us to do so.

    Sarmad Abbasi (Virtual University) Theory of Computation 18 / 40

  • The Yields Relation

    What if the head is reading a blank?

    uaqi yields uqjac

    if (qi ,) = (qj , c,L).and

    uaqi yields uacqj

    if (qi ,b) = (qj , c,R).

    Sarmad Abbasi (Virtual University) Theory of Computation 19 / 40

  • The Yields Relation

    Have we discussed all possibilities?One annoying one is left.Consider a machine in a configuration

    qi

    Is this a configuration. Yes, the machine is in state qi and the tape iscompletely blank and the machine is reading the left most symbol.

    qi yields qjc

    if (qi ,) = (qj , c,L).and

    qi yields cqj

    if (qi ,) = (qj , c,R).

    Sarmad Abbasi (Virtual University) Theory of Computation 20 / 40

  • The Yields Relation

    Summary:

    uaqibv yields uqjacv

    if (qi ,b) = (qj , c,L).and

    uaqibv yields uacqjv

    if (qi ,b) = (qj , c,R).

    Sarmad Abbasi (Virtual University) Theory of Computation 21 / 40

  • The Yields Relation

    Let us look at our previous TM and its diagram and see what the yieldsrelation gives us if we start the machine with input 1001.Let us first look at the state diagram of this TM again.

    The start configuration is q01001and if we apply the yields operation repeatedly we get

    1q1001,10q001,100q01,1001q1,1001qa.

    Sarmad Abbasi (Virtual University) Theory of Computation 22 / 40

  • The Yields Relation

    For a TM M, if C1 yields C2 we sometime write this as:

    C1 `M C2

    Sarmad Abbasi (Virtual University) Theory of Computation 23 / 40

  • Starting, accepting and rejection configurations

    1 The start configuration of M on input w is q0w where q0 is thestart state. Notice that the head is reading the left most symbol.

    2 A configuration C is accepting if the machine is in the accept state.3 A configuration C is rejecting if the machine is in the reject state.

    Accepting and rejecting configurations are called haltingconfigurations.

    Sarmad Abbasi (Virtual University) Theory of Computation 24 / 40

  • Starting, accepting and rejection configurations

    Suppose M is a TM and w . A TM accepts w if there existconfigurations C1,C2, . . . ,Ck such that

    1 C1 is the start configuration of M on input w ; that is,

    C1 = q0w

    .2 each Ci `M Ci+1.3 Ck is an accepting configuration.

    Sarmad Abbasi (Virtual University) Theory of Computation 25 / 40

  • Language accepted by a TM

    The collection of all strings in that are accepted by M is thelanguage of M and is denoted by L(M).

    L(M) = {w : M accepts w}.

    Sarmad Abbasi (Virtual University) Theory of Computation 26 / 40

  • Language accepted by a TM

    So, if we go to our previous example:

    Sarmad Abbasi (Virtual University) Theory of Computation 27 / 40

  • Language accepted by a TM

    Sarmad Abbasi (Virtual University) Theory of Computation 28 / 40

  • Language accepted by a TM

    Then for this TM M

    L(M) = {x : x ends with a 0}.

    Sarmad Abbasi (Virtual University) Theory of Computation 29 / 40

  • Language accepted by a TM

    Does a TM only accept or reject inputs? No. Lets consider M :

    Hence if a string ends with a 0 the machine keeps computing forever.

    q000 `M 0q00 `M 00q0 `M`M 00q0 `M 00q0

    Sarmad Abbasi (Virtual University) Theory of Computation 30 / 40

  • Language accepted by a TM

    What is the language accepted by M ?By definition it is the set of all strings accepted by M . Hence,

    L(M ) = {x {0,1} : x ends with a 0}.

    Sarmad Abbasi (Virtual University) Theory of Computation 31 / 40

  • Language accepted by a TM

    We have

    L(M) = {x{0,1} : x ends with a 0}.

    L(M ) = {x{0,1} : x ends with a 0}.Both accept the same language. However, the first machine M willreject all inputs which do not end with a 0. Whereas, M will go into ainfinite loop on all such inputs.We prefer M to M .

    Sarmad Abbasi (Virtual University) Theory of Computation 32 / 40

  • Language accepted by a TM

    We say that a Turing machine is a decider if it halts on all inputs in .Hence M is a decider and M is not a decider.

    Sarmad Abbasi (Virtual University) Theory of Computation 33 / 40

  • Designing TMs

    The most usual question in computer science can be posed as follows:Given a language L0 design a decider, M, such that

    L(M) = L0.

    L0 is the given problem and M is the algorithm that solves or decidesthe problem. Let us look at an example of this.

    Sarmad Abbasi (Virtual University) Theory of Computation 34 / 40

  • Designing TMs

    Let = {0}.

    L2 = {02n : n 0}.We want to design a TM M2 such that

    L(M2) = L2.

    Hence we want a TM M2 that accepts all the inputs in L2.In order to solve this problem we must first understand the languageL2.

    L2 = {0,00,0000,00000000,0000000000000000, . . . , }

    Sarmad Abbasi (Virtual University) Theory of Computation 35 / 40

  • Designing TMs

    To design a TM we must have a plan in mind. How will we solve thisproblem? Note that a TM can only have finite number of states andtherefore it cannot remember much. It does not even know how tocount (unless you teach it).

    If I have some number of 0s and I cross each alternate one I will cutthe number of 0s into half.

    Informal description of the M2.

    1 Sweep from the left to the right crossing off each other 0.2 If there was a single 0 on the tape, accept.3 If there were more then one 0s and the number was odd, reject.4 Return the head to the left end and repeat.

    Sarmad Abbasi (Virtual University) Theory of Computation 36 / 40

  • Designing TMs

    Why would this work.If the number of 0s is 16, it will be cut into 8 and then 4 and then 2 andthen 1 and then we will accept.On the other hand if the number of 0s is say 20, it will be cut to 10 then5 and then we will reject.

    Sarmad Abbasi (Virtual University) Theory of Computation 37 / 40

  • Designing TMs

    Let us look at the formal description of this Turing Machine. Themachine M2 = (Q,, , ,q1,qa,qr ) where,

    Q = {q1,q2,q3,q4,q5,qa,qr ). = 0. = {0, x ,}.q1 is the start state, qa is the accept state and qr is the reject state. is described by the following state diagram.

    Sarmad Abbasi (Virtual University) Theory of Computation 38 / 40

  • Designing TMs

    Sarmad Abbasi (Virtual University) Theory of Computation 39 / 40

  • Designing TMs

    Sarmad Abbasi (Virtual University) Theory of Computation 40 / 40