1 / 23

Algorithms

Algorithms. Homework. None Next Week: Mid-Term Open book / Open laptop. Old Business. CFGs: Context Free Grammars (Ch8). Ambiguity. The Chomsky Hierarchy Type 0 > Type 1 > Type 2 > Type 3 Recursively Enumerable > CS > CF > Regular Examples Type 3: Regular (Finite State):

Télécharger la présentation

Algorithms

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Algorithms

  2. Homework • None • Next Week: Mid-Term • Open book / Open laptop

  3. Old Business

  4. CFGs: Context Free Grammars (Ch8)

  5. Ambiguity

  6. The Chomsky Hierarchy • Type 0 > Type 1 > Type 2 > Type 3 • Recursively Enumerable > CS > CF > Regular • Examples • Type 3: Regular (Finite State): • Grep & Regular Expressions • Right-Branching: A  a A • Left-Branching: B  B b • Type 2: Context-Free (CF): • Center-Embedding: C  …  x C y • Parenthesis Grammars: <expr>  ( <expr> ) • w wR • Type 1: Context-Sensitive (CS): w w • Type 0: Recursively Enumerable • Beyond Type 0: Halting Problem

  7. New Business

  8. http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-006Spring-2008/LectureNotes/index.htmhttp://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/6-006Spring-2008/LectureNotes/index.htm

  9. Hash Tables n steps n2 time Linear Time n steps n time Constant Time

  10. Profiling

  11. O(n) << O(n2) Time n = |words|

  12. Excel

  13. Group Problems by Time Bounds • log(n) • Binary Search, Fibonacci • n • tr, cat, cut, uniq, egrep • n log n • Sort • n2 • Edit Distance (http://www.csse.monash.edu.au/~lloyd/tildeAlgDS/Dynamic/Edit/) • n3 • Matrix Multiplication n2.376 • Context-Free Parsing • 2n • Factoring • Satisfiability

  14. http://ocw.mit.edu/NR/rdonlyres/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/LectureNotes/lec3.pdfhttp://ocw.mit.edu/NR/rdonlyres/Electrical-Engineering-and-Computer-Science/6-046JFall-2005/LectureNotes/lec3.pdf

  15. Summary (for Mid-Term) • Symbolic Processing v. Stat Packages • Practical • Symbolic: LISP, Wolfram Alpha • Stats: Newton’s Method, R • Fundamental • Stuff you can’t do with stat packages • LISP: Recursion, Eval, Symbolic Differentiation • Lambda Calculus • Small is Beautiful (beyond reason) • Church’s Thesis & Computability Theory

  16. Summary (continued) • Unix for Poets • Pipes: tr | sort | uniq –c • Python & NLTK • Unix for Poets (without Unix) • Objects • Polymorphism • Equivalence Classes • Partial Orders • Algorithms • Group problems by time & space bounds

  17. Introduction to Programming Traditional (Start with Definitions) Non-Traditional (Start with Examples) Recursion def fact(x): if(x <= 1): return 1 else: return x * fact(x-1) Streams: Unix Pipes Briefly mentioned Everything else • Constants: 1 • Variables:x • Objects: • lists, strings, arrays, matrices • Expressions: x == 1 • Statements: Side Effects • x = 1 (assignment) • Conditionals: • If (x<=1) return 1; • Iteration: for loops • Functions • Recursion • Streams

  18. Examples • Factorial • Fibonacci • Counting Words in a Text

  19. Python def fact(x): if(x <= 1): return 1 else: return x * fact(x-1) def fact2(x): result=1 for i in range(x): result *=(i+1); return result Recursion Iteration

  20. Out-takes

  21. Cosine Distance

  22. Inner Products

  23. Inner Product in Python def bag_of_words(words): D = {} for w in words: if(D.has_key(w)): D[w] = D[w] + 1; else: D[w]=1; return D def inner_product(D1,D2): sum = 0.0 for key in D1: if key in D2: sum += D1[key] * D2[key] return sum

More Related