intro discrete midterm 2

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

what is the decimal expansion of integer

(1 0101 1111)2 1∙2^8 + 0∙2^7 + 1∙2^6 + 0∙2^5 + 1∙2^4 + 1∙2^3 + 1∙2^2 + 1∙2^1 + 1∙2^0 =351

addition modulo m

+m a +m b = (a + b) mod m 7 +11 9 = (7 + 9) mod 11 = 16 mod 11 = 5

Recursive binary search

- Search in the array A in positions numbered loIndex to hiIndex inclusive, for the specified value. - If the value is found, return the index in the array where it occurs. - If the value is not found, return -1. - Precondition: The array must be sorted into increasing order.

Derivation (Parse) Trees

-The root of the tree represents the start symbol. -The internal vertices represent the nonterminal symbols that arise in the derivation. -The leaves represent the terminal symbols that arise. -If the production A →w, where w is a word, arises in the derivation, the vertex that represents A has as children vertices that represent each symbol in w, in order from left to right.

Regular expression example

10* = a 1 followed by any number of 0s (including no zeros) (10)* = any number of copies of 10 (including the null string) 0 U 01 = the string 0 or the string 01 0(0U1)* = any string beginning with 0 (0*1)* = any string not ending with 0

13.1

13.1 below

What is the decimal expansion of the number with octal expansion (7016)8

7∙8^3 + 0∙8^2 + 1∙8^1 + 6∙8^0 =3598

Finite State Automaton (FSA)

A finite-state automaton M = (S, I, f, s0, F) consists of a finite set S of states, a finite input alphabet I, a transition function f that assigns a next state to every pair of state and input (so that f: S × I → S), an initial or start state s0, and a subset F of S consisting of final (or accepting) states Final states are depicted with a double circle

Full Binary Tree

A full binary tree (sometimes referred to as a proper or plane binary tree) is a tree in which every node in the tree has either 0 or 2 children.

Computability

A function that can be computed by a TM is called computable and a function that cannot be computed by a TM is called uncomputable.

Kleene's Theorem

A set is regular IFF it is recognized by an FSA

Representing an FSM

A state table is used to represent the values of the transition function f and the output function g for all (state, input). Alternatively, a finite-state machine can be represented by a state diagram, which is a directed graph with labeled edges. Each state is represented by a circle, and arrows labeled with the input and output pair represent the transitions.

Kleene Closure

A* For example, the Kleene closure A* of {a, b} is {ε, a, b, aa, ab, ba, bb, aaa, ...}

Kleene closure of A, a subset of V*, denoted A*

A* = ⋃2_(k=0)^∞ Ak set of arbitrarily long strings of elements in A The Kleene closures of A = {0} and C = {11} are A* = {0^n | n = 0, 1, 2, ....} C* = {1^(2n) | n = 0, 1, 2, ....}

Turing Machine working

At each step, the control unit reads the current tape symbol x. If the control unit is in state s and if the partial function f is defined for the pair (s, x) with f(s, x) = (s′, x′, d), the control unit: enters the state s′, writes the symbol x′ in the current cell, erasing x, and moves right one cell if d = R or moves left one cell if d = L. This step is written as the five-tuple (s, x, s′, x′, d). Turing machines are defined by specifying a set of such five-tuples. If the partial function f is undefined for the pair (s, x) then T will halt initial position = leftmost nonblank symbol on tape

Recursive/inductive definition (recursively defined functions)

Consists of two steps: basis step: specify value of function at zero recursive step: give a rule for finding its value at an integer from its values at smaller integers function f(n) = a0, a1,... where f(i) = ai

Turing Machine

Consists of: control unit - it is the read/write head that is present in one cell at a time on the tape. the tape is infinite in both directions A Turing machine T = (S, I, f, s0) consists of a finite set S of states, an alphabet I containing the blank symbol B, a partial function f from S × I to S × I ×{R,L}, and a starting state s0 For some (state, symbol) pairs the partial function f may be undefined, but for a pair for which it is defined, there is a unique (state, symbol, direction) triple associated to this pair. The five-tuples corresponding to the partial function in the definition of a TM are called the transition rules of the machine.

Construct base b expansion of integer n

