0% found this document useful (0 votes)
37 views50 pages

Theoretical Foundations of CS / Wide Variety of Problems - Frameworks/models To Solve Problems - Analyze Problems & Algorithms

The document introduces the theoretical foundations of computer science including frameworks for solving problems, analyzing problems and algorithms, and discusses why studying the theory of computation is important for understanding mathematical properties of problems and algorithms, defining provable limits, and providing abstract structures. It also outlines goals for studying principles of problems themselves to determine if solutions exist and are efficient, and defines key terminology needed to understand languages and strings as essential concepts in the theory of computation.

Uploaded by

Ratan Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views50 pages

Theoretical Foundations of CS / Wide Variety of Problems - Frameworks/models To Solve Problems - Analyze Problems & Algorithms

The document introduces the theoretical foundations of computer science including frameworks for solving problems, analyzing problems and algorithms, and discusses why studying the theory of computation is important for understanding mathematical properties of problems and algorithms, defining provable limits, and providing abstract structures. It also outlines goals for studying principles of problems themselves to determine if solutions exist and are efficient, and defines key terminology needed to understand languages and strings as essential concepts in the theory of computation.

Uploaded by

Ratan Jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 50

Introduction

• Theoretical foundations of CS / wide


variety of problems

• Frameworks/models to solve problems

• Analyze problems & algorithms

1
Why Study the Theory of
Computation?
Implementations come and go.

Chapter 1 2
Why study this?
Science of Computing
• Mathematical Properties (problems &
algorithms) having nothing to do with
current technology or languages

• Provides Abstract Structures


• Defines Provable Limits

3
Goals
Study Principles of Problems themselves
• Does a solution exist?
– If not, is there a restricted variation?
• Can solution be implemented in fixed
memory?
• Is Solution efficient?
– Growth of time & memory with problem size?
• Are there equivalent groups of problems?
4
Applications of the Theory
• Programming languages, compilers, & context-free
grammars.
• FSMs (finite state machines) for parity checkers,
vending machines, communication protocols, &
building security devices.
• Interactive games as nondeterministic FSMs.
• Natural languages are mostly context-free. Speech
understanding systems use probabilistic FSMs.
• Computational Biology: DNA & proteins are strings.
• Artificial Intelligence

5
Languages and Strings

It includes the TERMINOLOGY required to be


successful in this course.
KNOW this chapter & ALL DEFINITIONS!!

6
Alphabet - 
• An alphabet is a non-empty, finite set of
characters/symbols
– Use  to denote an alphabet

