Can someone answer this? For this problem, we shall define the median of n integ
ID: 3669260 • Letter: C
Question
Can someone answer this?
For this problem, we shall define the median of n integers a_1,...a_n to be the n/2 -th smallest number in the list if n is even and (n+1)/2 -th smallest number if n is odd.
We want to solve the following computational problem.
Input: An integer array A of size n.
Output: Array B such that B[i] is the median of the first i integers of A.
Example,
Array A = {1,2,5,3,6}
Array B = {1,1,2,3,3}
Give an algorithm that solves the above problem in O(n log n) running time.
3. For this problem, we shall defime the molian of N integers a.. bo th smallist th Brnallst be the 9-th smallest numbver in the list i bethe- fth smallse number in the list if n is even and s If n is even and number if n is odd We wnnt to solve the following computational problem Input An integer artY A of siai n. Output: Any B such that B For example, if A is the array is the modian of the first i integers of A 1263 thes B is Give an algorithm that solvee the abuwe geobliss in Oinlog ra) running time. (5 pointa).Explanation / Answer
ALGORITHM:
1. Start
2. Initialize i,n,a[],b[],k,median,j
3. Enter n value
4. for i=0…n
5. enter array of n elements
6. a[i] ß k
7. i++
8. end for loop
9. if (n %2 == 0)
10. n is even
11. for j = 0…i
12. median = n/2
13. b[j] = median
14. j++
15.end for loop
16. else n is odd
17. for j = 0…i
18. median =( n+1)/2
19. b[j] = median
20. j++
21.end for loop
22. end if
23. Print output array b[]
24. end main