levo

Theory of Computation

Data Abstraction and Problem Reduction

  • 2 things to know
  • Paper 1

Overview

Recall questions on what data abstraction is, the stack as a worked example and how new data objects are built from existing ones.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Evaluation

Why does data abstraction let a stack's representation be changed safely?

Process

Give a worked example of a real problem being reduced to one that is already solved.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is data abstraction?

    Model answer

    Data abstraction separates the way a compound data object is used from the way it is built. The details of how the data are actually represented are hidden, so fresh kinds of data object can be assembled out of ones already defined.

  2. 2

    Use a stack to give a worked example of data abstraction.

    Model answer

    How a stack is used is fixed by its operations: push adds an item, pop removes and returns the most recently added item, peek looks at it without removing it, and isEmpty reports whether there is anything there — last in, first out. How it is constructed is a separate matter: a stack could be implemented as an array together with a pointer holding the index of the top of the stack, where push increments the pointer and stores the item and pop returns the item at the pointer and decrements it. Data abstraction is the separation of those two things, so that code using the stack calls push and pop and never mentions the array or the pointer.

  3. 3

    That stack is built as an array plus a pointer. What does data abstraction let you do afterwards, and what would break if it were absent?

    Model answer

    It lets you replace the whole construction — say with a linked list where push adds a node at the front — and every program that uses the stack goes on working unchanged, because those programs only ever used push, pop, peek and isEmpty. Without data abstraction, code elsewhere would refer directly to the array and to the top-of-stack index; changing the representation would then mean finding and rewriting every such reference, and any code that had, for example, assumed a fixed array size would silently be wrong.

  4. 4

    How does data abstraction let new kinds of data objects be constructed from previously defined ones?

    Model answer

    Once a type has been defined by how it is used, it can be treated as a single building block in the definition of another type without its internals mattering. A queue of customers can be defined in terms of a previously defined Customer record; a graph can be defined as a set of vertices and a set of edges, each edge being a pair of previously defined vertices; a priority queue can be built on top of an existing heap. At each level the new object is described by its own operations, and the level below is used only through its operations.

  5. 5

    What is problem abstraction, also called problem reduction?

    Model answer

    Problem abstraction means paring a problem back, dropping detail after detail, until what remains is a problem that has already been solved — at which point the existing solution can simply be applied. Reducing a real road network to a weighted graph, for instance, turns 'find the quickest route between two towns' into the shortest-path problem, for which well-known algorithms are already available.

  6. 6

    Give a worked example of a real problem being reduced to one that is already solved.

    Model answer

    A satnav must find the quickest route across a city. Strip away the street names, the shop fronts, the traffic lights, the road surfaces and the geography, and keep only junctions, the roads joining them and a number on each road for how long it takes to travel. What remains is a weighted graph, and 'find the quickest route' has become 'find the shortest path between two vertices in a weighted graph' — a problem for which known algorithms already exist. No new algorithm has to be invented; the work was in the abstraction.

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.