2c03-review - 00017

2c03-review - 00017 - 5. a. In breadth-first search, we...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 b. Yes. For instance c(a) = 0, c(b) = 1, c(c) = 00, c(d) = 01, c(e)=10. Then the average length is 1.40. But the code does not have prefix property, and it is useless, because it results in ambiguity when decoding. 4. a. a b b a b b f(i) 0 0 0 1 2 3 g(i) 0 1 1 1 2 3 b. For naïve algorithm, every pass we fail, we move one step forward; so, we could move (n-m) times. For each pass we could compare m times, i.e. we fail at the last character. So, the time complexity should be O(m(n-m)) = O(mn). For KMP, we use O(m) to calculate failure function, and O(n) for comparison. Since we go from the beginning of x to the end once, and we never go back.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 5. a. In breadth-first search, we search the root first, then all nodes of depth 1, then all nodes of depth 2, and so on. Nodes at the same depth are searched in left-to-right order. For following tree: We search in the order of a, b, c, d, e, f, g, h. b. procedure breadth-first-search(x:elementtype, T:tree):boolean var level: QUEUE of nodes; v: node; begin v:= ROOT(T); MAKENULL_QUEUE(level); ENQUEUE(v, level); while not empty(level) do begin v:=FRONT(level); DEQUEUE(level);...
View Full Document

This note was uploaded on 12/10/2009 for the course CAS 2c03 taught by Professor Janicki during the Spring '03 term at McMaster University.

Ask a homework question - tutors are online