Presentation is loading. Please wait.

Presentation is loading. Please wait.

Complexity, etc. Homework. Comparison to computability. Big Oh notation. Sorting. Classwork/Homework: prepare presentation on specific sorts. Presentation.

Similar presentations


Presentation on theme: "Complexity, etc. Homework. Comparison to computability. Big Oh notation. Sorting. Classwork/Homework: prepare presentation on specific sorts. Presentation."— Presentation transcript:

1 Complexity, etc. Homework. Comparison to computability. Big Oh notation. Sorting. Classwork/Homework: prepare presentation on specific sorts. Presentation Day for some.

2 Homework CFG and PDA Regular expressions

3 Hierarchy There is a "proper" hierarchy concerning languages FSA and PDA and TM. meaning If a language is recognized by an FSA, then we can define a PDA. If a language is recognized by a PDA, we can define a TM. AND There are languages for which there is not FSA, but there is a PDA and similarly for PDA and TM.

4 Trick question Define a FSA for the language a i b j –some a's and then some b's. Define a FSA for the language a i b i –some a's and then the same number of b's.

5 Pumping lemma for FSA If A is a regular language, then there is a number p where if s is in A, and the length of s is at least p, then we can write s as s = xyz, –length of y is greater than 0 –length of xy is less than p and –xy i z is also in A. General idea: finite number of states. Set p to be number of states. So if there a string in A of length at least p, then the string s must re-visit at least 1 state. Call one such state q, then the substring from q and then back to q can be repeated.

6 Example of language that is not regular Alphabet {a,b}. All strings of the form a i b i –some number of a's followed by the same number of b's. –NOTE: the language of strings a i b j is regular.

7 Define a CFG for a i b j Try it!

8 Now, what about a i b i Write a grammar

9 Answer S => aSb S => ab Notice: this grammar is not regular. It better not be, because an application of the pumping lemma indicated that this language could not be produced by a FSA.

10 Many similar results Pumping lemma for CFL Extra credit assignment: look up and present to class.

11 Complexity calculate limit (maximum, minimum, worst case, average) amount of resources required to perform specific task –generally specific algorithm –time count of a specific type of operation –space Actual usage in any specific case may be different.

12 Comparison Computability looks at whether or not task can be done using a certain type of machine or grammar or definition of functions Complexity assumes that something can be done and complexity assessment generally looks at specific method –Note: there are proofs that say (something like) Any method will take at least …..

13 Bubble sort Class example Sort subset of students by height. Designate someone as counter of compare operations Designate someone as counter of swap operations Designate someone as counter of rounds

14 Bubble sort Worst case. n elements in set Round 1: n-1 compares Round 2: n-2 compares … Round n-1: 1 compare So, average number of compares per round is (n- 1)/2 Total number of compares is (rough) (n-1) * (n-1)/2

15 Measure generally given in terms of the size of the problem and given as a bound called Big Oh notation A function f(n) is O(g(n)), n integer, if there is an integer n 0 and a constant c such that f(n) =n 0 Conceptually, if n is big enough, than the function f is bounded by a multiple of the function g.

16 Common usage of O(n) O(c) constant O(n) linear O(n 2 ) quadratic O(n p ) polynomial O(n e ) exponential

17 Easy results f(n) = n IS O(n) and also O(n 2 ) and O(n p ) Let c = 1, and n 0 = 1, then n =1 but f(n 2 ) is NOT O(n)

18 Sorts There are sorting algorithms that are better than bubble sort, that is, time is less than O(n 2 ) heap sort quick sort merge sort Assign: be able to demonstrate with a deck of cards. Sketch proof on complexity.


Download ppt "Complexity, etc. Homework. Comparison to computability. Big Oh notation. Sorting. Classwork/Homework: prepare presentation on specific sorts. Presentation."

Similar presentations


Ads by Google