levo

Theory of Computation

Decomposition and Composition

  • 2 things to know
  • Paper 1
Start revising · £5/month

Overview

Recall questions on what procedural decomposition is, how a problem is broken down, its benefits and what distinguishes a good decomposition.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Evaluation

State three benefits of decomposing a problem before writing any code.

Key term

Give three examples of compound data objects built from previously defined types.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is procedural decomposition?

    Model answer

    In procedural decomposition a problem is split into sub-problems, each of which accomplishes some identifiable task, and any sub-problem still too large can be split again in the same way. A payroll system, for example, separates into reading employee records, calculating gross pay, deducting tax and printing payslips — and 'deducting tax' may itself break down further into separate bands and allowances.

  2. 2

    Decompose the problem 'produce end-of-year reports for a school' and show the further subdivision.

    Model answer

    At the top level: read the marks from file; calculate each student's results; sort the students into class order; produce the report documents. Each accomplishes an identifiable task. 'Calculate each student's results' subdivides further into: calculate the mean mark per subject; convert each mark into a grade; work out the overall average. 'Produce the report documents' subdivides into: fill in the heading with the student's details; add one line per subject; add the tutor's comment. The subdivision stops when each remaining task is small enough to write as a single procedure.

  3. 3

    State three benefits of decomposing a problem before writing any code.

    Model answer

    Each sub-problem is small enough to be understood, written and tested on its own, so mistakes are found in one small piece rather than in a large tangle. Different people can work on different sub-problems at the same time, because each has a defined task. Sub-problems that occur more than once — such as 'convert a mark into a grade' — need only be solved once and can be reused wherever they are needed, and can be improved later in one place.

  4. 4

    How do you tell a good decomposition from a poor one?

    Model answer

    In a good decomposition each sub-problem accomplishes a single identifiable task that can be named in a few words, and the sub-problems interact through a small, clearly stated set of values passed between them. In a poor one the pieces are named vaguely, several pieces have to be changed together whenever the requirement changes, and each piece needs to know a great deal about the internal workings of the others — which means the problem has been cut in the wrong place.

  5. 5

    What is composition, and how does it relate to decomposition?

    Model answer

    Composition is building something larger by combining existing parts: combining procedures to form compound procedures, and combining data objects to form compound data. It is the opposite direction of travel from decomposition, which starts with a whole problem and splits it into sub-problems. In practice a solution is decomposed on paper and then composed in code, the small procedures being written first and combined into larger ones.

  6. 6

    Give a worked example of building a compound procedure by composition.

    Model answer

    Suppose validateMark, convertToGrade and writeToReport already exist. A compound procedure is built by combining them: PROCEDURE processStudent(student) FOR EACH mark IN student.marks IF validateMark(mark) THEN grade ← convertToGrade(mark) writeToReport(student, grade) ENDIF ENDFOR ENDPROCEDURE processStudent is a new procedure made entirely out of existing ones, and it can in turn be combined into processWholeClass. Each level can be used without knowing how the level below works.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Theory of Computation, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.