Number systems
- Place values
- binary 2k, octal 8k, hex 16k
- To decimal
- Σ dk·bk
- From decimal
- divide by the base, read the remainders bottom-up
- Hex ↔ binary
- one hex digit = 4 bits
- Two’s complement
- invert the bits and add 1
Formula sheets, the key method steps for every topic and 20 practice problems, with full solutions at the back.
Set the bits so they store −15 in 8-bit two's complement. Read as an unsigned number, what is the pattern's value U?
Set the bits to the 8-bit result of 0101 0001 OR 1001 0011. What is the result's value R in decimal?
Is c → (c ∨ a) a tautology, a contradiction or a contingency? Click your answer.
Which statement is equivalent to ¬∃x (P(x) ∧ Q(x)), with the negation moved all the way inside? Click it.
Use the Karnaugh map to find the minimal sum-of-products (SOP) form of F(A, B, C, D) = Σm(2, 5, 7, 10, 13). How many literals L does it contain in total (a primed variable counts as one literal)?
Find the minimal SOP form of F(A, B, C, D) = Σm(3, 8, 11, 12, 13, 14) + d(4, 6), where d marks the don't-care conditions. How many product terms N does it have?
Solve 8x ≡ 30 (mod 31). Give the solution x with 0 < x < 31.
Encrypt the message m = 166 with the RSA public key (n, e) = (407, 7). Find the ciphertext c.
How much stack space does a simple recursive factorial function fact(n) = n × fact(n − 1) use?
How does the Bellman–Ford algorithm detect a negative-weight cycle reachable from the source?
Why is traversing an array often much faster in practice than traversing a linked list of the same length?
Why are B-trees used in databases and file systems?
Does the connected graph have an Euler circuit, an Euler path that is not a circuit, or neither? Click your answer.
How many closed walks of length 2 start and end at C? A walk may repeat vertices and edges. Call the number N.
Which statement about HAVING is correct?
Which SQL feature is best suited to finding every employee below a manager in an organisation tree of unknown depth?
What is the main difference between the HTTP methods GET and POST?
A path has 100 Mbit/s bandwidth and a 40 ms round-trip time. How much data must be in flight to keep it fully used?
A subnet uses the mask 255.255.240.0. How many usable host addresses H does it have?
A router has routes to these networks: 10.104.107.0/24, 10.104.108.0/24, 10.104.109.0/24. What is the longest prefix length p of a single summary route that covers all of them?
Answer: U = 241
Setting bits: each bit is worth a power of two (128, 64, …, 1). One hex digit is exactly four bits, and in 8-bit two's complement the leftmost bit is worth −128. Bitwise operations work on each bit position separately.
Answer: R = 211
Setting bits: each bit is worth a power of two (128, 64, …, 1). One hex digit is exactly four bits, and in 8-bit two's complement the leftmost bit is worth −128. Bitwise operations work on each bit position separately.
OR gives 1 where at least one bit is 1.
Answer: tautology
Logical equivalence: two formulas are equivalent (≡) when they have the same value in every row of the truth table. A tautology is 1 in every row, a contradiction is 0 in every row, and a contingency is neither. Useful laws: De Morgan, ¬(a ∧ b) ≡ ¬a ∨ ¬b and ¬(a ∨ b) ≡ ¬a ∧ ¬b; a → b ≡ ¬a ∨ b ≡ ¬b → ¬a (contrapositive); ¬(a → b) ≡ a ∧ ¬b; and the distributive laws, a ∨ (b ∧ c) ≡ (a ∨ b) ∧ (a ∨ c).
Answer: ∀x (P(x) → ¬Q(x))
Quantifiers and arguments: ¬∀x P(x) ≡ ∃x ¬P(x) and ¬∃x P(x) ≡ ∀x ¬P(x). Move a negation inwards, swap every quantifier it passes, and negate the inner formula with the propositional laws, such as ¬(a → b) ≡ a ∧ ¬b. An argument is valid when the conclusion is 1 in every row in which all premises are 1. A single row with true premises and a false conclusion is a counterexample and shows the argument is invalid.
The other options either keep a quantifier unchanged, change the order of the quantifiers, or negate the inner formula wrongly.
Answer: L = 9
Karnaugh maps: the cells are ordered in Gray code (00, 01, 11, 10), so neighbouring cells, including the ones across the edges, differ in exactly one variable. Group the 1s in rectangles of 1, 2, 4, 8 or 16 cells, as large as possible and as few as possible, until every 1 is covered. Each group is one product term: the variables that stay constant inside it. A group of 2ᵏ cells loses k variables. Don't-cares (X) may be used to make groups bigger but never have to be covered. Grouping the 0s instead gives the minimal POS form.
Every group is a rectangle of 2ᵏ cells; edge cells are neighbours of the cells on the opposite edge.
Answer: N = 4
Karnaugh maps: the cells are ordered in Gray code (00, 01, 11, 10), so neighbouring cells, including the ones across the edges, differ in exactly one variable. Group the 1s in rectangles of 1, 2, 4, 8 or 16 cells, as large as possible and as few as possible, until every 1 is covered. Each group is one product term: the variables that stay constant inside it. A group of 2ᵏ cells loses k variables. Don't-cares (X) may be used to make groups bigger but never have to be covered. Grouping the 0s instead gives the minimal POS form.
The largest groups that can be formed from 1s and Xs.
Answer: x = 27
Inverses and congruences: a has an inverse modulo n exactly when gcd(a, n) = 1. The extended Euclidean algorithm writes 1 = s·n + t·a, and then a⁻¹ ≡ t (mod n). A congruence a·x ≡ b (mod n) with gcd(a, n) = 1 has the solution x ≡ a⁻¹·b. Two congruences x ≡ r₁ (mod m₁) and x ≡ r₂ (mod m₂) with coprime moduli have one solution modulo m₁·m₂ (Chinese remainder theorem). Euler’s φ(n) counts the numbers from 1 to n that are coprime to n: φ(n) = n·∏(1 − 1/p).
Answer: c = 309
Modular powers and RSA: compute aᵏ mod n by repeated squaring: write k in binary, square, reduce after every step and multiply the powers whose bit is 1. Fermat: aᵖ⁻¹ ≡ 1 (mod p) for a prime p not dividing a, so the exponent can be reduced modulo p − 1. RSA: choose primes p and q, n = p·q and φ(n) = (p − 1)(q − 1); the public exponent e is coprime to φ(n), and the private exponent is d = e⁻¹ mod φ(n). Encrypt with c = mᵉ mod n and decrypt with m = cᵈ mod n.
Answer: A · O(n)
The recursion is n calls deep before any returns, and each call needs a stack frame, so it uses O(n) space.
Answer: A · After V − 1 rounds, it checks whether any edge can still be relaxed
All true shortest distances are found within V − 1 rounds; if an edge can still be improved, a negative cycle must exist.
Answer: B · Array elements are contiguous, so they make good use of the CPU cache
Contiguous memory gives good locality of reference, while linked nodes may be scattered and cause many cache misses.
Answer: D · Their high branching factor keeps the tree shallow, reducing slow disk reads
B-trees store many keys per node, so height is small and few block reads are needed per lookup; B+ trees also link leaves for range scans.
Answer: neither
Euler, Hamilton and trees: a connected graph has an Euler circuit (every edge once, back to the start) when every vertex has even degree, and an Euler path that is not a circuit when exactly two vertices have odd degree; the path then runs from one odd vertex to the other. A Hamilton circuit visits every vertex once; Kn has (n − 1)!/2 of them. A tree on n vertices has n − 1 edges, and a connected graph with m edges keeps a spanning tree after removing m − n + 1 edges.
Answer: N = 3
Degrees: the degree of a vertex is the number of edges that meet it. Every edge has two ends, so the degrees add up to twice the number of edges: Σ deg(v) = 2|E| (the handshake lemma). The number of vertices with odd degree is therefore even. Kn has n(n − 1)/2 edges, a k-regular graph on n vertices has nk/2, and a tree on n vertices has n − 1 edges.
Answer: A · It can use aggregate functions to filter groups
HAVING filters groups after aggregation and may reference aggregates; WHERE cannot.
Answer: A · A recursive common table expression (WITH RECURSIVE)
A recursive CTE starts with an anchor query and repeatedly joins the previous result to the table, so it handles hierarchies of any depth.
Answer: B · GET retrieves a resource, POST submits data in the request body
GET asks for a resource and should not change server state. POST sends data, such as a form, in the body for the server to process.
Answer: B · 500 kB
The bandwidth-delay product is 100 × 10⁶ bit/s × 0.04 s = 4 × 10⁶ bits = 500 kB. The sender's window must be at least this large.
Answer: H = 4094
IPv4 subnetting: an address has 32 bits. The prefix /p says how many leading bits identify the network; the remaining 32 − p bits number the hosts. A subnet has 2³²⁻ᵖ addresses, but the first (network address) and last (broadcast address) cannot be given to hosts, so 2³²⁻ᵖ − 2 hosts fit. Exceptions: a /31 (point-to-point link, RFC 3021) uses both of its 2 addresses for hosts, and a /32 is one single address (a single host or a loopback).
Answer: p = 21
Route summarisation: a summary route a.b.c.0/p covers all networks whose first p bits match. Write the differing octet of the first and last network in binary; the number of common leading bits, plus the bits of the octets before it, is the longest summary prefix.
Summary route: 10.104.104.0/21 (it also covers 5 network(s) that are not in the list).
ExamProblems · examproblems.com/courses/computer-science-fundamentals