Question

In: Computer Science

Q1) (1 point) Design an efficient algorithm (in terms of asymptotic complexity in the worst case)...

Q1) (1 point) Design an efficient algorithm (in terms of asymptotic complexity in the worst case) to determine if two students in a class of n students have the same height. What is the complexity of your algorithm?

a.Provide the pseudo-code of that algorithm.

b.Implement the algorithm in a language of your choice and provide a sample run with meaningful input.

Solutions

Expert Solution

Solution

1)

Consider we have 2 cases for the mentioned scenario

Case 1:The smallest measure in cm

Case 2:There is no such a limit

Time Complexity

Case 1

Answer

Θ(n)

Explanation

First Initializie the height slots to unmark

Then Measure each student

Then mark the corresponding to the height slot

return true if the marked slot is visited

--

Case 2

Answer

Θ(n lg n)

Explanation

we need to apply any Θ(n lg n) sorting algorithm

Scan the sorted array from left & right , return true whenever 2 neighbours are of the same height

return false in case if there is no true retun at the both cases

---

Pseudocode

Height(i) is the height of the student i

Mark(j) is the mark for the height j

miinimum_height & maximum_height are predetermined can be calculated in the linear time

HEIGHT_CASE_1(Height, A)
1 for j<-minimum_height to maximum_height
2 Mark[j]<-false
3 for i<-1 to n
4 if Mark(Height(i))
5 then return true
6 else Mark(Height(i))<-true
7 return false

HEIGHT_CASE_2(Height, A)
1 quicksort (Height)
2 for i<-1 to n-1
3 if Height(i) = Height(i + 1)
4 then return true
5 return false

---

provided complexity and pseudocode

really sorry couldnt able to complete the b

all the best


Related Solutions

Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis...
Implement 2-D peak finder and explain the asymptotic complexity of the algorithm For Design and Analysis of the Algorithme lecture
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you...
Give the asymptotic (“big-Oh”) running time complexity of the following algorithm, show all the work you have done. Algorithm: ArrayMangle(A[ ], int n) Input: an array A, an integer n x = 0; for (i=0; i<=n-1; i++) { for (j=i; j<=n-1; j++) { x = x + A[j]; } for (k=0; k<= n-1; k++) { for (j=0; j< =n-1; j++) { x = x + A[j]*A[k]; } } }
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps...
Calculate the time complexity of each algorithm for best, worst and average cases. Give all steps of your calculation and results in Big-O notation. algorithm : Selection Sort Bubble Sort Insertion Sort
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the...
Show that the worst-case number of entries computed by the refined dynamic programming algorithm for the 0-1 Knapsack problem is in Ω(2n). Do this by considering the instance in which W = 2n −2 and wi = 2i−1 for 1 ≤ i ≤ n. Please answer with clear explanations!!! Excerpt From: Richard Neapolitan. “Foundations of Algorithms.”
Q1 Differentiate the bus, star, hybrid, and mesh topologies based on the complexity of the design,...
Q1 Differentiate the bus, star, hybrid, and mesh topologies based on the complexity of the design, the setup cost, and the types of business operations that suitable to each.
Design an efficient algorithm to compute the number of binary strings with length n that satisfy...
Design an efficient algorithm to compute the number of binary strings with length n that satisfy 1 the regular expression ((0 + 11 + 101)∗ (1101))∗ .
1) Discuss the complexity of building efficient algorithms in Game Theory (+150 words)
1) Discuss the complexity of building efficient algorithms in Game Theory (+150 words)
Write code for O(n) worst-case algorithm that verifies that a tree is actually an AVL tree by detecting imbalance.
Write code for O(n) worst-case algorithm that verifies that a tree is actually an AVL tree by detecting imbalance. If imbalance is true, then call the proper rotation function provided in the lecture slides to fix the imbalance condition.1. Must read AVLNode data from a text file2. Create a Book Object; and an AVL node object to be inserted into the AVL tree3. At each insert, detect imbalance and fix the AVL tree4. Report each imbalance detection and the node...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it...
C programming problem I have to design an efficient algorithm which solves this problem. Also, it needs to include time and space complexities of this algorithm. There is a matrix (N times N) of integers which rows and columns are sorted in non-decreasing order. A sorted matrix and integer M will be given and we need to find the position(row,column) of M in this matrix. it's okay to report only one position if there are more than one answers. when...
Q. In the worst-case scenario related to casing collapse pressure, explain from a practical point of...
Q. In the worst-case scenario related to casing collapse pressure, explain from a practical point of view why the casing internal pressure is considered partially or completely empty. In other words, under what conditions the casing string can be empty or partially empty. (Note: This question needs to be answered in the context of Petroleum Drilling Engineering advance level)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT