Searching

Minimum and maximum

How many comparisons do you need to find the minimum of an array of length ? What about the maximum? What if you need both?

You are given an array and asked to check if a given element appears in it. What is the time complexity of your solution? How would you answer change if the input array is sorted?

Intersecting sorted arrays

You are given two sorted arrays and and asked to compute their intersection , an array containing all elements that appear in both and and if free of duplicates. Let and be the lengths of and respectively. What is a good way to find if ? What if or ?

We call a matrix sorted if each of its rows and columns is sorted. What is the fastest way to check if a sorted matrix contains a given value?