Divide And Conquer Approach


                Do you like Burgers? Let consider the process of eating Burger. A person can eat the burger in one bite or More than one bite. You must be thinking of the person who can eat the whole burger in just one bite, But generally, we eat the burger in more than one bite. A number of bites takes to eat the whole burger depends upon burger size as well as the size of each bite. We eat burger bite by bite because we cannot chew or put the whole burger in the mouth. Another reason for taking Many bites is because it is easier to handle small bite than the whole burger.



                In Education, we cannot teach/learn whole life oriented things in one single part. So we divide life aspects into fields of study. Again we cannot handle any particular field as single. So further we divide the field into subjects. Each subject has many books to learn it. Same as Book into chapters and Chapters into sections and section into figures, tables, paragraphs etc. Further Paragraph divides into sentences and sentence into words and word into letters. That’s why every child first learns alphabets of any language.In Big Company, CEO/Owner cannot handle all the work of company by hand. So Company has different departments, Each department has the general manager and Each General manager handle group of managers of the particular department. Each manager handles the group of workers.
                Again, back to the former example of Eating burger. Now Consider Burger as Big Computational Problem and Mouth as Processor of Computer. The processor can handle a small part of actual Big Computational problem easily. This type of algorithm which first divide the problem into the small problem until the problem becomes small enough to handle easily called Divide and Conquer Algorithm.

Merge Sort 

Merging Of Solutions

                Sorting of the array can be done with divide and conquer approach. For sorting of the array, first, we break array into smaller arrays and solve smaller array or break again into smaller arrays and solve them. Here the question is what is the minimum size of the array to be sorted. If we break the main array until all subarrays have one element. We already have sorted array because the array has only one element and In any order ascending or descending one element has its correct position. But the only division of array doesn’t give us the correct output of actual array to be sorted. For having the correct Sorted array of the input array, We have to merge these smaller sorted arrays into the big sorted array until we achieve correct array as output. This algorithm involving the merging of the smaller solution to achieve the Sorting solution, so it is called MERGESORT.
                As Merge sort involves breaking and merging of an array. It contains two functions to perform Merge Sort: merge-sort & merge. MergeSort algorithm demonstrate in C/C++ language for Sorting Integers.

Comments