edited by
11,674 views
56 votes
56 votes

Let $a$ and $b$ be two sorted arrays containing $n$ integers each, in non-decreasing order. Let $c$ be a sorted array containing $2n$ integers obtained by merging the two arrays $a$ and $b$. Assuming the arrays are indexed starting from $0$, consider the following four statements

  1. $a[i] \geq b [i] \Rightarrow c[2i] \geq a [i]$
  2. $a[i] \geq b [i] \Rightarrow c[2i] \geq b [i]$
  3. $a[i] \geq b [i] \Rightarrow c[2i] \leq a [i]$
  4. $a[i] \geq b [i] \Rightarrow c[2i] \leq b [i]$

Which of the following is TRUE?

  1. only I and II
  2. only I and IV
  3. only II and III
  4. only III and IV
edited by

5 Answers

–3 votes
–3 votes

4) is the correct option.

You can take a example and check easily

let array a contains elements : 3,5,7

and array b contains elements: 2,6,8,9

after merging array c will contain elements as 2,3,5,6,7,8,9

cheking option 1) a[i] ≥ b [i] => c[2i] ≥ a [i]

for elements at zero index in both the arrays, the one which is smaller is placed in array c at zero index.. so this fails as c[0]=2 and a[0]=3

2)a[i] ≥ b [i] => c[2i] ≥ b [i]

taking i=1

a[1]=5 , b[1]=6 and c[2]=5  so this condition also fails as c[2]<c[1](this condition may sometimes be true but not always, in case if array a and array b contains elements in common)

3)a[i] ≥ b [i] => c[2i] ≤ a [i]

a[1]=5 , b[1]=6 , c[2]=5  and so this condition is true as c[2]=a[1]

4)a[i] ≥ b [i] => c[2i] ≤ b [i]

a[1]=5 , b[1]=6 and c[2]=5 , viz also true as c[2]<b[1]

Answer:

Related questions

25 votes
25 votes
3 answers
7
Ishrat Jahan asked Nov 3, 2014
8,917 views
What is the output printed by the following program?#include <stdio.h int f(int n, int k) { if (n == 0) return 0; else if (n % 2) return f(n/2, 2*k) + k; else return f(n/...