0% found this document useful (0 votes)
11 views2 pages

Searching Sheet

Uploaded by

beetlejuiceezz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Searching Sheet

Uploaded by

beetlejuiceezz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Searching assignment

(1) Subarray with given sum


Given an unsorted array A of size N that contains only non-negative integers, find a
continuous sub-array which adds to a given number S.
In case of multiple subarrays, return the subarray which comes first on moving from left
to right.

Example 1:

Input:
N = 5, S = 12
A [] = {1,2,3,7,5}
Output: 2 4
Explanation: The sum of elements
from 2nd position to 4th position
is 12.

(2) Missing number in array


Given an array of size N-1 such that it only contains distinct integers in the
range of 1 to N. Find the missing element.
Example 1:

Input:
N = 5
A [] = {1,2,3,5}
Output: 4

Example 2:

Input:
N = 10
A [] = {6,1,2,8,3,4,7,10,5}
Output: 9
(3) Kth smallest element
Given an array arr [] and an integer K where K is smaller than size of array, the task
is to find the Kth smallest element in the given array. It is given that all array
elements are distinct.
Example 1:

Input:
N = 6
arr [] = 7 10 4 3 20 15
K = 3
Output: 7
Explanation:
3rd smallest element in the given
array is 7.

Example 2:

Input:
N = 5
arr [] = 7 10 4 20 15
K = 4
Output: 15
Explanation:
4th smallest element in the given
array is 15.

(4) Given a sorted array of integers, what can be the minimum worst case time complexity
To find ceiling of a number x in given array? Ceiling of an element x is the
smallest element presents in array which is greater than or equal to x. Ceiling is
not present if x is greater than the maximum element presents in array. For example,
if the given array is {12, 67, 90, 100, 300, 399} and x = 95, then output should be 100.

A. O(LogLogn)
B. O(n)
C. O(Logn)
D. O(Logn*Logn)

You might also like