Divide n by b to obtain a quotient and remainder. The remainder, a0, is the rightmost digit in the base b expansion of n. Next, divide q0 by b. The remainder, a1, is the second digit from the right in the base b expansion of n. Continue by successively dividing the quotients by b, obtaining the additional base b digits as the remainder. The process terminates when the quotient is 0

hexadecimal, octal, and binary representations

Each octal digit corresponds to a block of 3 binary digits. Each hexadecimal digit corresponds to a block of 4 binary digits. So, conversion between binary, octal, and hexadecimal is easy.

well-ordering property

Every nonempty set of nonnegative integers has a least element. Can be generalized to things like lexicographically ordered strings

Base b expansion example

Example: Find the octal expansion of (12345)10 Solution: Successively dividing by 8 gives: 12345 = 8 ∙ 1543 + 1 1543 = 8 ∙ 192 + 7 192 = 8 ∙ 24 + 0 24 = 8 ∙ 3 + 0 3 = 8 ∙ 0 + 3 The remainders are the digits from right to left yielding (30071)8.

Syntax

Form of a sentence

phase-structure grammar

G = (V,T,S,P) consists of a vocabulary, a subset T of V consisting of terminal symbols, a start symbol S from V, and a finite set of productions P

Congruence Relation

If a and b are integers and m is a positive integer, then a is congruent to b modulo m if m divides a - b. The notation a ≡ b (mod m) says that a is congruent to b modulo m. We say that a ≡ b (mod m) is a congruence and that m is its modulus. Two integers are congruent mod mif and only if they have the same remainder when divided by m 17 ≡ 5 (mod 6) because 6 divides 17 − 5 = 12. a and b are congruent modulo m if and only if there is an integer k such that a = b + km.

Divisibility

If a and b are integers with a ≠ 0, then a divides b if there exists an integer c such that b = ac a is then a factor or divisor of b If a | b, then b/a is an integer

Division Algorithm

If a is an integer and d a positive integer, then there are unique integers q and r, with 0 ≤ r < d, such that a = dq + r d is called the divisor a is called the dividend q is called the quotient r is called the remainder q = a div d r = a mod d What are the quotient and remainder when −11 is divided by 3? Solution: The quotient when −11 is divided by 3 is −4 = −11 div 3, and the remainder is 1 = −11 mod 3.

Distributivity of multiplication modulo m

If a, b, and c belong to Zm, then a ∙m (b +m c) = (a∙m b) +m (a ∙m c) (a+m b) ∙m c = (a ∙m c) +m (b ∙m c)

Additive Inverse of addition modulo m

If a≠ 0 belongs to Zm , then m− a is the additive inverse of a modulo m and 0 is its own additive inverse a +m (m− a ) = 0 0 +m 0 = 0

Merge Sort

Iteratively splitting a list (with an even number of elements) into two sublists of equal length until each sublist has one element. Then reorder from ground up and merge together (see image) procedure mergesort(L = a1, a2,...,an ) if n > 1 then split L into two lists L1 and L2 merge(mergesort(L1), mergesort(L2 )) procedure merge(L1, L2 :sorted lists) L := empty list while L1 and L2 are both nonempty successively remove lowest num from L1 orL2 and put in L until one list is empty, in which case append the rest of the other list to L return L {L is the merged list with the elements in increasing order}

directly derivable

Let G =(V, T, S, P) be a phrase-structure grammar. Let w0 = lz0r (that is the concatenation of l, z0, and r) and w1 = lz1r be strings over V. If z0 → z1 is a production of G, we say that w1 is directly derivable from w0 and write w0 ⇒w1 If w0,w1, ...,wn are strings over V such that w0 ⇒w1, w1 ⇒w2, ..., wn-1 ⇒ wn, then we say that wn is derivable from w0 and write w0 ⇒wn. The sequence of steps used to obtain wn from w0 is called a derivation.

How does a Turing Machine recognize sets

Let V be a subset of an alphabet I. A TM T = (S, I, f, s0) recognizes a string x in V* if and only if T, starting in the initial position when x is written on the tape, halts in a final stat A TM operating on a tape containing the symbols of a string x in consecutive cells, does not recognize x if it does not halt or halts in a state that is not final

