Answered step by step
Verified Expert Solution
Question
1 Approved Answer
5. We wish to store a collection of n key-value pairs where the keys are integers and the values are strings. We put the
5. We wish to store a collection of n key-value pairs where the keys are integers and the values are strings. We put the key-value pairs in a 0-indexed list of objects where each object represents a pair and such that the keys are in increasing order. For example the following key-value pairs: [3, apple], [10, cat], [5, math], [2, hello] Would be stored in a list A with: A[0] = [2, hello], A[1] = [3, apple], A[2] = [5, math], A[3] = [10, cat]. (a) To search for a particular key we will use a binary search. What is the best and worst case time complexity of this? Explain. (b) To insert a key-value pair we use a binary search to find the next smallest key (do you know how to do this?) and shift to make space accordingly. What is the best and worst case time complexity of this? Explain. (c) To delete a key-value pair we use a binary search to find the key and then splice to remove the key-value pair accordingly. What is the best and worst case O time complexity of this? Explain.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started