Answer please: We want to insert all the integers in an unsorted array of size m into a sorted array of integers of size n. The value of m is much smaller than the value of n. Two possible approaches that can accomplish the task are described as follows. Approach 1: Insert items in the smaller array into the right place in the larger array one by one. Approach 2: Sort the smaller array and merge the two arrays. We want to analyze the efficiency of the two approaches. What is the order for Approach 1? What is the order for Approach 2? Which approach is more efficient? Why? *Note that your answer should contain both m and n initially in your analysis and later you might reduce it to the simplest Big-O notation where appropriate
Answer please:
We want to insert all the integers in an unsorted array of size m into a sorted array of integers of size n. The value of m is much smaller than the value of n. Two possible approaches that can accomplish the task are described as follows.
Approach 1: Insert items in the smaller array into the right place in the larger array one by one.
Approach 2: Sort the smaller array and merge the two arrays.
We want to analyze the efficiency of the two approaches.
What is the order for Approach 1?
What is the order for Approach 2?
Which approach is more efficient? Why?
*Note that your answer should contain both m and n initially in your analysis and later you might reduce it to the simplest Big-O notation where appropriate
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 4 images