Algorithm Design & Analysis You are given an array called source, with length n, and a set of m arrays called target, each also with length n. The arrays contain only positive integers. The arrays are unsorted. For any number x, the smallest number in target[x] is guaranteed to be smaller than target[x+1]. All the numbers in target are unique. The following figure illustrates an example of valid source and target arrays for this case, where n=5 and m=6. The smallest number in each array in target is styled with bold and italic. You can quickly see that the smallest number in target[0] is smaller than the smallest number in target[1], the smallest number in target[1] is smaller than the smallest number in target[2], and so on. You can also see that there is no duplicate number within the arrays in target. You are asked to design an algorithm to find if there is an array in b that has the same set of numbers as in a. In the above case, your algorithm should return true, because b[2] has the same set of numbers as in a. A. Propose an algorithm to solve the case. Explain the algorithm in detail. B. Calculate and express the time complexity of your algorithm in n and m. Explain in detail why your algorithm has the time complexity you have calculated. C. Write down the pseudocode of your proposed algorithm. Notes: The most optimal algorithm for this case will have a time complexity equal to or less than O((m+1)n + lg(m) + 2n). In the case you cannot propose an algorithm with the optimal time complexity, you can still get a good score if your algorithm can solve the case and you can correctly calculate and explain the time complexity of your proposed algorithm.
You are given an array called source, with length n, and a set of m arrays called target, each also with length n. The arrays contain only positive integers. The arrays are unsorted. For any number x, the smallest number in target[x] is guaranteed to be smaller than target[x+1]. All the numbers in target are unique. The following figure illustrates an example of valid source and target arrays for this case, where n=5 and m=6.
The smallest number in each array in target is styled with bold and italic. You can quickly see that the smallest number in target[0] is smaller than the smallest number in target[1], the smallest number in target[1] is smaller than the smallest number in target[2], and so on. You can also see that there is no duplicate number within the arrays in target. You are asked to design an algorithm to find if there is an array in b that has the same set of numbers as in a. In the above case, your algorithm should return true, because b[2] has the same set of numbers as in a.
- A. Propose an algorithm to solve the case. Explain the algorithm in detail.
- B. Calculate and express the time complexity of your algorithm in n and m. Explain in detail why your algorithm has the time complexity you have calculated.
- C. Write down the pseudocode of your proposed algorithm.
Notes: The most optimal algorithm for this case will have a time complexity equal to or less than O((m+1)n + lg(m) + 2n). In the case you cannot propose an algorithm with the optimal time complexity, you can still get a good score if your algorithm can solve the case and you can correctly calculate and explain the time complexity of your proposed algorithm.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps