Lab 15 EC

2020_S19/wk15/lab15.txt
// The purpose of this lab is to generate n unique random integers
// into an array, sort the array, and build a balanced BinarySearchTree.
// In order to insure the random numbers are unique, we'll insert each
// random number into a BST, while "on failed insert" , we'll repeat
// generate a new random number and attempt again.
//
// In addition, we'll also insert each random number into our dynamic
// array and a hash table 
//
// Enter an element to search for:  elem
//
// A.
// We'll compare search operations with respect to time
//  - linear search (unsorted array)
//  - BinarySearchTree search (uglyTree)
//  - HashTable search (CAP 104729) hash(x): x % CAP
//
// B.
// We'll then sort the given array and build a new
// BinarySearchTree in hopes that a balanced BinarySearchTree
// will be closer to avg BigO log2(n) and compare search times
//
// C.
// Compare WorstCase for linear sorted array:
//  - BinarySearch
//  - Hash Search

lab15

Usage: ./lab15Exec <positiveInteger>


Execute the code with several different n sizes and note the times for each search algorithm for each data structure and orderdness. Be testful and try small values and very large values for n size

  1. What is the BigO for linear search, binary search, and hash table search
  2. Does the linear search in part A perform better than BST search or HashTable search? Why or whynot?
  3. Does the binary search in a balanced BST (B.) perform better than unbalanced BST (A.)? Why or whynot?
  4. Describe the function sortedArrayToBST and what it is doing
  5. What collision resolution strategy does our hash table use
  6. Does the balanced BST search perform better than our hash table search
  7. Search for the last elem in our unsorted array (worst case) and note the time for linear search (A.). Then compare the time for linear search for MAX elem in sorted array (C.). Are the two times similar? In your own words, why do you think the search is "faster" in part C, when in theory the two "times" should be similar.