Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write algorithms. To write code use Python. Solve (a) Motivation: You want to build an airfield in a mountainous area. Therefore, you look for a
Write algorithms. To write code use Python.Solve
(a) Motivation: You want to build an airfield in a mountainous area. Therefore, you look for a longest possible plateau, that is, for a longest possible flat surface. An additional constraint is that the airfield has to be build along a fixed line of latitude since this is the direction in which the airplanes land or take off. To solve this problem, you first measure the height of the surface along the line of latitude at n equidistant sample points. 1 Now, given an integer array h[1..n] with the measured heights (rounded to full meters), propose an efficient algorithm to find a longest plateau, that is, a longest consecutive subsequence ai..;] of the array where all the integers have the same value. The output should consist of a position i of the array where a longest plateau starts. What is the running time of your algorithm? (b) Motivation: You maintain a database storing the yearly salary of all n persons in Poland. The database is implemented as an integer array d[1..n) where d[i] is the salary of the i-th person in Polish Zloty (PLN). Now, your boss gives you a small database containing the salary (in PLN) of some other m persons whose salary is not larger than k PLN, also implemented as an integer array 9[1..m). Your task is to compute, for each person of the databse q, how many persons in the database d have exactly the same salary. Input: arrays d[1..n] and q[1..m] of nonnegative integer values, and a parameter k with the guar- antee that no value in q is larger than k. Output: an array res[1..m] where res[i] is the number of indices j = {1,..., n} for which q[i] = d[j]. Propose an algorithm solving this problem using only O(1) additional memory space, that is, be sides d, q, k and res, you are allowed to use only a constant number of variables. What is the running time of your algorithm? (c) (2 points) We consider the same problem as in (b). This time, propose an algorithm with running time O(n + m + k) without any constraints regarding the memory space. What is the extra memory used by your algorithm in enotation? Compare your running time to (b) when assuming m= (vn) and k= (m). Hint: Use the counting techniqueStep 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