Congruence of Sums and Products

Let m be a positive integer. If a ≡ b (mod m) and c ≡ d (mod m), then a + c ≡ b + d (mod m) and ac ≡ bd (mod m) Because 7 ≡ 2 (mod 5) and 11 ≡ 1 (mod 5) , it follows from Theorem 5 that 18 = 7 + 11 ≡ 2 + 1 = 3 (mod 5) 77 = 7 ∙ 11 ≡ 2 ∙ 1 = 2 (mod 5)

string concatenation

Let Σ be a set of symbols and Σ* be the set of strings formed from the symbols in Σ. We can define the concatenation of two strings, denoted by ∙, recursively as follows. BASIS STEP: If w in Σ*, then w ∙ λ = w. RECURSIVE STEP: If w1 in Σ* and w2 in Σ* and x in Σ, then w1 ∙ (w2 x)= (w1 ∙ w2)x. Often w1 ∙ w2 is written as w1 w2. If w1 = abra and w2 = cadabra, the concatenation w1 w2 = abracadabra.

nondeterministic finite-state automaton (NDFSA)

M = (S, I, f, s0, F) but the transition function f assigns a set of states to every pair of state and input

Prove recursive algorithm correct

Mathematical induction and strong induction are useful (for example proving recursive algorithm for calculating a^k)

structural induction vs mathematical induction vs strong induction

Mathematical induction is a proof technique that is used to prove statements about integers. It is based on the principle that if a statement is true for a base case, and if the truth of the statement for any given case implies the truth of the statement for the next case, then the statement is true for all cases. Structural induction is a proof technique that is used to prove statements about recursively defined objects. It is based on the principle that if a statement is true for the base case(s) of a recursively defined object, and if the truth of the statement for any given case implies the truth of the statement for the next case(s), then the statement is true for all cases. Full trees - height is two subsroots plus a root, so each recursive new tree is 1+max(height(a), height(b)) Strong induction is a proof technique that is similar to mathematical induction, but it allows you to assume that the statement is true for all cases up to a certain point, rather than just the previous case. This can be useful when the statement you are trying to prove is not just about the previous case, but about all previous cases.

Congruence Manipulation

