Binary Question
Problem : Let B be the smallest set of binary strings such
that:
. 10 \in B, and
. if b \in B, then b00 \in B.
Let f: B -> N be the function that maps each binary string
b to the numbe
Algorithm Correctness Examples
Example 1: recursive binary search
RecBinSearch(x,A,f,l)
if f = l then
if A[f] = x then
return f;
else
return 0;
end if
else
m := (f + l) div 2;
cfw_ integer division
i
Termination:
- Standard method: find an expression E involving program variables such
that:
. E_k is a natural number for all k;
. for all k >= 0, E_cfw_k+1 < E_k if the loop is executed at least k+1
Algorithm Complexity
- Standard measures for algorithms: space (memory) and time (speed). In
this course, we will consider only time.
- Want measure independent of one machine or implementation, and r
Algorithm Complexity Tips and Examples
- Example 1: Prove 2n^2 + 6n + 2 is O(n^2).
Scratch work (NOT part of proof): for all n >= 1, 2n^2 <= 2n^2
and 6n <= 6n^2 and 2 <= 2n^2, so 2n^2 + 6n + 2 <= 2n^2
Algorithm Correctness
- We don't need just programs that usually work
they should always work correctly.
- We have to prove they produce "correct output" on "acceptable inputs", these
are expressed in
Closure properties of FSA-accepted languages
If we apply an operation on a language that is accepted by a FSA and
the result is also a language accepted by a FSA we say the operation
has closure prope
Satisfiability and validity:
- The truth-value of a formula F under an interpretation I=(S,v) is
defined as follows:
. if F is an atomic formula P(t_1,.,t_m), where each t_i is a term
(either a variab
Constructing a NFSA
Example 1: Construct a NFSA that accepts the language of
(010+01)^*010(1)^*+1^*.
Answer:
Following the rules described in the notes (and lectures), we get
the following NFSA, with
CNF Form
We can also find a formula in CNF form which has the same truth table as
f(p,q,r) given above, and therefore is LEQV to it:
p q r | f(p,q,r)
-1 1 1 |
1
1 1 0 |
1
1 0 1 |
1
1 0 0 |
0
0 1 1 |
1
Advanced Finite State Automata
- Example: Come up with F.S.A. that recognizes L = cfw_ w in cfw_a,b* : w
contains an even number of a's . Use states that represent information
about string processed s