levo

Theory of Computation

Decomposition and Composition

  • 2 things to know
  • Paper 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

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

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

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

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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