• Examples
 = { a, b }
 = { 0, 1, 2 }
 = { a, b, c,…z, A, B, … Z }
 = { #, $, *, @, & }
7
Powers of an alphabet
• If Σ is an alphabet, we can express the set
of all strings of a certain length from that
alphabet by using the exponential notation
– Σ k: the set of strings of length k, each of
whose is in Σ
– Examples:
– Σ 0 : { ǫ }, regardless of what alphabet Σ is.
That is ǫ is the only string of length 0

8
– If Σ = { 0, 1 }, then:
1. Σ 1 = { 0, 1 }
2. Σ 2 = {00, 01, 10, 11 }
3. Σ 3 = {000, 001, 010, 011, 100, 101, 110, 111 }

– Σ is an alphabet; its members 0 and 1 are


symbols 2.
– Σ 1 is a set of strings; its members are strings
(each one of length 1)
9
Strings
• A string is a finite sequence, possibly
empty, of characters drawn from some
alphabet .
•  is the empty string
• * is the set of all possible strings over an
alphabet .

10
Example Alphabets & Strings

Alphabet name Alphabet symbols Example strings


The lower case {a, b, c, …, z} , aabbcg, aaaaa
English alphabet

The binary {0, 1} , 0, 001100,11


alphabet

A star alphabet { ,  ,  , , , } , , 


A music
alphabet {w, h, q, e, x, r, } , q w , w w r

11
Functions on Strings
Length:
• |s| is the length of string s
• |s| is the number of characters in string s.

|| = 0
|1001101| = 7

#c(s) is defined as the number of times that c occurs in s.

#a(abbaaa) = 4.

12
More Functions on Strings
Concatenation: the concatenation of 2 strings s
and t is the string formed by appending t to s; written
as s||t or more commonly, st

Example:
If x = good and y = bye, then xy = goodbye
and yx = byegood

• is the identity for concatenation of strings. So,


x (x  =  x = x)
•Concatenation is associative. So,
s, t, w ((st)w = s(tw))
13
More Functions on Strings
Replication: For each string w and each natural
number k, the string w k is:

w0=
w k+1 = w k w

Examples:
a3 = aaa
(bye)2 = byebye
a0b3 = bbb
b2y2e2 = ??

Natural Numbers {0,1,2,…}


14
More Functions on Strings
Reverse: For each string w, w R is defined as:

if |w| = 0 then w R = w = 

if |w| = 1 then w R = w

if |w| > 1 then:


a   (u  * (w = ua))
So define w R = a u R

15
Concatenation & Reverse of Strings

Theorem: If w and x are strings, then (w x)R = x R w R.

Example:

(nametag)R = (tag)R (name)R = gateman

16
Concatenation & Reverse of Strings
Proof: By induction on |x|:

|x| = 0: Then x = , and (wx)R = (w )R = (w)R =  wR = R wR = xR wR.

n  0 (((|x| = n)  ((w x)R = xR wR)) 


((|x| = n + 1)  ((w x)R = xR wR))):

Consider any string x, where |x| = n + 1. Then x = u a for some


character a and |u| = n. So:

(w x)R = (w (u a))R rewrite x as ua


= ((w u) a)R associativity of concatenation
= a (w u)R definition of reversal
= a (uR wR) induction hypothesis
= (a uR) wR associativity of concatenation
= (ua)R wR definition of reversal
= x R wR rewrite ua as x
17
Relations on Strings - Substrings
o Substring: string s is a substring of string t if s
occurs contiguously in t
o Every string is a substring of itself
o  is a substring of every string
o Proper Substring: s is a proper substring of t
iff s ≠ t
o Suppose t = aabbcc.
o Substrings: , a, aa, ab, bbcc, b, c, aabbcc
o Proper substrings?
o Others? 18
The Prefix Relations
s is a prefix of t iff x  * (t = sx).

s is a proper prefix of t iff s is a prefix of t and s  t.

Examples:

The prefixes of abba are: , a, ab, abb, abba.


The proper prefixes of abba are: , a, ab, abb.

•Every string is a prefix of itself.


• is a prefix of every string.

19
The Suffix Relations

s is a suffix of t iff x  * (t = xs).

s is a proper suffix of t iff s is a suffix of t and s  t.

Examples:

The suffixes of abba are: , a, ba, bba, abba.


The proper suffixes of abba are: , a, ba, bba.

•Every string is a suffix of itself.


• is a suffix of every string.

20
Defining a Language
A language is a (finite or infinite) set of strings over a (finite)
alphabet .

Examples: Let  = {a, b}

Some languages over :


={} // the empty language, no strings
{} // language contains only the empty string
{a, b}
{, a, aa, aaa, aaaa, aaaaa}

21
*
• * is defined as the set of all possible
strings that can be formed from the
alphabet *
– * is a language

• * contains an infinite number of strings


– * is countably infinite

22
* Example
Let  = {a, b}
* = {, a, b,aa,ab,ba,bb,aaa,aab,… }

Later, we will spend some more time


studying *.

23
Defining Languages
Remember we are defining a set
Set Notation:
L = { w  * | description of w}
L = { w  {a,b,c}* | description of w}

• “description of w” can take many forms but


must be precise
• Notation can vary, but must precisely define
24
Example Language Definitions

L = {x  {a, b}* | all a’s precede all b’s}

•aab,aaabb, and aabbb are in L.


•aba, ba, and abc are not in L.
•What about , a, aa, and bb?

25
Example Language Definitions

Let  = {a, b}
• L = { w  * : |w| < 5}
• L = { w  * | w begins with b}
• L = { w  * | #b(w) = 2}
• L = { w  * | each a is followed by
exactly 2 b’s}
• L = { w  * | w does not begin with a}

26
More Examples

Using prefix

L = {w  {a, b}*: no prefix of w contains b}

L = {w  {a, b}*: no prefix of w starts with b}

L = {w  {a, b}*: every prefix of w starts with b}

27
Using replication

L = {an : n  0}

L = {ba2n : n  0}

L = {bnan : n  0}

28
Enumeration

Enumeration: to list all strings in a language (set)

• Arbitrary order

• More useful: lexicographic order


• Shortest first
• Within a length, dictionary order
• Define linear order of arbitrary symbols

29
Lexicographic Enumeration
{w  {a, b}* : |w| is even}
{, aa, ab, bb, aaaa, aaab, …}

What string is next?


How many strings of length 4?
How many strings of length 6?

30
Cardinality of a Language

•Cardinality of a Language: the number of strings


in the language
•| L |
•Smallest language over any  is , with
cardinality 0.
•The largest is *.
• Is this true?
• How big is it?
•Cardinality of * is infinite.
31
Countably Infinite
Theorem: If    then * is countably infinite.
Proof: The elements of * can be lexicographically
enumerated by the following procedure:
• Enumerate all strings of length 0, then length 1,
then length 2, and so forth.
• Within the strings of a given length, enumerate
them in dictionary order.
This enumeration is infinite since there is no longest
string in *. Since there exists an infinite enumeration of
*, it is countably infinite.

32
How Many Languages Are There?

Theorem: If    then the set of languages


over  is uncountably infinite (uncountable).

Proof: The set of languages defined on  is


P(*). * is countably infinite. By Theorem A.4,
if S is a countably infinite set, P(S) is
uncountably infinite. So P(*) is uncountably
infinite.

33
Functions on Languages- refer notes

Set (Language) functions


Have the traditional meaning
• Union
• Intersection
• Complement
• Difference

Language functions
• Concatenation
• Kleene star
34
• Let  = {a,b}
L1 = {strings with even no of a’s}
L2 = {strings with no b’s}

Find :
L1 U L2 =
L1 ∩ L2 =
L2 – L1 =
¬(L2 - L1) =

35
Concatenation of Languages
If L1 and L2 are languages over :

L1L2 = {w : s  L1 & t  L2 w = st }

Examples:
L1 = {cat, dog}
L2 = {apple, pear}
L1 L2 ={catapple, catpear, dogapple, dogpear}
L2 L1 ={applecat,appledog,pearcat,peardog}

36
Concatenation of Languages
{} is the identity for concatenation:

L{} = {}L = L

 is a zero for concatenation:

L=L=

37
Concatenating Languages Defined
Using Variables

The scope of any variable used in an expression that


invokes replication will be taken to be the entire
expression.

L1 = {an: n  0}
L2 = {bn : n  0}

L1 L2 = {anbm : n, m  0}
L1L2  {anbn : n  0}

38
Kleene Star
L* - language consisting of 0 or more concatenations of
strings from L

L* = {}  {w  * : w = w1 w2 … wk, k  1 &


w1, w2, … wk  L}

Example:

L = {abc,pqr,xyz}

L* = {, abc,pqr,xyz, abcabc,abcpqr,xyzpqrxyz,


pqrabcabcabcxyz …}

39
The + Operator
L+ = language consisting of 1 or more
concatenations of strings from L

L+ = L* - {} iff   L

40
Semantics: Assigning Meaning to Strings

When is the meaning of a string important?

A semantic interpretation function assigns


meanings to the strings of a language.

41
Uniqueness???
• Chocolate, please.
• I’d like chocolate.
• I’ll have chocolate today.
• I guess I’ll have chocolate.

They all have the same meaning!

42
Uniqueness???
Hand
• Give me a hand.
• I smashed my hand in the door.
• Please hand me that book.

These all have different meanings!!!

43
Uniqueness in CS???
• int x = 4; x++;
• int x = 4; ++x;
• int x = 4; x = x + 1;
• int x = 5;

These all have the same result/meaning!

44
Defining a task: language
recognition
• Goal : build a framework, into which
computational problems can be casted
• Framework: Language recognition
• Given:
– Definition of L
– String w
“Is w in L?”
– Decision problem – requires ans in yes/no
45
• Encoding:

– Problems can be casted as a problem of


deciding whether string is in language
– Problems which are already stated as
decision problems – prime no checking
– what about problems like multiplying 2 no.s,
sorting no.s, retrieving values from
database…
– Reformulate / Redefine…

46
• Ex. 1 Primary no testing

– Problem: non –ve int n, is it prime?


– Encoding: non –ve no.s as binary string
– Language: {w is binary encoding of prime no}

47
• Ex. 2 Pattern matching on web

– Problem: search string w


web document d
– On i/p w, should search engine return d?
– Language: {<w,d> :d is candidate match for
query w}
– Refer textbook for more ex.

48
• Casting problems as a decision question

– Problem: given a list of integers, sort it


– Encoding: examine pair of list & decide 2nd list
corresponds to sorted version of 1st list
– Language: L={ w1#w2: w1 is of the for
int1,int2,int3…intn,
w2 is of the same form, sorted, and having
same elements as w1}
Refer text book for more examples

49
Hierarchy of languages

50

You might also like