Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use Java or pseudocode to write this. I hope you can use pseudocode. Give

ID: 3747884 • Letter: P

Question

Please use Java or pseudocode to write this. I hope you can use pseudocode.

Given a sequential list with n numbers, represented in a one dimensional array. A)Write an algorithm to check if the list has any duplication. Explain the time complexity of your algorithm Can you think of a better algorithm to do the job? If so, briefly explain. B) Write an algorithm to find all the duplicate numbers in the list, if any. Explain the time complexity of your algorithm Can you think of a better algorithm to do the job? If so, briefly explain. .

Explanation / Answer

public class Duplicates { // This algorithm runs in O(n^2). // Yes, we can do better in this algorithm. we can first sort the numbers in O(n log(n)) using mergesort or quicksort // then we can check for duplicates. // This changed algorithm will run in O(n log(n)) public static boolean hasDuplicate(int arr[]) { for (int i = 0; i