Multiplying both sides by an integer, adding an integer to both sides preserves validity Division by an integer on both sides is not always valid (dont divide the number inside (mod #))

polynomial-time problems

P is a class of decision problems that can be solved by a deterministic Turing machine in polynomial time. NP is a class of decision problems that can be solved by a non-deterministic Turing machine in polynomial time. In other words, a decision problem is in P if there is a deterministic Turing machine that can solve the problem in a number of steps that is polynomial in the size of the input. A decision problem is in NP if there is a non-deterministic Turing machine that can solve the problem in a number of steps that is polynomial in the size of the input, and for every possible computation path, the machine halts with the correct answer.

Tractability

Problems in P are called tractable, whereas problems not in P are called intractable

Strong Induction (complete induction, the second principle of mathematical induction)

Prove that P(n) true for all positive integers n, where P(n) is a propositional function. Two steps: Basis step: verify P(1) is true Inductive step: show that [P(1)^P(2)^...^P(k)] -> P(k+1) holds for all positive integers k, assume [ ] statement true, show P(k+1) is also true Example: Show that if n is an integer greater than 1, then n can be written as the product of primes. Solution: Let P(n) be the proposition that n can be written as a product of primes. BASIS STEP: P(2) is true since 2 itself is prime. INDUCTIVE STEP: The inductive hypothesis is P(j) is true for all integers j with 2 ≤ j ≤ k. To show that P(k + 1) must be true under this assumption, two cases need to be considered: If k + 1 is prime, then P(k + 1) is true. Otherwise, k + 1 is composite and can be written as the product of two positive integers a and b with 2 ≤ a ≤ b < k + 1. By the inductive hypothesis a and b can be written as the product of primes and therefore k + 1 can also be written as the product of those primes.

More powerful machines

Pushdown Automaton (PDA): includes a stack, which provides unlimited memory. We can use a PDA to recognize {0n1n | n = 0, 1, 2, ...}, but no PDA recognizes the set {0n1n2n | n = 0, 1, 2, ...}. Linear Bounded Automaton (LBA): More powerful than pushdown automata. We can use a LBA to recognize {0n1n2n | n = 0, 1, 2, ...}, but there are languages generated by phrase-structure grammars that cannot be recognized by a LBA. Turing Machine (TM): Yet more powerful machines (to be studied in the next section) which can recognize all languages generated by phrase-structure grammars

Addition Machine

Recall the conventional procedure to add (xn...x1x0)2 and (yn...y1y0)2 . First, the bits x0 and y0 are added, producing a sum bit z0 and a carry bit c0. Next the bits x1 and y1 are added together with the carry bit c0. This gives a sum bit z1 and a carry bit c1. We can construct a finite state machine that uses just two states. The start state s0 is used to remember that the previous carry is 0. The other state s1 is used to remember that the previous carry is 1. (For simplicity, we assume that both xn and yn are 0.) The inputs are pairs of bits. The transitions and the outputs are constructed from the sum of the two bits in the input and the carry represented by the state. For example, when the machine is in state s1 and receives 01 as input, the next state is s1 and the output is 0, because the sum 0 + 1 + 1 =(10)2.

Arithmetic modulo m properties

Same as addition and multiplication Closure: If a and b belong to Zm , then a +m b and a ∙m b belong to Zm Associativity: If a, b, and c belong to Zm , then (a +m b) +m c = a +m (b +m c) and (a ∙m b) ∙m c = a ∙m (b ∙m c) Commutativity: If a and b belong to Zm , then a +m b = b +m a and a ∙m b = b ∙m a Identity elements: The elements 0 and 1 are identity elements for addition and multiplication modulo m, respectively. If a belongs to Zm , then a +m 0 = a and a ∙m 1 = a.

What is the decimal expansion of the number with hexadecimal expansion (2AE0B)16

The hexadecimal expansion needs 16 digits, but our decimal system provides only 10. So letters are used for the additional symbols. The hexadecimal system uses the digits {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F}. The letters A through F represent the decimal numbers 10 through 15 2∙16^4 + 10∙16^3 + 14∙16^2 + 0∙16^1 + 11∙16^0 = 175627

Recursive def of string length

The length of a string can be recursively defined by: l(λ) = 0; l(wx) = l(w) + 1 if w ∊ Σ* and x ∊ Σ.

Pidgeonhole Principle

The pigeonhole principle is a mathematical concept that states that if n items are put into m containers, with n > m, then at least one container must contain more than one item1. For example, if you have two pairs of socks, one black and one white, and you randomly pull three socks from the drawer, then you must have at least two socks of the same color.

Regular expression

The regular expressions over a set I are defined recursively by: the symbol Ø is a regular expression; the symbol lambda is a regular expression; the symbol x is a regular expression whenever x in set I; the symbols (AB), (A U B), and A* are regular expressions whenever A and B are regular expressions. for sets, the set concatenation AB of {a, b} and {c, d} is {ac, ad, bc, bd}. Set union A U B produces a new set that contains all the elements from both original sets. For example, the set union of {a, b} and {c, d} is {a, b, c, d}.

Find the octal and hexadecimal expansions of (11 1110 1011 1100)2

To convert to octal, we group the digits into blocks of three (011 111 010 111 100)2, adding initial 0s as needed. The blocks from left to right correspond to the digits 3,7,2,7, and 4. Hence, the solution is (37274)8 To convert to hexadecimal, we group the digits into blocks of four (0011 1110 1011 1100)2, adding initial 0s as needed. The blocks from left to right correspond to the digits 3,E,B, and C. Hence, the solution is (3EBC)16

Unary representation of integers

To represent an input that is a k-tuple of integers, we represent each integer in the k-tuple separately and separate these representations using asterisks. For example, (2,0,1,3) is represented by 111*1*11*1111.

Complexity of Merge

Two sorted lists with m elements and n elements can be merged into a sorted list using no more than m + n − 1 comparisons. comparisons to merge a list of n elements is O(nlogn) At the end of the splitting process, we have a binary tree with m levels, and 2m lists with one element at level m. each element in the array is copied log(n) times. The number of elements in the array is n. So, the total number of copies is n log(n)

Types of Grammars

Type 2 grammars are called context-free grammars. A language generated by a context-free grammar is called a context-free language. Type 1 grammars are called context-sensitive grammars. Type 3 are called regular grammars.A language generated by a context-sensitive grammar is called a context-sensitive language (or a regular language)

Generalized Induction

Used to prove results about sets other than ones with integers that are well-ordered (for example ones that are lexicographically ordered) base case: prove smallest one inductive: Specify that (x1 ,y1) is less than or equal to (x2,y2) according to a stated lexicographic ordering, then prove statement works for (x1, y1) and so implies the next statement for some reason (bullshit)

The set of all words over V

V*

Base b representations (examples next)

We can use positive integer b greater than 1 as a base, because of this theorem: Theorem 1: Let b be a positive integer greater than 1. Then if n is a positive integer, it can be expressed uniquely in the form: n = akb^k + ak-1b^k-1 + .... + a1b + a0 where k is a nonnegative integer, a0,a1,.... ak are nonnegative integers less than b, and ak≠ 0. The aj, j = 0,...,k are called the base-b digits of the representation. The representation of n given in Theorem 1 is called the base b expansion of n and is denoted by (akak-1....a1a0)b

Decidability

When there is an effective algorithm that decides whether instances of a decision problem are true, we say that this problem is solvable or decidable. However, if no effective algorithm exists for solving a problem, then we say the problem is unsolvable or undecidable.

A language recognized by an NDFSA is also recognized by

a deterministic FSA

Finite State Machine

a machine that consists of a fixed set of possible states, a start state, an input alphabet, and a transition function that assigns a next state to every (state, input) pair finite-state machine M =(S, I, O, f, g, s0) consists of a finite set S of states, a finite input alphabet I, a finite output alphabet O, a transition function f that assigns to each state and input pair a new state, an output function g that assigns to each state and input pair an output, and an initial state s0

a ≡ b (mod m) vs a *mod* m = b

a ≡ b (mod m) is a relation on the set of integers In a *mod* m = b,the notation mod denotes a function

decimal notation

base 10 notation when we write 965, we mean 9∙10^2 + 6∙10^1 + 5∙10^0

Recursively defined sets/structures

basis step: specifies initial collection of elements recursive step: gives rules for forming new elements in set from those already known to be in the set recursive def sometimes has an exclusion rule: specifies that the set contains nothing other than elements specified in basis step and generated by rules in recursive step (we will always assume this rule holds, even if not explicitly mentioned) STRINGS EXAMPLE Definition: The set Σ* of strings over the alphabet Σ: BASIS STEP: λ ∊ Σ* (λ is the empty string) RECURSIVE STEP: If w is in Σ* and x is in Σ, then wx ∊ Σ*. Example: If Σ = {0,1}, the strings in Σ* are the set of all bit strings, {λ,0,1, 00,01,10, 11, etc}. Example: If Σ = {a,b}, show that aab is in Σ*. Since λ ∊ Σ* and a ∊ Σ, a ∊ Σ*. Since a ∊ Σ* and a ∊ Σ, aa ∊ Σ*. Since aa ∊ Σ* and b ∊ Σ, aab ∊ Σ*.

The frog writes neatly - explain in terms of semantics and syntax

correct syntax, bad semantics

Other integer representations

decimal = base 10 bases b = 2 (binary), b = 8 (octal) , and b= 16 (hexadecimal) are important for computing and communications

Unit Delay Machine

delays an input string by one unit of time, that is, produces as output the bit string 0x1x2...xk-1 given the input bit string x1x2...xk-1

A vocabulary (or alphabet) V is a

finite set of elements called SYMBOLS

A word or sentence over a vocabulary V is a

finite string of elements from V

GCD recursive algorithm

gcd(a,b) = gcd(b mod a, a) WHERE input a < b gcd(0, b) = b is base case, return b, the gcd

Properties of divisibility

i. If a | b and a | c, then a | (b + c) ii. If a | b, then a | bc for all integers c iii. If a | b and b | c, then a | c If a, b, and c be integers, where a ≠0, such that a | b and a | c, then a | mb + nc whenever m and n are integers

Recursive modular exponentiation

idk bruh its purpose is to accomplish b^n mod m where b, n, m are integers and m >= 2 and n >= 0 and 1 <= b <= m

A string x is recognized (or accepted) by and FSA if

it takes the initial state s0 to a final state

formal languages

languages that are designed by people for specific applications

Semantics

meaning of a sentence

mod m of products and sums

mod of sum (a + b) (mod m) = ((a mod m) + (b mod m)) mod m mod of product ab mod m = ((a mod m) (b mod m)) mod m

Replaceable elements are called

non-terminals (sentence, noun phrase (article followed by an adjective followed by a noun), etc)

Every production P must contain at least

one non-terminal on its left side

structural induction

prove property of elements in a recursively defined set basis step: show that the result holds for all elements specified in the basis step of the recursive def recursive step: show that if statement is true for each of the elements used to construct new elements in the recursive step of def, the result holds for these new elements

An FSA recognizes a

regular set

productions of grammar

rules that specify when we can replace a string V* with another string. We denote z0 -> z1 the production that specifies z0 can be replaced by z1 within a string

Recognized (accepted) language

set of all strings recognized by machine M

The concatenation of A and B, where A and B are subsets of V*, denoted by AB

set of all strings that can be formed from combining that elements in A and B Let A = {0, 11} and B = {1, 10, 110} Then AB = {01, 010, 0110, 111, 110, 11110} and BA = {10, 111, 100, 1011, 1100, 11011} AB!=BA

The set N = V - T

set of non-terminal symbols

Zm

set of nonegative integers less than m {0, 1, ...}

Let G be a phase-structure grammar. The language generated by G, denoted L(G), is the

set {} of all strings or terminals that are derivable from the starting state S using the given productions

recursive algorithm

solves a problem by reducing it to an instance of the same problem with a smaller input termination occurs when instance of problem is reduced to an initial case for which a solution is known

Backus-Naur Form (BNF)

sometimes used to specify type 2 grammar, often used to specify syntactic rules of computer languages - productions of a type 2 grammar have a single nonterminal symbol on their left-hand side - All the productions with the same nonterminal symbol on the left-hand side are combined into one statement using the symbol ::= instead of →. Additionally, all nonterminal symbols are enclosed in brackets (〈〉), and the right-hand side of productions are separated by bars. For example, the productions A →Aa, A →a, and A →AB are written as 〈A〉 ::= 〈A〉a | a | 〈A〉 〈B〉.

A language over V is a

subset of V*

Elements of V that cannot be replaced by other symbols are called

terminals (a, the, rabbit)

nondeterministic Turing machine

the restriction that no two transition rules begin with the same pair (s, x) is eliminated. A NDTM T recognizes a string x if and only if there exists some sequence of transitions of T that ends in a final state when the machine starts in the initial position with x written on the tape

Two FSA are equivalent if

they recognize the same language

Binary Modular Exponentiation

to compute bn, we need only compute the values of b, b2, (b2)2 = b4, (b4)2 = b8 , ..., and the multiply the terms in this list, where aj = 1. Example: Compute 311 using this method. Solution: Note that 11 = (1011)2 so that 311 = 38 32 31 = ((32)2 )2 32 31 = (92 )2 ∙ 9 ∙3 = (81)2 ∙ 9 ∙3 =6561 ∙ 9 ∙3 =117,147

set of rooted trees

trees that have a root

Σ* and Σ

Σ = set of symbols Σ* = set of symbols formed from symbols in Σ

multiplication modulo m

∙m a ∙m b = (a ∙ b) mod m 7 ∙11 9 = (7 ∙ 9) mod 11 = 63 mod 11 = 8


संबंधित स्टडी सेट्स

"Is Our Gain Also Our Loss?" Test Review

View Set

BL 3030 A&P Allen test answers test no. 3 Ch.9 and Ch. 11

View Set

History of Photography Ch.3: Popular Photography and the Aims of Art

View Set

Chapter 32: Structure and Function of the Kidney

View Set

Chapter 7 - Texas Real Estate License Act - Mini Quiz

View Set

PrepU - Chapter 15 - Assessing Head and Neck

View Set