Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You are given a list L of n, not necessarily distinct, integers. Your task is to devise an algorithm that outputs a list of the
You are given a list L of n, not necessarily distinct, integers. Your task is to devise an algorithm that outputs a list of the distinct integers in L, in order of non-increasing frequency (the frequency of an element in L is the number of times it occurs in L). For example, if L is 2, 5, 4, 4, 2, 3, 4, 3, then a suitable output is 4, 3, 2, 5; the only other suitable output for this list is 4, 2, 3, 5. In this example, L contains only small integers, but this is not always the case.
an algorithm that outputs a list of the distinct integers in L, in order of non-increasing frequency (the frequency of an element in L is the number of times it occurs in L). For example, if L is 2,5,4,4,2,3, 4, 3, then a suitable output is 4,3,2,5; the only other suitable output for this list is 4,2,3,5. In this example, L contains only small integers, but this is not always the case. You cannot make any assumption on the integers in L (e.g., their maximum size, or distribution). In particular, some integers of L can very large, and so it is not feasible to use tables of size proportional to these integers a. Give a Hash Table-based algorithm for this problem whose expected time complexity is (n), under some Hash Table assumptions that you must clearly state. Explain why, your algorithm achieves this time complexity under these assumptions. What is the worst-case time complexity of your algorithm? Use the notation and justify your answer HINT: As part of your algorithm, you may find useful to discover a way to sort n numbers in the range 0 to n in O(n) worst-case time. b. Give an algorithm for this problem whose worst-case time complexity is O(n logn). Explain why your algorithm achieves this time complexityStep 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