Question: 1. Write a program in either C++ or Java that counts the number of duplicates in a list of integer numbers. Your program receives a
1. Write a program in either C++ or Java that counts the number of duplicates in a list of integer numbers. Your program receives a list of n numbers and outputs the total number of duplicates. Your algorithm should be of order of O(n 2 ). in the worst-case. Analyze your algorithm in the worst-case. 2. Assume you have a sorting algorithm that you can use as a black box. Use the sorting algorithm to sort the input list. Now write an algorithm to count the number of duplicates again. Analyze the time complexity of your algorithm in the worst-case (ignore the time complexity of sorting). Could you improve the worst-case time complexity of your algorithm compared to the previous question?
2. Assume you have a sorting algorithm that you can use as a black box. Use the sorting algorithm to sort the input list. Now write an algorithm to count the number of duplicates again. Analyze the time complexity of your algorithm in the worst-case (ignore the time complexity of sorting). Could you improve the worst-case time complexity of your algorithm compared to the previous question?
(if you can only answer of the questions please answer question 2)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
