- Practice
- About 12 min
- 5 practice questions
Concept and terminology traps: translators, data structures, searching, sorting and OOP
Answer definition-style questions quickly by recalling one distinguishing fact for each pair of look-alike programming terms.
If something looks wrong, please tell us.
Many programming questions are not traces but definitions. The options are built from look-alike terms, so the winning habit is to remember one distinguishing fact for each pair. This lesson collects those facts and then shows how to use them to eliminate options.
Pairs and their distinguishing fact
| Pair | Distinguishing fact |
|---|---|
| Compiler / interpreter | A compiler translates the whole program first; an interpreter translates and runs it line by line |
| Source code / object code | Source code is written by people; object code is the translated machine code |
| Syntax error / logical error | Syntax error breaks the grammar rules and stops translation; logical error runs but gives wrong results |
| Runtime error / logical error | A runtime error stops the program while it runs, for example dividing by zero |
| Stack / queue | Stack is last in, first out; queue is first in, first out |
| Linear / binary search | Binary search needs sorted data and halves the range each time |
| Bubble / selection sort | Bubble swaps neighbours; selection picks the smallest each time |
| Local / global variable | Local exists only in its function; global is visible everywhere |
| Class / object | A class is the blueprint; an object is one thing built from it |
| Algorithm / program | An algorithm is the plan in steps; a program is the plan written in a programming language |
| Pseudocode / flowchart | Pseudocode is words; a flowchart is a diagram |
Programming terms in one line
- Variable: a named memory location whose value can change. Constant: a value that does not change.
- Function: a named, reusable block of code; parameter: an input to it; return value: what it gives back.
- Loop: repeats steps; selection: chooses a path; sequence: steps in order.
- Debugging: finding and fixing errors. Bug: an error in a program.
- High-level language: close to human language and independent of the machine; low-level language: close to the machine.
Worked example 1: eliminate
Which of these is NOT a feature of a compiler? (a) Translates the entire program, (b) Produces object code, (c) Executes the program line by line, (d) Reports syntax errors. Only (c) describes an interpreter, so (c) is the answer.
Worked example 2: classify the error
A program is meant to print the average of three numbers but it adds them and divides by 2. It runs and prints a number, but the number is wrong. A program that runs and gives wrong output has a logical error, because the grammar is fine and nothing stops it. If a bracket were missing, it would be a syntax error; if it tried to divide by an input of 0, a runtime error.
Worked example 3: structure from the story
"Customers are served in the order they arrive." This is first in, first out: a queue. "The last page visited is the first one the Back button returns to." This is last in, first out: a stack. "A list that must be sorted before it can be halved repeatedly" describes binary search.
For each pair, remember one fact that only one member of the pair has.
Common traps
- Saying the interpreter creates a separate object file for the whole program.
- Calling every wrong result a syntax error.
- Confusing a class with an object.
- Forgetting that binary search needs a sorted list.
Check your understanding
-
1. Which translator executes a program statement by statement?
- Compiler
- Assembler
- Interpreter
- Preprocessor
Show answer
Answer: C. An interpreter translates and runs one statement at a time.
-
2. A program runs to the end but prints a wrong answer. This is a
- Syntax error
- Runtime error
- Compile-time error
- Logical error
Show answer
Answer: D. Wrong results from a program that runs normally indicate a logical error.
-
3. Which structure is first in, first out?
- Stack
- Array
- Queue
- Tree
Show answer
Answer: C. A queue removes the item that arrived first.
-
4. A class is best described as:
- A blueprint for objects
- A running program copy
- A name for a variable
- A kind of program loop
Show answer
Answer: A. A class is a blueprint or template from which objects are made.
-
5. Which search method halves the range on each step?
- Linear search
- Binary search
- Random search
- Serial search
Show answer
Answer: B. Binary search divides a sorted list in half at every comparison.
Sign in to keep track of the lessons you finish.