Thursday, July 30, 2009

Do any one have complete code in divide and conquer in c programming ?

do any one have complete code in divide and conquer in c programming ?

Do any one have complete code in divide and conquer in c programming ?
Algorithm LargestNumber


Input: A non-empty list of numbers L.


Output: The largest number in the list L.


Comment: Divide and Conquer


if L.size == 1 then


return L.front


largest1 ← LargestNumber(L.front...L.mid)


largest2 ← LargestNumber(L.mid....L.back)


if largest1 %26gt; largest2, then


largest ← largest1


else


largest ← largest2


return largest








Memory access


Divide-and-conquer algorithms naturally tend to make efficient use of memory caches. The reason is that once a sub-problem is small enough, it and all its sub-problems can, in principle, be solved within the cache, without accessing the slower main memory. An algorithm designed to exploit the cache in this way is called cache oblivious, because it does not contain the cache size(s) as an explicit parameter.





Moreover, D%26amp;C algorithms can be designed for many important algorithms, such as sorting, FFTs, and matrix multiplication, in such a way as to be optimal cache oblivious algorithms—they use the cache in a provably optimal way, in an asymptotic sense, regardless of the cache size. In contrast, the traditional approach to exploiting the cache is blocking, where the problem is explicitly divided into chunks of the appropriate size—this can also use the cache optimally, but only when the algorithm is tuned for the specific cache size(s) of a particular machine.





The same advantage exists with regards to other hierarchical storage systems, such as NUMA or virtual memory, as well as for multiple levels of cache: once a sub-problem is small enough, it can be solved within a given level of the hierarchy, without accessing the higher (slower) levels.





However, the kind of asymptotic optimality described here, analogous to big O notation, ignores constant factors, and additional machine/cache-specific tuning is in general required to achieve optimality in an absolute sense.

sage

No comments:

Post a Comment