Given two sorted arrays A and B of numbers. The size of A is N and the size of B is n + 1. Say that the numbers in A U B are pairwise distinct (no value returns more than once). Note that A U B has odd size because its 2n + 1. Hence the median is unique. Give an algorithm that returns the median. PSEUDOCODE ONLY.
Pseudocode To find median of a sorted array
1. IF size of array is 1 return array[0]
2. ELSE IF size of array is 2 return (array[0]+array[size-1])/2
3 ELSE
4 IF size is odd return array[mid]
5 ELSEreturn (array[mid] + array[mid+1])/2
6. END
Now we have two sorted arrays arr1 and arr2. To find median of two sorted arrays the best way is to find median m1 and m2 of both arrays and if median of both arrays is same then median is the common number otherwise if m1 < m2 then elements on the right side of in arr2 are compared to elements on right side of m1 in arr1 to find the median.
Pseudo code
1. IF m1 == m2 return m1
2. ELSE IF m1 < m2
3. find median of arr1[mid to n] and arr2[0, mid-1]
4. ELSE IF m1 > m2
5. find median of arr2[mid to n] and arr1[0, mid-1]
6. END
Given two sorted arrays A and B of numbers. The size of A is N and...
Order Statistics: A. Given two sorted arrays X and Y of equal size n, use Quick-Select to find the median of all 2n elements in arrays X and Y. Can you improve Quick-Select by choosing better pivots at every step?(in java) B. Show some experiments of your improved Quick-Select with arrays of size n=50. You can assume, if you want, that all the elements in the two arrays are distinct.
Suppose you are given k sorted arrays of size n. Give an algorithm, that runs in O(nk log k)time, that merges them into a single list.
You are given an input of k arrays each of size n. Each one of the k arrays is sorted. Give an algorithm that turns the k sorted arrays into one sorted array of k * n elements. Please explain the algorithm in words and analyze the run time.
(25pts) You are given two sorted lists of size m and n. Give an O(log m log n) time algorithm for computing the k-th smallest element in the union of the two lists Note that the only way you can access these values is through queries to the databases. Ina single query, you can specify a value k to one of the two databases, and the chosen database will return the k-th smallest value that it contains. Since queries are...
I need help In the lecture you got acquainted with the median algorithm, which calculates the median of an unsorted array with n∈N elements in O (n). But the algorithm can actually do much more: it is not limited to finding only the median, but can generally find the ith element with 0≤i <n. Implement this generic version of the median algorithm by creating a class selector in the ads.set2.select package and implementing the following method: /** * Returns the...
Given two arrays A and B of n integers both of which are sorted in ascending order. Write an algorithm to check whether or not A and B have an element in common. Find the worst case number of array element comparisons done by this algorithm as a function of n and its Big-O complexity
3. (20 pts.) You are given two sorted lists of numbers with size m and n. Give an O(logn+ logm) time algorithm for computing the k-th smallest element in the union of the two lists. 4. (20 pts.) Solve the following recurrence relations and give a bound for each of them. CMPSC 465, Fall 2019, HW 2 (a) T(n) = 117(n/5)+13n!.3 (b) T(n) = 2T (n/4)+nlogn (c) T(n) = 5T (n/3) +log-n (d) T(n) = T(n/2) +1.5" (e) T(n) =...
Suppose we are given two sorted arrays (nondecreasing from index 1 to index n) X[1] · · · X[n] and Y [1] · · · Y [n] of integers. For simplicity, assume that n is a power of 2. Problem is to design an algorithm that determines if there is a number p in X and a number q in Y such that p + q is zero. If such numbers exist, the algorithm returns true; otherwise, it returns false....
Introduction to the Design and Analysis of Algorithms Note: Present Algorithms in Pseudocode Give an algorithm to print all the common elements in two sorted arrays of integers, A and B of sizes m and n, respectively. Assume that the numbers in each of the arrays are distinct. Input: Sorted arrays A[m] and B [n]. Output: Common elements. ExA:3.5 6 9 12 17 23; B:2581011 12 15 16 17 19 22 25; Output: 5 12 17
1. (16 pts.) Sorted Array Given a sorted array A of n (possibly negative) distinct integers, you want to find out whether there is an index i for which Al = i. Give a divide-and-conquer algorithm that runs in time O(log n). Provide only the main idea and the runtime analysis.