The question is to find the median of two sorted arrays of numbers. Write an algorithm running in O(log n) time. The median of a list of numbers is the middle one when the list is sorted. When the list…

The question is to find the median of two sorted arrays of numbers. Write an algorithm running in O(log n) time. The median of a list of numbers is the middle one when the list is sorted. When the list…

Posted in Algorithm

Big Oh notation describes the limiting behavior of a function \(f(n)\) when its argument approaches infinity. Let \(f,g\) be two functions on positive numbers. We write \(f = O(g)\) if there exists \(c>0\) such that \(f(n)\leq c \cdot g(n)\) for…

A permutation of a set is an arrangement of the elements in a particular order. For example, there are two permutations of {1,2}, namely {1,2} and {2,1}, and 6 permutations of {1,2,3}, namely {1,2,3}, {1,3,2}, {2,1,3}, {2,3,1}, {3,1,2}, and {3,2,1}.…

The problem is to rotate elements in an array in a circular way. For example, shifting the array {38, 27, 43, 3, 9, 82, 10} 3 positions to the left produces {3, 9, 82, 10, 38, 27, 43} Using a…