2016년 12월 29일 목요일

2. Models of Computation, Document Distance





Models of Computation, Document Distance


Goals

  1. What’s an algorithm and time?
  2. RAM & Pointer Machine
  3. Document Distance


What’s an algorithm?


- Mathematical abstraction of computer program
- Computational procedure to solve a problem


Model of Computation

Def) set of allowable operations used in computation and their respective costs.(https://en.wikipedia.org/wiki/Model_of_computation)
- cost (time, space, … ) of each operation
- cost of algorithm = sum of operations costs

RAM & Pointer Machine


Random Access Machine (RAM)
- modelled by a big array
- ϴ(1) registers (each 1 word
- In ϴ(1) time, can load word / compute / store …
- word : w >=lg(mem.size) bits
- realistic & powerful -> implement abstraction

Pointer Machine
- dynamically allocated objects
- object has O(1) fields
- field = word or pointer to object / NULL

Python

  • “List” is actually array (RAM)
    • L[i] = L[i] + 5 -> ϴ(1) time
  • object with O(1) attributes (Pinter machine)
    • x = x.next -> ϴ(1)
  • List
    • L.append(x) -> ϴ(1)
    • L = L1 + L2  -> ϴ(1+|L1|+|L2|)
    • L1.extend(L2) -> ϴ(1 + |L1|)
    • L2 = L1[i:j] : O(L)
    • b = x in L / L.index(x) / L.find(x) : O(|L|)
    • len(L) -> ϴ(1)
    • L.sort() -> ϴ(|L|lg(|L|))
      • via comparison sort
  • dict
    • D[key] = val -> ϴ(1) time with high probability
  • set / heap(lec4) / long(lec11)


Document Distance


[MIT 6.006 Introduction to Algorithms, Fall 2011, http://ocw.mit.edu/6-006F11]

댓글 없음:

댓글 쓰기