extended binary trees recurrence relations
play

Extended Binary Trees Recurrence relations After today, you should - PowerPoint PPT Presentation

Extended Binary Trees Recurrence relations After today, you should be able to explain what an extended binary tree is solve simple recurrences using patterns } Today: Extended Binary Trees (on HW9) Recurrence relations, part 1 }


  1. Extended Binary Trees Recurrence relations After today, you should be able to… …explain what an extended binary tree is …solve simple recurrences using patterns

  2. } Today: ◦ Extended Binary Trees (on HW9) ◦ Recurrence relations, part 1 } GraphSurfing Milestone 2 ◦ Two additional methods: shortestPath(T start, T end) and stronglyConnectedComponent(T key) ◦ Tests on Living People subgraph of Wikipedia hyperlinks graph ◦ Bonus problem: find a “challenge pair” – Hard to solve optimally! Longest path problem

  3. } Today: ◦ Extended Binary Trees (on HW9) ◦ Recurrence relations, part 1 } Due later: ◦ Hardy’s Taxi, part two: efficiency boost! – Some HW1 solutions took 60+ sec to find the 4 th taxicab #. Now you’ll try to find the 50,000 th one in the same time! …3 or 4 nested for-loops won’t work.

  4. Bringing new life to Null nodes!

  5. 1-2 } Not a single NULL_NODE, but many NULL_NODEs } An Extended Binary tree is either ◦ an ex exter ernal l (n (null) ll) node de , or ◦ an ( in inter ernal ) root node and two EBTs T L and T R . } We draw internal nodes as circles and external nodes as squares. ◦ Generic picture and detailed picture. } This is simply an alternative way of viewing binary trees, in which we view the external nodes as “places” where a search can end or an element can be inserted.

  6. 3-5 rty P(N): For any N>=0, any EBT with N } Pro Propert internal nodes has _______ external nodes. tion , based on the } Pro Prove by by str trong g indu ducti recursive definition. ◦ A notation for this problem: IN(T), EN(T) Hint (reminder): Find a way to relate the properties for larger trees to the property for smaller trees.

  7. A technique for analyzing recursive algorithms

  8. 6 } Split the sequence in half } Where can the maximum subsequence appear? } Three possibilities : ◦ entirely in the first half, ◦ entirely in the second half, or gins in the first half and en ends in the second half ◦ be begi

  9. Using recursion, find the maximum sum of 1. first half of sequence fir Using recursion, find the maximum sum of 2. nd half of sequence se second Compute the max of all sums that begin in 3. the first half and end in the second half ◦ (Use a couple of loops for this) Choose the largest of these three numbers 4.

  10. 7 N = array size What’s the run-time?

  11. 8 Runtime = Recursive part + non-recursive part

  12. 9 } Write a Re Recu currence ce Re Relation ◦ T(N) gives the run-time as a function of N ◦ Two (or more) part definition: – Base case, like T(1) = c – Recursive case, like T(N) = T(N/2) + 1 So, what’s the recurrence relation for the recursive MCSS algorithm?

  13. 10 10 Runtime = Recursive part + non-recursive part

  14. 10 10 Runtime = Recursive part + non-recursive part T(N) = 2T(N/2) + q (N) T(1) = 1

  15. } An equation (or inequality) that relates the n th element of a sequence to certain of its predecessors (recursive case) } Includes an initial condition (base case) ion: A function of n. } So Solu lutio } Similar to differential equation, but discrete instead of continuous } Some solution techniques are similar to diff. eq. solution techniques

  16. 11-15 11 15 } One strategy: look look for or pa patte ttern rns } Examples: As As class : ◦ T(0) = 0, T(N) = 2 + T(N-1) ◦ T(0) = 1, T(N) = 2 T(N-1) ◦ T(0) = T(1) = 1, T(N) = T(N-2) + T(N-1) On quiz On iz: ◦ T(0) = 1, T(N) = N T(N-1) ◦ T(0) = 0, T(N) = T(N -1) + N ◦ T(1) = 1, T(N) = 2 T(N/2) + N (just consider the cases where N=2 k )

  17. 14 14-15 15 } Find patterns } Telescoping } Recurrence trees } The master theorem

Recommend


More recommend