Find the closest pair from two sorted arrays – Searching and Sorting – Given two sorted arrays and a number x, find the pair whose sum is closest to x and the pair has an element from each array.
Searching and Sorting
C programming K’th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time) – Searching and Sorting – Given an array and a number k where k is smaller than size of array, we need to find the k’th smallest element in the given array. It is given that ll array elements are distinct.
Sort an array in wave form – Searching and sorting – A Simple Solution is to use sorting. First sort the input array, then swap all adjacent elements.
C++ programming K’th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time) – Searching and Sorting – Given an array and a number k where k is smaller than size of array, we need to find the k’th smallest element in the given array. It is given that ll array elements are distinct.
JAVA programming K’th Smallest/Largest Element in Unsorted Array | Set 2 (Expected Linear Time) – Searching and Sorting – Given an array and a number k where k is smaller than size of array, we need to find the k’th smallest element in the given array. It is given that ll array elements are distinct.
Search in an almost sorted array – Searching and Sorting – A simple solution is linearly search given key in given array.Time complexity of solution is O(n).We cab modify binary search to do it in O(Logn) time.
A Problem in Many Binary Search Implementations – Searching and Sorting – The above looks fine except one subtle thing, the expression “m = (l+r)/2”. It fails for large values of l and r. Specifically, it fails if the sum of low and high is greater than the maximum positive int value (231– 1).
Find k closest elements to a given value – searching and sorting – start from the first element and search for the crossover point (The point before which elements are smaller than or equal to X and after which elements are greater).
QuickSort on Doubly Linked List – Searching and sorting -. The idea is simple, we first find out pointer to last node. Once we have pointer to last node, we can recursively sort the linked list using pointers to first and last nodes of linked list.
QuickSort on Singly Linked List – Searching and sorting – Quick Sort on Doubly Linked List is discussed here.In Singly linked list was given as an exercise. Following is C++ implementation for same.