ALGORITHM N COMPLEXITY (URGENT) 1.Build a model of the problem if such a model i
ID: 3692082 • Letter: A
Question
ALGORITHM N COMPLEXITY (URGENT)
1.Build a model of the problem if such a model is not provided.
2. Decide which class it belongs to: P, NP, NP-Complete, PSPACE.
3.If possible:
Propose a polynomial-time algorithm to solve it.
4. Analyze its time complexity.
Otherwise:
State the complexity of this problem.
5.Explain why.
You are interested in analyzing some hard-to-obtain data from two separate databases. Each database contains n numerical values—so there are 2n values total—and you may assume that no two values are the same. You’d like to determine the median of this set of 2n values, which we will define here to be the nth smallest value. However, the only way you can access these values is through queries to the databases. In a single query, you can specify a value k to one of the two databases, and the chosen database will return the kth smallest value that it contains. Since queries are expensive, you would like to compute the median using as few queries as possible.
Explanation / Answer
1.Build a model of the problem if such a model is not provided.
Algorithm:
Step 1: Start
Step 2: Read k value
Step 3: Read Database from which kth smallest value is to retrieved
Step 4: fetch the data from the database and store it in temporary vector
Step 5: Apply Merge Sort on temporary vector to arrange elements in ascending order
Step 6: Pick up the Kth index value and display
Step 7:
2. Decide which class it belongs to: P, NP, NP-Complete, PSPACE.
The above model belongs to class P
Complexity : O(nlogn)
Steps
Time Complexity
Total Complexity
1
----
---
2
1
1
3
1
1
4
1
n
5
1
nlogn
6
1
1
7
---
---
3+n+nlogn
Complexity
O(nlogn)
Steps
Time Complexity
Total Complexity
1
----
---
2
1
1
3
1
1
4
1
n
5
1
nlogn
6
1
1
7
---
---
3+n+nlogn
Complexity
O(nlogn)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.