220 likes | 356 Views
Data Structures and Algorithms. Semester Project – Fall 2010 Faizan Kazi Comparison of Binary Search Tree and custom Hash Tree data structures. Project Description. This project uses: Hash + Tree structures Tree Structures Efficient Searching and Sorting and Shuffling
E N D
Data Structures and Algorithms Semester Project – Fall 2010 FaizanKazi Comparison of Binary Search Tree and custom Hash Tree data structures
Project Description • This project uses: • Hash + Tree structures • Tree Structures • Efficient Searching and Sorting and Shuffling • Speech and manual search to locate terms • It is based on Microsoft’s .Net Framework 4 • The code was written in C# on Visual Studio 2010
Goal • Prove that Tree and Hash Structures are efficient • Use Speech for searching
Issues Encountered • Inserting data into the two data structures • Shuffling sorted Data • Speech API provided by Microsoft is subject to restrictions
Hash Tree • One of the problems with Hash Structures • Collisions • Solution: • Chaining • Embed Binary Search Trees into each Key Value Pair. All Colliding Elements can be inserted into a BST. Retrieval: O(1) best case , O(log(n)) worst case Insertion: O(1) best case , O(log(n)) worst case
Binary Search Tree • Does not allow duplicate items Retrieval: O(log(n)) average case Insertion: O(log(n)) average case
Shuffling – Page 1 • Problem: all dictionary words being inserted into the data structures were sorted! • This will make the Tree linear: O(n) Example: try inserting a,b,c,d into a tree
Shuffling – Page 2 • Initial Solution: do a recursive insert into the binary search tree by calculating the optimal node and left and right child strings from the string array. • Problem: this will produce a near optimal tree but could be at a disadvantage to the hash tree. Eg: 1 2 3 4 5 6 7 Root = 4, LC = 2, RC = 6
Shuffling – Page 3 • Solution: Fisher-Yates shuffle • For a count of 0 to N, choose random indexes into the string array and swap the items • This is O(n) and produces a good mix. • The fact is, O(n) is completely under our control, and does not have to depend on the size of the data. If you want a very small shuffle, run the technique n/4 times. If you want to make sure it is extremely shuffled call it 2n times.
The Demo Program • The Demo program is written in C# (most similar to Java) and designed to run on the Microsoft .Net Framework 4 (you may have to download this or it may ask you if it can automatically download it). • It will demonstrate, through manual, random or speech directed searching just how efficient these data structures are.
The Demo Program – Step 1 Click “Next” to begin
Step 2 – Initializating Data Structures Select the list, modify the selected size, and click “Go!”
Step 3 – Test Configuration Select the Number of iterations for each search term (small numbers will probably give you 0 millisecond results, they’re that fast!
Step 4 – Search Method 1 – Manual Type a word from the list into the search box and click “Search!”
Step 4 – Search Method 2 – Random Click “Random”
Step 4 – Search Method 3 – Voice Just select a word from the list and say “Search (word)” for example, “Search action”. Troubleshooting: Make sure that Microsoft’s Speech engine is running on your pc. There should be a speech icon in the taskbar or at the top of your screen (once your click “Go!”). Check to make sure it is “On” and not in “Sleep Mode” or “Off”. Make sure your laptop’s built in mic works, or that your mic is properly plugged in. Access Recording Devices from the Volume Control in the taskbar to check if your mic works and is enabled.
Step 5 – Search Results Search results show up on the lower right and speech results show up on the top right
Step 6 – Data Structure Visualization Check out the graphical representations of the HashTree and BSTree. Check out the difference in depths
Hash Tree Visualization Every index in the Hash Table has its own Binary Search Tree
Binary Search Tree Visualization Somewhere down there The Binary Search Tree has one root, and for every node, one left and one right child
Conclusion • That’s it! • I hope you find the program useful and informative about these two datastructures. • If you have any questions you may contact me at: • +92-300-254-1119 • faizan@faizan-kazi.com