0% found this document useful (0 votes)
43 views

Lecture 13 - Problem Decomposition

The document discusses problem decomposition, which is the process of breaking down complex problems into smaller, more manageable subproblems. This allows problems to be solved using a "divide and conquer" approach where each subproblem is addressed individually and the solutions are then combined. Several examples are provided to illustrate how large, complex tasks like making a pizza, organizing a school trip, and developing software can be decomposed into smaller steps. Binary search is used as an example of how decomposition reduces the complexity of algorithms by dividing problems into subproblems that can be solved independently.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Lecture 13 - Problem Decomposition

The document discusses problem decomposition, which is the process of breaking down complex problems into smaller, more manageable subproblems. This allows problems to be solved using a "divide and conquer" approach where each subproblem is addressed individually and the solutions are then combined. Several examples are provided to illustrate how large, complex tasks like making a pizza, organizing a school trip, and developing software can be decomposed into smaller steps. Binary search is used as an example of how decomposition reduces the complexity of algorithms by dividing problems into subproblems that can be solved independently.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Session 13

Problem Decomposition
13. 1 Introduction
A solution to a large problem is often complex. It can be made simple if the problem is
broken down into smaller parts. Then each part can be solved individually and then the solutions
are combined to produce the solution to the original problem. The process of breaking down a
complex problem or system into smaller sub problems with more manageable parts is known as
Problem Decomposition.
 Decomposition helps to solve complex problems and manage large projects.
 Large problems can be tackled with “divide and conquer” method
 The problem should be decomposed such that every sub problem is of the same level of
detail.
 Each sub problem can be solved independently.
 The solutions to the sub problems can be combined to solve the original problem.

Example 1: Consider the problem of making a pizza. The task of making a pizza is a considerably
larger task. But it can be subdivided into the following subtasks.
1. Make crust
2. Make spread and sauce
3. Spread cheese
4. Spread toppings
5. Bake
6. Slice

Fig. 13.1 Dividing a problem into smaller subproblems


Hence, if the task is divided into subtasks, the problem becomes smaller and more manageable.
Example 2: Organizing a school trip
The task of organizing a school trip can be subdivided into sub tasks such as, booking a coach,
getting consent letters, staffing, checking weather and checking resources. Each subtask can be
delegated to different persons and finally the school trip can be successfully organized easily.

Fig. 13.2 Decomposition of ‘Organizing a School Trip’


Example 3: Designing a course curriculum
Typically this would be decomposed as years and subjects, further decomposed into terms, units
of work and individual lessons or activities. Then each task will be given to a team member and
the team would work together to integrate the parts properly.
Example 4: Software Development
Software development is also a complex process. Therefore, to break down a large project into
its component parts is essential. A program like developing a powerpoint software will have so
many individual components.
Example 5: Searching a List using binary search
Binary search is an apt example of how the divide and conquer technique is applied in
programming. Binary search is a technique used to search a given element in a list of elements.
The usual method of searching an element is the linear search. In linear search, the given element
is first compared with the first element in the list. If there is a mismatch, it is compared with the
second element. If there is again a mismatch, it is compared with the third element and so on. The
comparison continues until a match is found or the entire list has been compared. Therefore, if the
search element, for example, is at the bottom of the list, the algorithm will have much complexity.
An alternative search method is the binary search method. In this search method, the divide
and conquer technique is applied which reduces the complexity of the algorithm. Let us consider
a list as shown in Fig. 13.3.

0 1 2 3 4 5 6 7 8 9 10

20 23 15 7 4 8 10 20 40 25 12

Fig. 13.3 List of numbers


In the list shown in Fig. 13.3, 0,1,2,3, etc. on the upper row indicate the position of the elements
in the list. 20, 23, 15, 7 etc. indicate the elements stored in the list. In this list, we have to search
whether the element 25 is present or not. To apply binary search technique, the list should be
sorted initially. The sorted list is shown in Fig. 13.4.

0 1 2 3 4 5 6 7 8 9 10

4 7 8 10 12 15 20 20 23 25 40

Fig. 13.4 List sorted in ascending order


Now,
low = 0 (the position of the first element)
high = 10 (the position of the last element)
The position of the middle element is calculated using the formula,
mid = low + (high - low)/2
Therefore, mid = 0 + (10-0)/2 = 5
Hence, the middle element is the element in position 5, which is 15. Now the search element 25 is
less than 15. Therefore, it will be found only in the upper half of the list. Hence, the lower half of
the list can be discarded as shown in Fig. 13.5.
0 1 2 3 4 5 6 7 8 9 10

4 7 8 10 12 15 20 20 23 25 40

Fig. 13.5 Middle Element 15; 25<15; So, left half is discarded
Now, the new low is calculated as low = mid + 1, since the lower half of the list is discarded. If
the upper half is discarded, low will be calculated as low = mid – 1.
So
low = mid+1 = 5+1 = 6
mid = 6 + (10-6)/2 = 6 + 2 = 8

6 7 8 9 10

