281 views
1 1 vote

Alice has two sorted arrays $\mathrm{A}[1, \ldots, \mathrm{n}], \mathrm{B}[1, \ldots, \mathrm{n}+1]$. She knows that A is composed of distinct positive numbers, and B is derived from inserting a zero into $A$. She would like to know the index of this zero. She wonders if you can design and analyse a fast algorithm for her to find the index of the zero in $B$.

She has provided the following example to ensure that the problem statement is clear.

A: $[ 1,3,4,6,7,8,9,20]$

B: $[1,3,0,4,6,7,8,9,20]$.

Your algorithm should return 2 in this case, which is the index of the zero in B.

What is the tightest upper bound of the best algorithm to do this task in terms of $n$ ?
(Here O represents big-oh)

  1. $O(n)$
     
  2. $O(logn)$
     
  3. $O(1)$
     
  4. $O(loglogn)$

3 Answers

2 2 votes
answer Is B

O(log n)

Use Binery Search And Match Middle element If Postion of Middle element Index are Same in Both Array  Then Search Element In Next Half Array
0 0 votes
Let t be the index of the zero in B . Here is the key observation: for any $i \in\{1, \ldots, n\}$, if $A[i]=B[i]$ then $t>i$; otherwise, $t \leq i$. Therefore, we can do a binary search.
reshown by
Answer:
Position:
Show:

Related questions

2 2 votes
1 1 answer
251
251 views
GO Classes asked Aug 28, 2025
251 views
A monkey is given $n$ piles of bananas, where the 'ith' pile has nums[i] bananas (nums is an array of size n ). An integer h represents the total time in hours to eat all...
3 3 votes
3 3 answers
352
352 views
GO Classes asked Aug 28, 2025
352 views
You are given an $n \times n$ matrix where each row and each column is sorted in ascending order. You need to search for a target element "x" in the matrix.What is the be...
1 1 vote
3 3 answers
390
390 views
GO Classes asked Aug 28, 2025
390 views
A machine needs a maximum of $200$ seconds to sort $1000$ elements by Quick sort. The maximum time needed (in seconds) to sort $200$ elements will be approximately ______...
2 2 votes
2 2 answers
276
276 views
GO Classes asked Aug 28, 2025
276 views
Which of the following statements is/are not correct?(Here $o, \omega$ represents small-oh and small-omega, respectively.)The average-case time complexity of quicksort $=...