Question

9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problduplicate search problem input: a vector V of comparable objects output: an element of V that appears more than once in V, or

9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time efficiency class of your algorithm.
duplicate search problem input: a vector V of comparable objects output: an element of V that appears more than once in V, or None if no such element exists
0 0
Add a comment Improve this question Transcribed image text
Answer #1

We will reduce this problem to sorting problem where we sort all the entries of vector V of comparable objects into sorted array and then determine whether there are two consecutive indices having same value. If there are two consecutive indices having same value, then there exist an element of V appearing more than once in V, otherwise not.

ALGORITHM(V, n)

1. Given the vector V of size n, store the element in V in array A in sorted order by using HEAPSORT algorithm.

2. For i = 1 to n-1:-

3..........if A[i] == A[i+1]:- //This means element at index i is repeated, hence return True

4................Return True

5. Return False //If now such index is found till the end, then return false, since no element is repeated.

Hence this procedure require to perform sorting which takes O(n log n) time if MERGESORT is used and then iterating through all the indices will take O(n) time. Hence total time complexity will be O(n log n) + O(n) = O(n log n).

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
9-2. For each of the following problems: design a reduction algorithm a hash table or sorting algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time effi...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1) Design a greedy algorithm that solves the problem; describe your algorithm with clear pseudocode; and...

    1) Design a greedy algorithm that solves the problem; describe your algorithm with clear pseudocode; and prove the time efficiency class of your algorithm: If x, y are two adjacent elements in a sequence, with x before y, we say that the pair x, y is in order when x <= y and the pair is out of order when x > y. For example, in the string “BEGGAR” the pair G, A are out of order, but all the...

  • Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path pr...

    Problem 6. (Weighted Graph Reduction) Your friend has written an algorithm which solves the all pairs shortest path problem for unweighted undirected graphs. The cost of a path in this setting is the number of edges in the path. The algorithm UNWEIGHTEDAPSP takes the following input and output: UNWEİGHTEDA PSP Input: An unweighted undirected graph G Output: The costs of the shortest paths between each pair of vertices fu, v) For example, consider the following graph G. The output of...

  • 2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G...

    2. Design a deterministic algorithm to solve the following problem. input: A directed acyclic graph G = (V, E) stored using adjacency lists. output: A Hamiltonian path, if such a path exists. Otherwise, return NONE. Your algorithm must take O(|V| + |E|) time. You must describe your algorithm in plain English (no pseudocode) and you must explain why the running time of your algorithm is O(|V| + |E|). Maximum half a page

  • Searching/sorting tasks and efficiency analysis - Big-oh For each problem given below, do the following: 1....

    Searching/sorting tasks and efficiency analysis - Big-oh For each problem given below, do the following: 1. Create an algorithm in pseudocode to solve the problem. 2. Identify the factors that would influence the running time of your algorithm. For example, if your algorithm is to search an array the factor that influences the running time is the array size. Assign names (such as n) to each factor. 3. Count the operations performed by the algorithm. Express the count as a...

  • Your task is to design algorithms to solve the following problems. For full credit, your algorithm...

    Your task is to design algorithms to solve the following problems. For full credit, your algorithm must run in logarithmic time. Given a number n greaterthanorequalto 1 and a (user-specified) error tolerance e, you want to approximate the squareroot of n to within error tolerance e. Specifically, you want to return an x = Squareroot n that satisfies |x^2 - n| greaterthanorequalto e. For example, to compute the squareroot of n = 2 with e = 0.01, an acceptable answer...

  • For each problems segment given below, do the following: Create an algorithm to solve the problem...

    For each problems segment given below, do the following: Create an algorithm to solve the problem Identify the factors that would influence the running time, and which can be known before the algorithm or code is executed. Assign names (such as n) to each factor. Identify the operations that must be counted. You need not count every statement separately. If a group of statements always executes together, treat the group as a single unit. If a method is called, and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT