If the range turns out to be consecutive, there's no need to subdivide it further.
In the best case, when the entire input array is what did chelsea win before abramovich consecutive, this algorithm will detect it instantly.Otherwise (if the range is not consecutive divide it into two equal parts i, m and m1,.Here's one possible recursive approach: Input of recursive step is the range of elements i,.The usability of this algorithm is, again, undermined by the uniqueness requirement.The first thing that comes to mind is this: if you know that all numbers in the input array are unique, then for a range of elements i, j in the array, you can immediately tell whether elements in that range are consecutive or not.Copyright Disclaimer Under Section 107 of the Copyright Act 1976, allowance is made for "fair use" for purposes such as criticism, comment, news reporting, teaching, scholarship, and research.ALL 30 NBA Teams' Longest WIN Streak in Franchise history!Full License here - Music promoted by NCM /fh3rEJ.All the while you have keep track of the "longest consecutive range" found so far.The above algorithm will perform binary partition of the array and recursive descent of the partition tree using the left-first approach.Send the range to output (see below for further details).Anyway, here's a possible C implementation typedef std:vector int vint; typedef std:pair vint:size_type, vint:size_type range; class longest_sequence public: const range operator const vint v) current max range(0, 0 process_subrange(v, 0, ze - 1 check_record return max; private: range current, max; void process_subrange(const vint v, vint:size_type.This means that this algorithm will find adjacent subranges with consecutive elements in left-to-right order.Apply the above criterion to range i,.It would be interesting to see if the fact that the array is sorted can be exploited somehow to improve the algorithm.Recursively invoke the algorithm on the lower part (i, m) and then on the upper part (m1, j).(I'm still working on a meaningful O estimation for this algorithm.).License for commercial use: Creative Commons Attribution.0 Unported "Share Alike" (CC BY-SA.0) License.The benefit of this algorithm is that it detects subranges of consecutive elements "early without looking inside these subranges.Obviously, it's worst case performance (if ther are no consecutive subranges at all) is still O(n).Non-profit, educational or personal use tips the balance in favor of fair use.
Initially it is 0, n-1 - the whole array.