Question

Questions 1a–d are about developing an efficient implementation of a Set that combines the advantages of...

Questions 1a–d are about developing an efficient implementation of a Set that combines the advantages of a hash table and a balanced binary search tree. In particular, the search function for your data structure should have O (lg n ) worst case complexity and Θ(1) expected case complexity, and it should not be limited to values in a small range (as a bit vector would).

(a) Describe how you would store data values in memory.

(b) Give pseudocode for how you would insert a new value into your data structure.

(c) Give pseudocode for how you would search for a given value. (

d) Briefly justify why your search function has O (lg n ) worst case and Θ(1) expected case complexit

0 0
Add a comment Improve this question Transcribed image text
Answer #1

(a) answer>>>If we want implementation of a Set that combines the advantages of a hash table and a balanced binary search tree than We can choose treeset whose internal implementation is binary search tree ...it is efficient if we are more concerned in insertion, removal and retrieval operations.

(b)answer>>>

struct node* insert(struct node* node, int key)

{

    if (node == NULL) return newNode(key);

    if (key < node->key)

        node->left = insert(node->left, key);

    else if (key > node->key)

        node->right = insert(node->right, key);   

    return node;

}

   

// Driver Program to test above functions

int main()

   

    // print inoder traversal of the BST

    inorder(root);

   

    return 0;

}

(c)answer>>>

struct node* search(struct node* root, int key)

{

    if (root == NULL || root->key == key)

       return root;

    if (root->key < key)

       return search(root->right, key);

    return search(root->left, key);

}

(d)answer>>>

 The maximum number of times that the for-loop can run is than  worst case occurs and when  the value being searched for is not present in the array. 

Binary search internally uses log(n) time complexity

Add a comment
Know the answer?
Add Answer to:
Questions 1a–d are about developing an efficient implementation of a Set that combines the advantages of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with...

    Title: Implementation of chained hashing in Java or Python Description: Implement a double linked list with a procedure for adding list elements. Implement a hash table using chaining and the linked list discussed above. Use Array size m = 7 A hash function of: h = k mod 7 Insert 100 random key values into the table. Key values should be between 0 and 99. Implement a Search procedure that tells whether a particular key value is in the hash...

  • Describe the most time-efficient way to implement the operations listed below. Assume no duplicate values and...

    Describe the most time-efficient way to implement the operations listed below. Assume no duplicate values and that you can implement the operation as a member function of the class - with access to the underlying data structure. Then, give the tightest possible upper bound for the worst case running time for each operation in terms of N. (both implemented using an arm elements into a single binary min heap. Explanation:

  • 1. Randomized Binary Search Which are true of the randomized Binary Search algorithm? Multiple answers:You can...

    1. Randomized Binary Search Which are true of the randomized Binary Search algorithm? Multiple answers:You can select more than one option A) It uses a Variable-Size Decrease-and-Conquer design technique B) Its average case time complexity is Θ(log n) C) Its worst case time complexity is Θ(n) D) It can be implemented iteratively or recursively E) None of the above 2. Randomized Binary Search: Example Assume you have an array, indexed from 0 to 9, with the numbers 1 4 9...

  • 2. You must support the following two operations on a set of numbers: (1) insertion, and...

    2. You must support the following two operations on a set of numbers: (1) insertion, and (2) "large-delete" which is to delete the largest half of the values in the set. In other words if there are k elements you delete the elements with the rk/2] largest values. For example, large-delete15, 3,7,9,1,8) 3,1,5) Both operations should take constant time, amortized. Assume that you start with an empty data structure. You can use whatever data structure you like for the set....

  • Problem 3 Suppose that you have a set of n large, orderable, objects, each of size...

    Problem 3 Suppose that you have a set of n large, orderable, objects, each of size q, so that it requires time e(a) to time to compute a hash function h(a) for any object and requires time e(g) to compare any two objects. Describe a compound data structure, built out of a heap and a hash table, that supports the following operations with the specified run times.. elt (x) Is x an element of the set? Expected run time O(g)....

  • 4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up t...

    4) [15 points total (5 points each)] Assume you are given a sorted array A of n numbers, where A is indexed from 1 up to n, anda number num which we wish to insert into A, in the proper sorted position. The function Search finds the minimum index i such that num should be inserted into Ali]. It searches the array sequentially until it finds the location i. Another function MakeRoom moves A[i], .., AIn] to Ali+1]...AIn+1] same sort...

  • really need help. All information that i have is posted, In java Dynamic programming allows you...

    really need help. All information that i have is posted, In java Dynamic programming allows you to break a large problem into multiple subproblems. Each of these subproblems must be solved, and the solution must be stored as a memory-based solution. Solve the following binary search algorithm using dynamic programming (Adapted from Esquivalience, 2018): Graph To solve this problem, complete the following tasks: Create a binary search tree using a data structure. Insert the node values as described in the...

  • 5. A three-heap with n elements can be stored in an array A, where A[O] contains...

    5. A three-heap with n elements can be stored in an array A, where A[O] contains the root of the tree. a) Draw the three-heap that results from inserting 5, 2, 8, 3, 6, 4, 9, 7, 1 in that order into an initially empty three-heap. You do not need to show the array representation of the heap. You are only required to show the final tree, although if you draw intermediate trees. b) Assuming that elements are placed in...

  • problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to...

    problem 2 can use Det-Selection(A, p, q, r) as a sub-routine (i.e, you don't need to write its pseudo-code). To sort an array A, you will then call Det-QuickSort(A, 1, n). You also need to provide the worst case time complexity analysis of your algorithm. 2. (20 points) Given a set of n distinct numbers, we wish to find the k largest in sorted order using a comparison-based algorithm. Give an algorithm that implements each of the following methods, and...

  • C++ please read all the question Create 3 large arrays to search, where the size will be variable up until it reaches your machines limit. They should contain the same information since we are going t...

    C++ please read all the question Create 3 large arrays to search, where the size will be variable up until it reaches your machines limit. They should contain the same information since we are going to compare 3 different algorithms.You are going to do operational studies on them to determine their order. O(N), O(log(N)), and O(1)? Search algorithms.Linear, Binary, Hash You should know which algorithms are what order,now you are going to prove it. Fill the 3 arrays with the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT