大象传媒

Decomposition and abstraction - EdexcelDecomposition and abstraction

Decomposition is a crucial step for an algorithm to be designed effectively. Once a problem is broken down into smaller steps, it can then be understood much easier, rather than attempting to solve it as a whole.

Part of Computer SciencePrinciples of computer science

Decomposition and abstraction

involves analysing a complex problem or system and breaking it down into smaller parts that are more manageable and easy to understand. The smaller parts can then be examined and solved, or designed individually, as they are simpler to work with.

If a problem is not decomposed, it is much harder to solve. Dealing with a complex problem is much more difficult than breaking a problem down into subproblems and solving them, one at a time. Smaller problems are easier to understand and can be examined in more detail.

For example, suppose that a crime has been committed. Solving a crime can be a very complex problem as there are many things to consider.

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. Once the individual information has been gathered and collated, the police officer may be able to solve the crime.

Question

How might you decompose the complex problem of how to create an app?

Abstraction

is the process of filtering out - essentially ignoring - the characteristics of problems that are not needed in order to concentrate on those that are needed. It is also the filtering out of specific details. From this, an idea of what is to be solved can be created.

Abstraction allows programmers to create a general idea of what the problem is and how to solve it. The process instructs them to remove all specific detail and any patterns that will not help find a solution. An idea of the problem can then be formed. This idea is known as a 鈥榤odel鈥.

Consider the problem of how a program might be required to calculate the area of any rectangle. All rectangles share general characteristics:

  • a width
  • a height
  • a formula to calculate area: area = width 脳 height

When abstracting, certain details are discarded but others are kept:

  • all rectangles have a width, but for the program design the actual rectangle width is not needed
  • all rectangles have a height, but for the program design the actual rectangle height is not needed
  • area is always width 脳 height

To solve this problem, the program needs to be able to input a width and a height, then calculate the area from those numbers. The actual numbers are irrelevant - they change with every rectangle - and so are discarded.

An example of abstraction is the London Underground map. It details tube and rail lines and the stations that are on them. That is all that is required for passengers to be able to plan a journey from one station to another. Other details, such as real geographical location, distance between stations, depth underground and number of platforms are not included. They are not relevant to journey planning on the Underground.

A section of the London Underground tube map