20 20 23 25 40
Fig. 13. 6 New list
Now the search element is to be searched only in the upper half of the list shown in Fig. 13.6. The
low and middle values are calculated as shown above and the middle element is 23. Since, 25>23,
once again the lower half of the list is discarded and the upper half is considered. The low and
middle values are calculated using the usual formula.
low = mid + 1 = 8 + 1 = 9
mid = low + (high-low)/2 = 9 + (10-9)/2 = 9.5 = 10.
Now the new list is shown in Fig. 13.7.

9 10

25 40

Fig. 13.7 New list


Once again, 25 is compared with the new middle element 40 and since it is less than 40, it should
be in the lower half of the array. Therefore, the upper half element 40 is discarded and the
remaining list is considered. The values are calculated as before,
low = mid – 1 = 10 – 1 = 9
mid = low + (high-low)/2 = 9 + (10-9)/2 = 9.5
Now only one element is remaining i.e. 25. Therefore, it is compared with the search element.
Since a match is found, the given element is found in the array. Otherwise, the element is not found
in the array.
A comparison with linear search
The steps for linear search is given below:
Is 25=20, No => Move to next element
Is 25=23, No => Move to next element
Is 25=15, No => Move to next element
Is 25=7, No => Move to next element
Is 25=4, No => Move to next element
Is 25=8, No => Move to next element
Is 25=10, No => Move to next element
Is 25=20, No => Move to next element
Is 25=40, No => Move to next element
Is 25=25, Yes => Stop
It shows that the steps are more, if linear search is used especially when the size of the list is large
and the search element is found in the extreme portion of the list.
Example 6: Computer Hardware
Computer hardware: a smartphone or a laptop computer is itself composed of many components,
often produced independently by specialist manufacturers and assembled to make the finished
product, each under the control of the operating system and applications.
Example 7: Solving a Crime
• Imagine that a crime has been committed. Solving a crime can be a very complex problem
as there are many things to consider.
• For example, a police officer would need to know the answer to a series of smaller
problems:
– what crime was committed
– when the crime was committed
– where the crime was committed
– what evidence there is
– if there were any witnesses
– if there have recently been any similar crimes
• The complex problem of the committed crime has now been broken down into simpler
problems that can be examined individually, in detail.
Example 8: Creating an App
To decompose this task, you would need to know the answer to a series of smaller problems:
• What kind of app you want to create
• What your app will look like
• Who the target audience for your app is
• What your graphics will look like
• What audio you will include
• What software you will use to build your app
• How the user will navigate your app
• How you will test your app
• Where you will sell your app
This list has broken down the complex problem of creating an app into much simpler problems
that can now be worked out. You may also be able to get other people to help you with different
individual parts of the app.
For example, you may have a friend who can create the graphics, while another will be your tester.
Example 9: Decomposition in Writing
The frequently taught writing technique is called outlining which means to organize a work
beginning by decomposing the entire work into its main ideas. Each of the main task might be
divided into sub points, like dividing problems into sub problems. Outlining can continue by
decomposing any appropriate subpoint into its own sub points. The standard notation for outlining
uses,
Roman numerals to index the main tasks
Capital letters for the first level sub points
Numbers for the second level sub points
Small letters for the third level sub point … so on and so forth.

Fig. 13.8 Sample Outlining


Fig. 13.8 shows a sample.
13.2 Why is Decomposition Important?
If a problem is not decomposed, it is much harder to solve. Dealing with many
different stages all at once is much more difficult than breaking a problem down into a
number of smaller problems and solving each one, one at a time. Breaking the problem
down into smaller parts means that each smaller problem can be examined in more detail.
Similarly, trying to understand how a complex system works is easier using decomposition.
For example, Understanding how a bicycle works is more straightforward than to separate
it into smaller parts and then each part is examined to see how it works in more detail. On
the other hand, if you want to know the working of each part in detail, it would be feasible
only if you separated into individual parts and see how every part is working.

13.3 Advantages and Disadvantages of Decomposition


Advantages
 Different people can work on different sub problems /Modules.
 Parallelization may be possible.
 Maintenance is easier.
Disadvantages
 The solutions to the sub problems might not combine to solve the original problem .
 Poorly understood problems are hard to decompose.

13.4 Decomposition in Software Design


Decomposition in computer science,, is breaking a complex problem or system into parts that
are easier to conceive, understand, program, and maintain. This involves top-down design. In top-
down design, in which design begins by specifying complex pieces and then dividing them into
successively smaller pieces.

Fig. 13.9 Example for Modular Designing


13.5 Activities
Divide the following problems into modules.
1. Finding the sum of first ‘n’ natural numbers
2. Finding the factorial of a number
3. Finding the sum of the digits of a number
4. Counting the digits of a number and checking whether the given number is an Armstrong
number or not.
5. Counting the divisors of a number and checking whether the given number is prime or
composite.
6. Finding the sum of the divisors of a number and checking whether the given number is
perfect or not.
7. Evaluation of nCr.

You might also like