Complexity, etc. - PowerPoint PPT Presentation

About This Presentation
Title:

Complexity, etc.

Description:

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

Number of Views:62
Avg rating:3.0/5.0
Slides: 19
Provided by: Jeani178
Category:
Tags: complexity | etc | heap | sort

less

Transcript and Presenter's Notes

Title: Complexity, etc.


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 aibj
  • some a's and then some b's.
  • Define a FSA for the language aibi
  • 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 ass xyz,
  • length of y is greater than 0
  • length of xy is less than p and
  • xyiz 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 formaibi
  • some number of a's followed by the same number of
    b's.
  • NOTE the language of strings aibj is regular.

7
Define a CFG for aibj
  • Try it!

8
Now, what about aibi
  • Write a grammar

9
Answer
  • S gt aSb
  • S gt 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 n0 and a constant c such thatf(n)
    lt cg(n) if ngtn0
  • 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(n2) quadratic
  • O(np) polynomial
  • O(ne) exponential

17
Easy results
  • f(n) n IS O(n) and also O(n2) and O(np)Let c
    1, and n0 1, then n lt n2 for all values
    of ngt1
  • but
  • f(n2) is NOT O(n)

18
Sorts
  • There are sorting algorithms that are better than
    bubble sort, that is, time is less than O(n2)
  • heap sort
  • quick sort
  • merge sort
  • Assign be able to demonstrate with a deck of
    cards. Sketch proof on complexity.
Write a Comment
User Comments (0)
About PowerShow.com