Implement both a Binary Search Tree (BST) and a Trie and compare the operation speeds within the context of a real-world scenario: a cataloging system for a library.
-
A) Implement a BST.
-
Each node should have a string value representing a book title.
-
Implement insertion, deletion, and search operations.
-
B) Implement a Trie.
-
Each node should represent a character of a book title.
-
Implement insertion, deletion, and search operations.
- Insertion:
- Measure the time taken to insert book titles into the BST and the Trie. Use a list of 10,000 book titles for this comparison. (Suggestion: Generate random strings in a loop for insertion)
- Deletion:
- Measure the time taken to delete book titles from the BST and the Trie. Use the same list of 10,000 book titles for this comparison.
- Search:
- Measure the time taken to search for book titles in the BST and the Trie. Use the same list of 10,000 book titles for this comparison.