The most popular method of problem solving is to divide and conquer. This means that the problem has to be divided into smaller problems, each of which must be solved to get the complete solution.
For instance, if it is required to find the second smallest element in an array, the problem could be divided into two parts viz.
Arranging the elements in the array in ascending or descending order and then getting the second smallest element form the sorted array.
This strategy is called divide and conquer.
If you want to find the sum of the digits in a number, it can be divided into 3 parts:
1. Finding modulus of 10 i.e. finding the remainder when the number is divided by 10.
2. Adding the remainder to a sum whose initial value is zero.
3. Dividing the number by 10 and then repeating the process from (1) again till the quotient is zero.
No comments:
Post a Comment