Static Binary Search Tree for Faster Frequent Item Searches

optimal binary search trees n.w
1 / 23
Embed
Share

Discover the concept of optimal binary search trees that facilitate faster searches for frequent items. Learn about the cost optimization and strategies for forcing key elements to be at the root, enhancing search efficiency in static binary trees.

  • Binary Search Tree
  • Optimal Trees
  • Search Optimization
  • Static Structure

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Optimal Binary Search Trees Find a static binary search tree that will allow to search for frequent items faster.

  2. Example Input:

  3. The cost of a search tree ? ????(?) = ?? (???? ??? + 1) ?=1 Our problem: Given ?1,?2, ,(??,??) find the binary search tree over ??of minimum cost. (Find the min cost and the tree) Denote the cost an optimal tree over ?1, ,??by ? 1,?

  4. Example Input:

  5. Force ??to be at the root ?? ???? ? ? 1 = ??+ ?? ???? ??? + 1 ?? ?=1 ?? ? k + ?? ???? ??? + 1 ?1, ,?? 1 ??+1, ,?? ?=?+1

  6. Force ?? to be at the root ?? ???? ? ? 1 = ??+ ?? ???? ???? + 1 + 1 ?? ?=1 ?? ? k + ?? ???? ???? + 1 + 1 ?1, ,?? 1 ??+1, ,?? ?=?+1

  7. Force ?? to be at the root ?? ? ???? ? = ??+ ???? ?? + ???? ?? ?=1 ?? ?? k ?1, ,?? 1 ??+1, ,??

  8. Force ?? to be at the root ?? ? ???? ? = ??+ ???? ?? + ???? ?? ?=1 ?? ?? ? ??(1,?) = ??+ ?(1,? 1) + ?(? + 1,?) k ?1, ,?? 1 ?=1 ??+1, ,?? ? ,? = The cost of an optimal search tree for ? , ,?? ?? ,? = The cost of an optimal search tree for ? , ,?? when ? is at the root

  9. Force ?? to be at the root ?? ? ???? ? = ??+ ???? ?? + ???? ?? ?=1 ?? ?? ??(1,?) = ?(1,?) + ?(1,? 1) + ?(? + 1,?) k ?1, ,?? 1 ??+1, ,?? ??? ? ,? = ?=

  10. Now we optimize over the choices for the root ?? ? ???? ? = ??+ ???? ?? + ???? ?? ?=1 ?? ?? ??(1,?) = ?(1,?) + ?(1,? 1) + ?(? + 1,?) k ?1, ,?? 1 ??+1, ,?? ?(?,?) = ??? ? ? ????,? = ??? ? ? ? ?(?,?) + ?(?,? ?) + ?(? + ?,?)

  11. More generally ? ,? ?? ? ???? ? = ??+ ???? ?? + ???? ?? ?= ?? ?? ??( ,?) = ?( ,?) + ?( ,? 1) + ?(? + 1,?) k ? , ,?? 1 ??+1, ,?? ?( ,?) = ??? ? ??? ,? = ??? ? ? ?( ,?) + ?( ,? ?) + ?(? + ?,?)

  12. We have a recurrence ?( ,?) = ??? ? ? ?( ,?) + ?( ,? ?) + ?(? + ?,?) = ?( ,?) + ??? ? ? ?( ,? ?) + ?(? + ?,?) ? , ? = ? = ?, ,? + ? ? , = ??? ? ? , + ? , ? + ? + ?, = ? , = ?

  13. Example ? 1 2 3 4 5 ?? 0.4 0.15 0.10 0.15 0.2 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 Can compute by a simple double loop in ? ?2time

  14. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 0.4 0.15 ?(?,?) 0.10 0.15 0.2

  15. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 0.4 0.15 ?(?,?) 0.10 0.15 0.2 ?( ,?) = ?( ,?) + ??? ? ? ?( ,? ?) + ?(? + ?,?)

  16. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 1 0.4 0.70 2 0.15 0.35 ?(?,?) ?(?,?) 4 0.10 0.35 0.15 0.50 5 0.2 ?( ,?) = ?( ,?) + ??? ? ? ?( ,? ?) + ?(? + ?,?)

  17. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 1 1 0.4 0.70 1.0 3 2 0.15 0.35 0.70 ?(?,?) ?(?,?) 4 0.10 0.35 0.75 4 0.15 0.50 5 0.2 ?( ,?) = ?( ,?) + ??? ? ? ?( ,? ?) + ?(? + ?,?)

  18. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 1 1 1 0.4 0.70 1.0 1.5 4 3 2 0.15 0.35 0.70 1.15 ?(?,?) ?(?,?) 4 0.10 0.35 0.75 4 0.15 0.50 5 0.2 ?( ,?) = ?( ,?) + ??? ? ? ?( ,? ?) + ?(? + ?,?)

  19. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 1 1 1 2 0.4 0.70 1.0 1.5 2.15 4 3 2 0.15 0.35 0.70 1.15 ?(?,?) ?(?,?) 4 0.10 0.35 0.75 4 0.15 0.50 5 0.2

  20. Example 0.4 0.55 0.65 0.8 1 0.15 0.25 0.4 0.6 ?(?,?) 0.10 0.25 0.45 0.15 0.35 0.2 1 1 1 2 0.4 0.70 1.0 1.5 2.15 2 4 3 2 0.15 0.35 0.70 1.15 1 4 ?(?,?) ?(?,?) 4 0.10 0.35 0.75 4 0.15 0.50 5 0.2 3 5

  21. Summary for j = 0 to n ? ? + 1,? = 0 for = 1 to ? for ? = 1 to ? + 1 ? = ? + 1 ? ?,? = for ? = ? to ? ? = ? ?,? + ? ?,? 1 + ? ? + 1,? if (? < ?[?,?]) ? ?,? = ? ? ?,? = ? 1 1 1 2 0.4 0.70 1.0 1.5 2.15 2 4 3 2 0.15 0.35 0.70 1.15 1 4 ?(?,?) ?(?,?) 4 0.10 0.35 0.75 4 0.15 0.50 5 0.2 3 5

  22. Running time for j = 0 to n ? ? + 1,? = 0 for = 1 to ? for ? = 1 to ? + 1 ? = ? + 1 ? ?,? = for ? = ? to ? ? = ? ?,? + ? ?,? 1 + ? ? + 1,? if (? < ?[?,?]) ? ?,? = ? ? ?,? = ? ?(?3) Can be improved to ? ?2 (Knuth 1971)

  23. Extensions for j = 0 to n ? ? + 1,? = 0 for = 1 to ? for ? = 1 to ? + 1 ? = ? + 1 ? ?,? = for ? = ? to ? ? = ? ?,? + ? ?,? 1 + ? ? + 1,? if (? < ?[?,?]) ? ?,? = ? ? ?,? = ? Can be extended to handle inputs of the form:

More Related Content