First 50 of 190 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.
Continue in the practice tool above to load more questions, 50 at a time.
Question 1Programming, object modelling and software development
In Java, an abstract class:
- Cannot be instantiated directly and may contain abstract methods declared without a body Correct answer.
- Must contain only static methods
- Can never have a constructor declared
- Is identical to a primitive type
Explanation
An abstract class models a partial type: it may declare abstract methods (to be implemented by subclasses) and concrete members, but no direct instances - an LK modelling concept beyond GK object basics.
Question 2Programming, object modelling and software development
A Java interface (treating only pre–Java 8 abstract method declarations) specifies:
- A contract of method signatures that implementing classes must provide Correct answer.
- A concrete superclass with stored attributes
- A relational schema for SQL tables
- A primitive numeric range
Explanation
An interface declares method signatures without implementation; classes state `implements` and supply bodies. This separates contract from implementation - LK OOP design content.
Question 3Programming, object modelling and software development
In UML, the difference between composition (filled diamond) and aggregation (hollow diamond) is:
- Composition ties the part's lifetime to the whole; aggregation does not Correct answer.
- Composition forbids any methods on the whole
- Aggregation requires the part to be a primitive type
- They are identical notations
Explanation
Composition is a strong 'owns' relation: if the whole is destroyed, the parts cease to exist; aggregation is a weaker 'has-a' where parts outlive the whole. This UML distinction is LK-level modelling detail.
Question 4Programming, object modelling and software development
Dynamic (late) binding in Java means that for `Shape s = new Circle();`, the call `s.area()`:
- Dispatches to Circle's overridden area() based on the runtime type Correct answer.
- Always calls Shape's area() because of the declared type
- Cannot compile because types differ
- Resolves to a static method of Shape
Explanation
The declared type Shape determines the call's admissibility at compile time, but the runtime type Circle selects the overridden method - the mechanism behind polymorphism, examined at erhöhtes Niveau.
Question 5Programming, object modelling and software development
The Liskov Substitution Principle (informally) requires that:
- Subtypes must be usable wherever a supertype is expected without surprising behavior Correct answer.
- Subtypes must inherit every attribute as public
- Subtypes may weaken the supertype's method signatures arbitrarily
- A subtype may remove methods it dislikes
Explanation
LSP is a behavioural subtyping rule: objects of a subtype must honour the supertype's contract so that client code is unchanged. It is a design-by-contract idea at LK depth.
Question 6Programming, object modelling and software development
A class invariant is best described as:
- A condition that must hold for every instance before and after each public method call Correct answer.
- A loop counter inside one method
- A SQL constraint on a foreign key
- The name of a sorting algorithm
Explanation
Invariants characterise the valid state of an object; methods may temporarily violate them internally but must restore them before returning - a design-by-contract concept at LK level.
Question 7Programming, object modelling and software development
In Java a class may implement multiple interfaces but extend at most one class because:
- Java permits multiple interface inheritance but single class inheritance to avoid diamond ambiguity Correct answer.
- Java forbids interfaces entirely
- A class may extend at most zero classes
- Multiple interfaces always produce a compile error
Explanation
Java's single-class-inheritance rule avoids the diamond problem of multiple state inheritance, while multiple interfaces (pure contracts) keep type flexibility - an LK design rationale.
Question 8Programming, object modelling and software development
Given `List<Shape> shapes` holding Circle and Square objects, iterating and calling `area()` on each element:
- Invokes each element's runtime area() method via dynamic dispatch Correct answer.
- Calls a single Shape.area() for all elements
- Fails because lists cannot hold different types
- Returns a constant for every element
Explanation
A polymorphic collection stores references of the declared type but dispatches on each object's runtime type, so Circle.area() and Square.area() run as appropriate - LK polymorphism in collections.
Question 9Programming, object modelling and software development
For `Shape s = new Circle();`, which statement about types is correct?
- Static (compile-time) type Shape, dynamic (runtime) type Circle Correct answer.
- Both types are Circle
- Both types are Shape
- The static type is Circle and the dynamic type is Shape
Explanation
The declared variable type is the static type (Shape), used for legality checks; the object actually referenced is the dynamic type (Circle), used for method dispatch - the static/dynamic distinction is LK material.
Question 10Algorithms, recursion and complexity
The information-theoretic lower bound for any comparison-based sort of n distinct keys is:
- Ω(n log n) comparisons Correct answer.
- Ω(n) comparisons
- Ω(n²) comparisons
- Ω(log n) comparisons
Explanation
A comparison sort corresponds to a binary decision tree over n! orderings; its height is at least ⌈log₂(n!)⌉ = Ω(n log n) (Stirling). This lower bound is standard erhöhtes Niveau analysis.
Question 11Algorithms, recursion and complexity
Heapsort's worst-case time complexity on n elements is:
- Θ(n log n) Correct answer.
- Θ(n²)
- Θ(n)
- Θ(2ⁿ)
Explanation
Building the heap is O(n) and each of the n extractions costs O(log n) sift-down, giving Θ(n log n) worst case - and unlike quicksort, this is guaranteed, not just expected.
Question 12Algorithms, recursion and complexity
Insertion sort on a reverse-sorted array of n distinct elements performs how many comparisons (inversions)?
- n(n−1)/2 - the maximum inversion count Correct answer.
- n
- ⌈log₂ n⌉
- exactly n−1 swaps only, regardless of comparisons
Explanation
Reverse-sorted input has the maximum number of inversions, n(n−1)/2; each inversion forces one comparison-and-shift, so insertion sort runs in Θ(n²) on this input.
Question 13Algorithms, recursion and complexity
Which algorithm first arranges the data into a heap and then repeatedly extracts the maximum to the end of the array?
- Heapsort Correct answer.
- Mergesort
- Bubblesort
- Counting sort
Explanation
Heapsort = build-heap (O(n)) followed by n extract-max/sift-down steps, placing each max at the shrinking end - the heap-based O(n log n) sort.
Question 14Algorithms, recursion and complexity
Merging two already sorted runs of lengths p and q needs at most how many key comparisons?
- p + q − 1 Correct answer.
- p · q
- p + q
- max(p, q)
Explanation
Each comparison emits one element to the output; once one run is exhausted the rest of the other is copied without comparison. Hence at most p+q−1 comparisons - the LK merge-step bound underlying mergesort's Θ(n log n).
Question 15Algorithms, recursion and complexity
Quicksort with a uniformly random pivot has what expected time complexity?
- Θ(n log n) expected Correct answer.
- Θ(n²) expected
- Θ(n) expected
- Θ(2ⁿ) expected
Explanation
Randomisation makes balanced splits probable in expectation, so E[T(n)] = Θ(n log n); the Θ(n²) outcome still exists but is exponentially unlikely. This expectation analysis is erhöhtes Niveau material beyond the worst-case statement.
Question 16Algorithms, recursion and complexity
Which statement about heapsort stability is correct?
- Heapsort is generally not stable because extraction can reorder equal keys Correct answer.
- Heapsort is always stable by definition
- Stability is guaranteed only for n ≤ 10
- Heapsort's stability depends on the pivot choice
Explanation
The heap's array-based extraction swaps distant elements, which can change the relative order of equal keys, so heapsort is not stable in its standard form - an LK-level refinement of the stability concept.
Question 17Algorithms, recursion and complexity
Counting sort runs in O(n + k). In that bound, k represents:
- The range of the key values (max−min, or the size of the key universe) Correct answer.
- The number of elements n
- The recursion depth
- The number of comparisons
Explanation
Counting sort builds a frequency array over the key range k and is non-comparison based; it beats the Ω(n log n) comparison lower bound only when k = O(n). This trade-off is LK analysis.
Question 18Algorithms, recursion and complexity
The mergesort recurrence T(n) = 2T(n/2) + Θ(n) solves to:
- Θ(n log n) Correct answer.
- Θ(n²)
- Θ(2ⁿ)
- Θ(log n)
Explanation
Two half-size subproblems plus linear merge work: by the Master theorem (a=2, b=2, f=Θ(n)=Θ(n^{log_b a})) this is case 2, giving Θ(n log n). LK derivation rather than stating the result.
Question 19Algorithms, recursion and complexity
The Master theorem applies to recurrences of the form T(n) = a·T(n/b) + f(n). Which condition on a and b is required?
- a ≥ 1 and b > 1 Correct answer.
- a = 0 and b = 1
- a > b always
- b < 1
Explanation
a ≥ 1 (at least one subproblem) and b > 1 (the subproblem is strictly smaller) are the standard Master-theorem preconditions - an LK formal requirement.
Question 20Algorithms, recursion and complexity
The Towers of Hanoi puzzle with n disks, under the rule that a larger disk may never sit on a smaller one, requires how many disk moves?
- 2ⁿ − 1 moves Correct answer.
- n² moves
- n! moves
- exactly n moves
Explanation
To move n disks you move n−1 aside (T(n−1)), move the base disk (1), then move the n−1 back (T(n−1)): T(n)=2T(n−1)+1 with T(1)=1 solves to 2ⁿ−1 - a classic LK exponential recurrence.
Question 21Algorithms, recursion and complexity
By the Master theorem, T(n) = 2T(n/2) + Θ(n) (a=2, b=2, n^{log_b a}=n) gives:
- Θ(n log n) - case 2 (f matches n^{log_b a}) Correct answer.
- Θ(n²) - case 3
- Θ(n) - case 1
- Θ(2ⁿ)
Explanation
Here log_b a = 1, so n^{log_b a} = n and f(n)=Θ(n) matches it exactly - the critical-exponent equality that defines case 2, yielding Θ(n log n).
Question 22Algorithms, recursion and complexity
By the Master theorem, T(n) = 4T(n/2) + Θ(n) gives which order (a=4, b=2, n^{log_b a}=n²)?
- Θ(n²) - case 1 (f is polynomially smaller than n²) Correct answer.
- Θ(n log n)
- Θ(n)
- Θ(2ⁿ)
Explanation
log₂ 4 = 2, so n^{log_b a}=n²; f(n)=Θ(n) is polynomially smaller (case 1), and the recursion tree is dominated by its leaves → Θ(n²).
Question 23Algorithms, recursion and complexity
Converting a tail-recursive function to an equivalent loop typically changes the space complexity by:
- Reducing stack usage to O(1) because the recursive frame need not be kept Correct answer.
- Increasing stack usage to O(n)
- Leaving time complexity at Θ(2ⁿ)
- Making the function non-terminating
Explanation
A tail call does nothing after the recursive return, so a compiler/transform can reuse one frame, yielding O(1) space - an LK link between recursion form and resource cost.
Question 24Algorithms, recursion and complexity
Memoizing naive recursive fibonacci changes its time complexity from Θ(φⁿ) approximately to:
- Θ(n), since each fib(k) is computed once and reused Correct answer.
- Θ(n²)
- Θ(1)
- Θ(2ⁿ)
Explanation
Each fib(k) depends on fib(k−1) and fib(k−2); caching makes the n distinct subproblems linear in n, the bridge from naive recursion to dynamic programming at LK level.
Question 25Algorithms, recursion and complexity
The linear recurrence T(n) = T(n−1) + Θ(1) with a constant base case solves to:
- Θ(n) Correct answer.
- Θ(n log n)
- Θ(2ⁿ)
- Θ(log n)
Explanation
Each step shrinks the problem by one and adds constant work, so the total is the sum of n constant terms → Θ(n). This contrasts with T(n)=2T(n−1)+Θ(1)=Θ(2ⁿ).
Question 26Algorithms, recursion and complexity
A recursive inorder traversal of a balanced BST with n nodes has recursion depth approximately:
- Θ(log n), because the tree height is logarithmic when balanced Correct answer.
- Θ(n), because every node is visited
- Θ(n log n)
- Θ(2ⁿ)
Explanation
Recursion depth tracks the current path length, i.e. the tree height; a balanced BST has height Θ(log n). Total work is Θ(n) (all nodes), but depth is logarithmic - an LK distinction between total cost and stack depth.
Question 27Algorithms, recursion and complexity
Naive recursive fibonacci satisfies T(n) = T(n−1) + T(n−2) + Θ(1). Its growth is closest to:
- Θ(φⁿ) where φ = (1+√5)/2 ≈ 1.618 Correct answer.
- Θ(n²)
- Θ(n log n)
- Θ(2ⁿ)
Explanation
Solving the Fibonacci recurrence gives growth governed by the golden ratio φ ≈ 1.618, so T(n)=Θ(φⁿ) - the LK closed form, more precise than the loose 'exponential' label.
Question 28Algorithms, recursion and complexity
The complexity class P is the set of decision problems:
- Solvable by a deterministic algorithm in polynomial time Correct answer.
- Verifiable in polynomial time but not necessarily solvable
- Solvable only with exponential time
- That are undecidable
Explanation
P = decision problems with a deterministic polynomial-time algorithm. Defining P precisely (rather than the informal 'efficient') is LK complexity theory.
Question 29Algorithms, recursion and complexity
The class NP is the set of decision problems:
- Whose yes-answers can be verified in polynomial time (equivalently, solvable nondeterministically in polynomial time) Correct answer.
- Solvable only in exponential time
- That are provably intractable
- That are undecidable
Explanation
NP is defined by polynomial-time verification of certificates (or nondeterministic polynomial-time solution). Note NP does not stand for 'not polynomial' - an LK definition and a common misconception.
Question 30Algorithms, recursion and complexity
If A is NP-complete and A ≤p B (polynomial-time reduction), then B is:
- NP-hard (at least as hard as every problem in NP) Correct answer.
- Definitely in P
- Decidable in O(1)
- Regular
Explanation
An NP-complete problem reduces to B in polynomial time, so every NP problem reduces (via A) to B; B is therefore NP-hard. If additionally B ∈ NP, then B is NP-complete - an LK reduction-direction argument.
Question 31Algorithms, recursion and complexity
A decision problem is decidable if:
- There exists an algorithm that halts with the correct yes/no answer on every input Correct answer.
- It can be solved quickly in practice
- It has only finitely many inputs
- It is in P
Explanation
Decidability requires a total algorithm that always halts with the right answer. Decidable problems need not be fast or in P - an LK distinction between decidability and tractability.
Question 32Algorithms, recursion and complexity
To prove a new problem B is NP-hard, the standard method is to:
- Reduce a known NP-complete problem to B in polynomial time (A ≤p B) Correct answer.
- Reduce B to a problem in P
- Show B has a polynomial verification algorithm
- Show B is regular
Explanation
Reducing a known NP-complete A to B shows B is at least as hard as A, hence NP-hard. The reduction direction (A to B) is the LK-critical detail; the converse does not prove hardness.
Question 33Algorithms, recursion and complexity
Master theorem case 1 applies when f(n) = O(n^{log_b a − ε}) for some ε > 0. The result is:
- T(n) = Θ(n^{log_b a}) Correct answer.
- T(n) = Θ(n^{log_b a} log n)
- T(n) = Θ(f(n))
- T(n) = Θ(2ⁿ)
Explanation
When the combine work f is polynomially smaller than the leaf work n^{log_b a}, the recursion tree is leaf-dominated, giving Θ(n^{log_b a}) - the LK case-1 statement.
Question 34Algorithms, recursion and complexity
Which proof-style judgment about O-notation is correct?
- If f(n)=O(n) and g(n)=O(n), then (f+g)(n)=O(n) Correct answer.
- If f(n)=O(n), then necessarily f(n)=Ω(n²)
- O(n²) implies O(1)
- Θ(n) forbids f being O(n)
Explanation
Sums preserve O(n). O(n) does not imply Ω(n²); O(n²) is a weaker upper bound than O(1); Θ(n) implies O(n). Such closure facts are typical erhöhtes-Niveau complexity judgment.
Question 35Algorithms, recursion and complexity
Which reduction-style judgment is sound at LK depth?
- If A ≤p B and B ∈ P, then A ∈ P Correct answer.
- If A reduces to B and A is undecidable, then B must be decidable
- Polynomial reductions apply only to sorting algorithms
- P is defined using arbitrary exponential-time reductions only
Explanation
Polynomial-time reductions transfer membership in P from B to A. Undecidability transfers the other way: if A ≤ B and A is undecidable, B is undecidable.
Question 36Algorithms, recursion and complexity
Amortised analysis is used to:
- Bound the average cost per operation over a sequence, even if single operations are occasionally expensive Correct answer.
- Measure the wall-clock time of one specific operation
- Count the number of states in a DFA
- Prove a language is regular
Explanation
Some data structures have cheap common operations and rare expensive ones (e.g. dynamic-array resizing); amortised analysis averages across a sequence to state a tight per-operation bound - an LK analysis technique.
Question 37Digital representation and data structures
For a worst-case lookup, which statement about binary search trees is correct?
- Search is Θ(log n) in a balanced BST but can degrade to Θ(n) if the tree is skewed Correct answer.
- Search is always Θ(1) for every insertion sequence
- BSTs forbid inorder enumeration of keys
- A BST is identical to a FIFO queue
Explanation
Q1.4 höhere Datenstrukturen: BST cost tracks height. Balance keeps logarithmic height; sorted insertions into an unbalanced BST yield a chain of height n.
Question 38Digital representation and data structures
Which graph representation is preferable for a sparse directed graph with n vertices and m ≪ n² edges?
- Adjacency lists using Θ(n + m) space Correct answer.
- An adjacency matrix only, requiring Θ(n²) space regardless of m
- A single scalar with no edge storage
- A sorted array of all possible n² edges always materialised
Explanation
Adjacency lists scale with vertices plus edges. Matrices cost Θ(n²) even when few edges exist - a key Q1.4 modelling/complexity judgment.
Question 39Digital representation and data structures
BFS on an unweighted graph from a source yields:
- Shortest paths measured in number of edges Correct answer.
- A minimum spanning tree for arbitrary positive weights by definition
- A topological order of every cyclic graph
- Guaranteed Θ(1) time independent of n and m
Explanation
BFS explores by distance layers; first discovery is a shortest path in unweighted graphs - standard graph algorithm content at LK Q1.4.
Question 40Digital representation and data structures
A hash table with chaining resolves collisions by:
- Storing colliding keys in a secondary structure (often a list) at the same bucket Correct answer.
- Rejecting every key after the first insertion into the table
- Requiring the key universe to be sorted beforehand
- Converting the dictionary into a pure stack ADT
Explanation
Chaining is a core hashing technique under Q1.4 höhere Datenstrukturen: multiple keys mapping to one index share a bucket chain.
Question 41Digital representation and data structures
Load factor α = n/m in a hash table primarily influences:
- Expected chain length / probe cost under standard simple uniform hashing models Correct answer.
- Whether a DFA can recognise aⁿbⁿ
- The Notenpunkte scale maximum
- Whether SQL INNER JOIN is allowed
Explanation
Under uniform hashing, expected cost grows with load factor α = keys/buckets - an LK judgment linking representation to complexity.
Question 42Digital representation and data structures
AVL (or similarly balanced) BST rotations are used to:
- Restore height-balance invariants after updates so searches stay logarithmic Correct answer.
- Turn every tree into a queue permanently
- Guarantee Θ(n) search after each insertion
- Eliminate the need for ordered keys
Explanation
Rotations locally restructure trees to maintain balance - deeper Q1.4 content beyond plain BST usage at LK level.
Question 43Digital representation and data structures
Dijkstra’s algorithm (non-negative edge weights) computes:
- Single-source shortest paths Correct answer.
- Maximum cliques in general graphs in polynomial time for all instances
- Only whether a language is regular
- Primary keys of an ER diagram
Explanation
Dijkstra grows a shortest-path tree from a source when weights are non-negative - LK graph-algorithm judgment under höhere Datenstrukturen.
Question 44Digital representation and data structures
Which OO modelling of a graph fits Q1.4 style best?
- Classes for Graph, Vertex, and Edge with associations/collections (e.g., adjacency lists) Correct answer.
- Making Graph a subclass of Integer only
- Forbidding objects and using only global static procedures with no structure
- Storing the graph solely as a single boolean flag
Explanation
LA26 Q1.4 emphasises object-oriented modelling of higher data structures: entities become classes; links become associations and collections.
Question 45Digital representation and data structures
Open addressing (linear probing) handles hash collisions by:
- Searching a probe sequence of alternate slots in the table array Correct answer.
- Ignoring the hash function after the first collision
- Allocating an infinite Turing-machine tape per key
- Sorting the entire table with mergesort after every insert
Explanation
Open addressing keeps entries in the table array and probes on collision - complementary to chaining in Q1.4 hashing.
Question 46Entity modelling, relational algebra and SQL
A functional dependency A → B on a relation means:
- Any two tuples that agree on A must also agree on B Correct answer.
- B always equals A
- A and B are both primary keys
- A is always NULL when B is NULL
Explanation
An FD A→B is a constraint: the A-value determines the B-value, so identical A implies identical B. FDs are the formal basis for normal forms at LK depth.
Question 47Entity modelling, relational algebra and SQL
Boyce-Codd Normal Form (BCNF) requires that for every nontrivial functional dependency X → Y, X is:
- A superkey Correct answer.
- A single attribute
- A foreign key
- The empty set
Explanation
BCNF is a stricter 3NF: every determinant of a nontrivial FD must be a superkey. This removes anomalies 3NF can still allow - LK normalisation theory.
Question 48Entity modelling, relational algebra and SQL
An insertion anomaly in a relation means:
- Certain facts cannot be recorded unless an unrelated fact is also present Correct answer.
- Rows can be added without any primary key
- SELECT queries run too slowly
- Foreign keys are auto-generated
Explanation
Anomalies are the motivation for normalisation. In an insertion anomaly you cannot, for example, store a new course until a student enrols in it - LK rationale for normal forms.
Question 49Entity modelling, relational algebra and SQL
A surrogate key is:
- An artificial, system-generated identifier with no business meaning, used as a primary key Correct answer.
- A foreign key that references a different table
- A key composed of all attributes
- A key that is always NULL
Explanation
Surrogate keys (e.g. an auto-increment id) decouple identity from business attributes, which may change; their use and trade-offs are LK modelling decisions.
Question 50Entity modelling, relational algebra and SQL
Denormalisation is best described as:
- Intentionally introducing redundancy to speed up reads at the cost of update anomalies Correct answer.
- Removing all keys from a schema
- A required step before 1NF
- Deleting tables to save space
Explanation
Denormalisation trades normal-form purity for read performance, accepting extra write complexity and anomaly risk - an LK design trade-off beyond pure normalisation.