Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

- What to Upload to SlideShare by SlideShare 4772316 views
- Customer Code: Creating a Company C... by HubSpot 3579648 views
- Be A Great Product Leader (Amplify,... by Adam Nash 796553 views
- Trillion Dollar Coach Book (Bill Ca... by Eric Schmidt 957115 views
- APIdays Paris 2019 - Innovation @ s... by apidays 1016648 views
- A few thoughts on work life-balance by Wim Vanderbauwhede 839186 views

1,470 views

Published on

- Speaker: Phong Vu - Software Engineer

Published in:
Technology

No Downloads

Total views

1,470

On SlideShare

0

From Embeds

0

Number of Embeds

0

Shares

0

Downloads

54

Comments

4

Likes

2

No notes for slide

- 1. Optimal Binary Search Tree Le Phong Vu
- 2. About me ▶ Le Phong Vu ▶ Member of Grokking ▶ Data structure and caching system ▶ Email: lephongvu90@gmail.com 2
- 3. Agenda ▶ Problem: Build a dictionary online with fast lookup ▶ Approach to apply OBST in dictionary application ▶ Use Dynamic programming to find OBST ▶ Optimize solution to reduce time create OBST ▶ Application of OBST 3
- 4. Problem: Build a dictionary ▶ Given an English world, you want to search its meaning quickly 4
- 5. Build a dictionary with BST apple hatch mango pizzajump Balanced binary search tree Worst-case O(log n) time per query Total cost: 2000100 Word Total search Depth of Node Cost apple 1.000.000 2 1000000 * 2 hatch 100 1 100 * 1 jump, mango, pizza 0 * 0 5
- 6. Re-structure BST apple hatch … Re-structure BST, move “apple” node to root Total cost: 1000200 Word Total search Depth of Node Cost apple 1.000.000 1 1.000.000 * 1 hatch 100 2 100 * 2 jump, mango, pizza 0 * 0 OBTIMAL BINARY SEARCH TREE 6
- 7. Approach 7 Build a balanced BST Collect search information Calculate probability search Calculate a Optimal BST Change current BST by new Optimal BST
- 8. Key and probability ▶ word key probability apple hatch jump mango 8
- 9. Dummy Key Meaning Symbol d0 d1 d2 di d0 d1 d2 d3 d5d4 apple hatch jump mango pizza< apple (apple, hatch) 9
- 10. Example 10 word key total search probability < apple 5 apple 10 (apple, hatch) … … hatch … … jump … … mango … … Total search = 100
- 11. Search time ▶ 11
- 12. Optimal Binary Search Tree ▶ Given the set probabilities p and q, can we construct a binary search tree whose expected search time is minimized? ▶ This tree is called an Optimal Binary Search Tree 12
- 13. Dynamic Programming ▶ Solves problems by combining the solutions to sub-problems. 13 Figure 1: Dynamic Programming https://itnext.io/dynamic-programming-vs-divid e-and-conquer-2fea680becbe
- 14. Step 1: The structure of OBST ▶ If an OBST has a sub-tree T, then this sub-tree T must be optimal BST. 14 Optimal BST Optimal BST Optimal BST
- 15. Step 2: Deciding root of OBST ▶ 15
- 16. Step 2: Deciding Root of OBST ▶ 16 kr Contribute e [i, r-1] Contribute e [i, r-1] Contribute W[i,j]
- 17. Step 3: Bottom-up approach ▶ 17
- 18. 18
- 19. Optimize solution ▶ 19
- 20. Application ▶ Huffman Tree ▶ Optimal routing lookup 20
- 21. Reference ▶ Le Phong Vu, “Dùng kỹ thuật quy hoạch động giải bài toán tối ưu cây nhị phân tìm kiếm” https://engineering.grokking.org/optimal-binary-search-tree/ ▶ D. Knuth, “Optimum binary search trees”, Acta Informatica www.inrg.csie.ntu.edu.tw/algorithm2014/presentation/Knuth71.pdf ▶ Thomas H. Cormen, “Introduction to algorithm”, MIT Press, 3rd Edition ▶ D. Knuth, “The art of computer programming”, volume 3 ▶ Kurt Mehlhorn, “Nearly Optimal Binary Search Tree” https://people.mpi-inf.mpg.de/~mehlhorn/ftp/mehlhorn3.pdf 21
- 22. Question 22
- 23. Example 23 An example from book: Introduction to Algorithm, 3rd edition
- 24. Example 24
- 25. Pseudocode 25

No public clipboards found for this slide

Login to see the comments