Ngân hàng đề / Luyện thi phong cách Bebras

Bebras Practice · Cấp độ 6 / Level 6 (Song ngữ Anh–Việt · Lớp 11–12 · 15 câu)

Điểm: 0/15

Question 1

Dễ · +10 điểm

[Part A · Easy] In $8$-bit Two's Complement representation of signed integers, the leftmost bit has negative weight $-128$, and the remaining $7$ bits have positive weights $+64, +32, +16, +8, +4, +2, +1$. What absolute value $|x|$ does the negative 8-bit register 11101011 represent? (Enter the positive magnitude $|x|$, e.g. enter 5 if $x = -5$)

Hình minh họa câu 1
Chọn đáp án

Xem đáp án và lời giải

Đáp án: $21$

Answer / Đáp án: 21

Step-by-step (EN): Method 1 (weights): $x = -128 + 64 + 32 + 0 + 8 + 0 + 2 + 1 = -128 + 107 = -21 \implies |x| = 21$. Method 2 (invert bits + 1): ~11101011 + 1 = 00010100 + 1 = 00010101 $= 16 + 4 + 1 = 21$.

Giải chi tiết (VI): Cách 1 (cộng trọng số): $x = -128 + (64 + 32 + 8 + 2 + 1) = -128 + 107 = -21 \implies |x| = 21$. Cách 2 (đảo bit cộng $1$): đảo 11101011 được 00010100, cộng $1$ được 00010101 $= 16 + 4 + 1 = 21$.

Computational Thinking / Tư duy Máy tính: Two's Complement Signed Arithmetic (Biểu diễn số nguyên có dấu Bù 2 trong kiến trúc máy tính).

Question 2

Dễ · +10 điểm

[Part A · Easy] A divide-and-conquer sorting algorithm splits an array of size $N$ into $2$ halves of size $N/2$, recursively sorts both halves, and merges them in $O(N)$ linear operations: $$T(N) = 2T(N/2) + cN.$$ What is the asymptotic time complexity $T(N)$?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $O(N \log N)$

Answer / Đáp án: $O(N \log N)$

Step-by-step (EN): The recursion tree has $\log_2 N$ levels, and each level performs $2^k \cdot c(N / 2^k) = cN$ merge operations. Multiplying work per level by number of levels gives $O(N \log N)$ (Master Theorem Case 2 / Merge Sort).

Giải chi tiết (VI): Cây đệ quy có chiều cao $\log_2 N$ tầng, tại mỗi tầng tổng chi phí trộn các mảng con luôn bằng $2^k \cdot c(N/2^k) = cN$. Nhân số tầng với chi phí mỗi tầng thu được độ phức tạp $O(N \log N)$ (thuật toán Merge Sort).

Computational Thinking / Tư duy Máy tính: Divide-and-Conquer Recurrences & Master Theorem (Đệ quy Chia để trị & Định lý Thợ).

Question 3

Dễ · +10 điểm

[Part A · Easy] In Diffie–Hellman / RSA public-key cryptography, we compute modular powers using Binary Exponentiation (Square-and-Multiply). What is the remainder when $3^{13}$ is divided by $17$?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $12$

Answer / Đáp án: 12

Step-by-step (EN): Write $13 = (1101)_2 = 8 + 4 + 1$ and compute squares modulo $17$:

  • $3^1 \equiv 3 \pmod{17}$
  • $3^2 \equiv 9 \pmod{17}$
  • $3^4 \equiv 9^2 = 81 \equiv 13 \equiv -4 \pmod{17}$
  • $3^8 \equiv (-4)^2 = 16 \equiv -1 \pmod{17}$.

Multiply: $3^{13} = 3^8 \cdot 3^4 \cdot 3^1 \equiv (-1) \cdot (-4) \cdot 3 = 12 \pmod{17}$.

Giải chi tiết (VI): Phân tích nhị phân $13 = 8 + 4 + 1$ và bình phương liên tiếp theo $\bmod\ 17$:

  • $3^1 \equiv 3$
  • $3^2 \equiv 9$
  • $3^4 \equiv 81 \equiv -4 \pmod{17}$
  • $3^8 \equiv (-4)^2 = 16 \equiv -1 \pmod{17}$.

Suy ra $3^{13} = 3^8 \cdot 3^4 \cdot 3^1 \equiv (-1)(-4)(3) = 12 \pmod{17}$.

Computational Thinking / Tư duy Máy tính: Fast Modular Exponentiation in Cryptography (Lũy thừa nhanh theo modulo).

Question 4

Dễ · +10 điểm

[Part A · Easy] An expression tree represents (7 + 3) * (9 - 4) with * at the root, + as left child (7, 3), and - as right child (9, 4). What sequence of tokens is produced by a Pre-order traversal (Root -> Left -> Right) of this expression tree?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: * + 7 3 - 9 4

Answer / Đáp án: * + 7 3 - 9 4

Step-by-step (EN): Visit Root (*), then recursively traverse Left subtree (+, then 7, then 3), then Right subtree (-, then 9, then 4), yielding Polish prefix notation * + 7 3 - 9 4.

Giải chi tiết (VI): Thăm Gốc (*), tiếp theo duyệt Tiền thứ tự cây con trái (+ 7 3), rồi duyệt Tiền thứ tự cây con phải (- 9 4), thu được ký pháp Ba Lan tiền tố * + 7 3 - 9 4.

Computational Thinking / Tư duy Máy tính: Abstract Syntax Trees & Tree Traversals (Cây cú pháp trừu tượng & Duyệt cây).

Question 5

Dễ · +10 điểm

[Part A · Easy] A Bloom filter uses an $8$-bit array B[0..7] initialized to 00000000 and two hash functions $h_1(x) = x \bmod 8$ and $h_2(x) = (3x + 1) \bmod 8$. Inserting key $x$ sets both B[h1(x)] = 1 and B[h2(x)] = 1. After inserting x = 2 and x = 7, how many bits in B[0..7] are equal to 1?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $3$

Answer / Đáp án: 3

Step-by-step (EN): - For $x = 2$: $h_1(2) = 2$, $h_2(2) = (6+1) \bmod 8 = 7 \to$ sets bits {2, 7}.

  • For $x = 7$: $h_1(7) = 7$ (already 1!), $h_2(7) = (21+1) \bmod 8 = 6 \to$ sets bits {6, 7}.

Distinct set bits: {2, 6, 7}, so $3$ bits equal 1.

Giải chi tiết (VI): - Với $x = 2$: $h_1(2) = 2$, $h_2(2) = 7 \to$ bật các ô {2, 7}.

  • Với $x = 7$: $h_1(7) = 7$ (trùng ô 7 đã bật!), $h_2(7) = 22 \bmod 8 = 6 \to$ bật {6, 7}.

Hợp lại có các vị trí {2, 6, 7}, tức đúng $3$ bit bằng 1.

Computational Thinking / Tư duy Máy tính: Probabilistic Data Structures — Bloom Filters (Cấu trúc dữ liệu xác suất Bloom Filter).

Question 6

Trung bình · +20 điểm

[Part B · Medium] A cloud network pipes data from source S to sink T. Each arrow shows the maximum bandwidth capacity (in Gbps) of that one-way link. What is the Maximum Flow (in Gbps) that can be sent simultaneously from S to T?

Hình minh họa câu 6
Chọn đáp án

Xem đáp án và lời giải

Đáp án: $15$

Answer / Đáp án: 15

Step-by-step (EN): Verify via the Max-Flow Min-Cut Theorem:

  • Send $6\text{ Gbps}$ along S -> A -> C -> T.
  • Send $2\text{ Gbps}$ along S -> A -> B -> D -> C -> T (C->T is now saturated at $6+2=8$, B->D uses $2$).
  • Send $7\text{ Gbps}$ along S -> B -> D -> T (D->T is saturated at $7$, B->D is saturated at $2+7=9$).

Total flow $= 6 + 2 + 7 = 15\text{ Gbps}$. Now check the cut $X = \{S, A, B, D\}$, $Y = \{C, T\}$: edges crossing $X \to Y$ are A->C ($6$), D->C ($2$), and D->T ($7$), whose capacity sum is $6 + 2 + 7 = 15$! Since flow $=$ cut capacity, $15$ is strictly optimal.

Giải chi tiết (VI): Áp dụng Định lý Luồng cực đại – Lát cắt cực tiểu (Max-Flow Min-Cut):

  • Đẩy $6\text{ Gbps}$ theo S -> A -> C -> T.
  • Đẩy $2\text{ Gbps}$ theo S -> A -> B -> D -> C -> T.
  • Đẩy $7\text{ Gbps}$ theo S -> B -> D -> T.

Tổng luồng đạt $6 + 2 + 7 = 15\text{ Gbps}$. Kiểm tra lát cắt $X = \{S, A, B, D\}$ sang $Y = \{C, T\}$ gồm đúng $3$ cạnh đi qua là A->C ($6$), D->C ($2$) và D->T ($7$) có tổng dung lượng $6 + 2 + 7 = 15$. Vậy luồng cực đại chính xác bằng $15$.

Computational Thinking / Tư duy Máy tính: Network Flow & Ford–Fulkerson / Max-Flow Min-Cut Theorem (Luồng cực đại trên mạng).

Question 7

Trung bình · +20 điểm

[Part B · Medium] The Levenshtein (Edit) Distance between two strings is the minimum number of single-character edits (insert, delete, or substitute 1 letter) needed to transform one string into the other. What is the edit distance between "KITTEN" and "SITTING"?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $3$

Answer / Đáp án: 3

Step-by-step (EN): 1) Substitute K -> S: "SITTEN" 2) Substitute E -> I: "SITTIN" 3) Insert G at the end: "SITTING" ($3$ edits). Since the length increases by $1$ (requiring at least $1$ insertion) and aligned prefix characters differ in at least $2$ positions (K != S and E != I), fewer than $3$ edits is impossible.

Giải chi tiết (VI): Ta cần ít nhất $3$ phép biến đổi: 1) Thay K -> S: "SITTEN" 2) Thay E -> I: "SITTIN" 3) Chèn G vào cuối: "SITTING". Do độ dài tăng từ $6$ lên $7$ (tốn ít nhất $1$ phép chèn) và có ít nhất $2$ vị trí ký tự lệch nhau (K/S, E/I), không thể ít hơn $3$ bước.

Computational Thinking / Tư duy Máy tính: Edit Distance / Approximate String Matching DP (Quy hoạch động khoảng cách xâu Levenshtein).

Question 8

Trung bình · +20 điểm

[Part B · Medium] Five university courses (C1–C5) have prerequisite arrows X -> Y (meaning X must be taken before Y; ignore the 1m badge). A student takes $1$ course per term. Which of the following is a valid Topological Ordering of all $5$ courses?

Hình minh họa câu 8
Chọn đáp án

Xem đáp án và lời giải

Đáp án: C2, C1, C3, C4, C5

Answer / Đáp án: C2, C1, C3, C4, C5

Step-by-step (EN): Check all prerequisites:

  • C3 requires both C1 and C2 $\implies$ {C1, C2} must appear before C3 (eliminates options 2 and 4).
  • C4 requires both C2 and C3 (C3 -> C4!) $\implies$ C3 must appear before C4 (eliminates option 3).

Only C2, C1, C3, C4, C5 satisfies every arrow!

Giải chi tiết (VI): Kiểm tra các mũi tên tiên quyết:

  • C3 cần cả C1 và C2 đứng trước (loại phương án 2 và 4).
  • Có mũi tên C3 -> C4 nên C3 bắt buộc phải học trước C4 (loại phương án 3).

Vậy chỉ có C2, C1, C3, C4, C5 thỏa mãn mọi ràng buộc.

Computational Thinking / Tư duy Máy tính: Topological Sort on Directed Acyclic Graphs (Sắp xếp Tô-pô trên đồ thị không chu trình).

Question 9

Trung bình · +20 điểm

[Part B · Medium] How many structurally distinct Binary Search Trees (BSTs) can store the $4$ keys {1, 2, 3, 4}?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $14$

Answer / Đáp án: 14

Step-by-step (EN): The number of BSTs on $n$ keys is the $n$-th Catalan number $C_n = \dfrac{1}{n+1}\binom{2n}{n}$ (with $C_0=1, C_1=1, C_2=2, C_3=5$): $$C_4 = C_0 C_3 + C_1 C_2 + C_2 C_1 + C_3 C_0 = 5 + 2 + 2 + 5 = 14.$$

Giải chi tiết (VI): Số cây BST phân biệt trên $n$ khóa chính là số Catalan thứ $n$: với $C_0=1, C_1=1, C_2=2, C_3=5$, chọn lần lượt gốc $r \in \{1, 2, 3, 4\}$ ta có: $$C_4 = C_0 C_3 + C_1 C_2 + C_2 C_1 + C_3 C_0 = 5 + 2 + 2 + 5 = 14.$$

Computational Thinking / Tư duy Máy tính: Catalan Numbers & Recursive Tree Enumeration (Số Catalan đếm cấu trúc cây nhị phân).

Question 10

Trung bình · +20 điểm

[Part B · Medium] In this directed graph with a negative edge weight (A -> B has weight $-4$, representing an energy regeneration downhill slope), standard non-revisiting Dijkstra's algorithm greedily finalizes the vertex with smallest tentative distance first. What happens when standard Dijkstra runs from S?

Hình minh họa câu 10
Chọn đáp án

Xem đáp án và lời giải

Đáp án: Dijkstra finalizes B too early with distance $2$ and outputs suboptimal d(T) = 5 instead of optimal $4$

Answer / Đáp án: Dijkstra finalizes B too early with distance $2$ and outputs suboptimal d(T) = 5 instead of optimal $4$

Step-by-step (EN): From S, tentative distances are d(B) = 2 and d(A) = 5. Standard Dijkstra permanently closes B at $2$ and relaxes B -> T to $2 + 3 = 5$, then closes T at $5$ (or later relaxes A -> B to $5 - 4 = 1$, after B was already finalized!), missing the true shortest path S -> A -> B -> T of cost $5 - 4 + 3 = 4$ (which Bellman–Ford finds!).

Giải chi tiết (VI): Từ S, nhãn ban đầu là d(B) = 2, d(A) = 5. Dijkstra chuẩn chốt cứng B với giá trị $2$ rồi chốt T ở $2 + 3 = 5$, bỏ lỡ đường đi thực sự ngắn hơn là S -> A -> B -> T có chi phí $5 + (-4) + 3 = 4$ (cần dùng Bellman–Ford khi có cạnh âm).

Computational Thinking / Tư duy Máy tính: Algorithmic Preconditions: Dijkstra vs. Bellman–Ford (Điều kiện đúng đắn của thuật toán).

Question 11

Khó · +30 điểm

[Part C · Hard] In the Knuth–Morris–Pratt (KMP) string-matching algorithm, the prefix array $\pi[i]$ stores the length of the longest proper prefix of P[0..i] that is also a suffix of P[0..i] (proper means strictly shorter than P[0..i]). For pattern P = "ABABACA" ($7$ characters, $0$-indexed $i = 0..6$), compute the sum $\pi[0] + \pi[1] + \pi[2] + \pi[3] + \pi[4] + \pi[5] + \pi[6]$.

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $7$

Answer / Đáp án: 7

Step-by-step (EN): Compute $\pi[i]$ for each prefix of "ABABACA":

  • i=0 ("A"): $0$
  • i=1 ("AB"): $0$
  • i=2 ("ABA"): $1$ ("A")
  • i=3 ("ABAB"): $2$ ("AB")
  • i=4 ("ABABA"): $3$ ("ABA")
  • i=5 ("ABABAC"): $0$
  • i=6 ("ABABACA"): $1$ ("A").

Sum $= 0 + 0 + 1 + 2 + 3 + 0 + 1 = 7$.

Giải chi tiết (VI): Tính lần lượt $\pi[i]$ cho từng tiền tố của "ABABACA":

  • "A" $\to 0$; "AB" $\to 0$; "ABA" $\to 1$ ("A"); "ABAB" $\to 2$ ("AB"); "ABABA" $\to 3$ ("ABA"); "ABABAC" $\to 0$; "ABABACA" $\to 1$ ("A").

Tổng các phần tử là $0 + 0 + 1 + 2 + 3 + 0 + 1 = 7$.

Computational Thinking / Tư duy Máy tính: KMP Prefix Automaton / Failure Function (Hàm thất bại trong so khớp xâu tuyến tính KMP).

Question 12

Khó · +30 điểm

[Part C · Hard] In a directed web-link graph, a Strongly Connected Component (SCC) is a maximal set of pages where every page in the set can reach every other page in the set via directed links (a single page with no cycle is an SCC of size $1$). How many SCCs decompose the $7$-page directed graph shown?

Hình minh họa câu 12
Chọn đáp án

Xem đáp án và lời giải

Đáp án: $3$

Answer / Đáp án: 3

Step-by-step (EN): Identify directed cycles and cross-component bridges (Tarjan's / Kosaraju's algorithm): 1) {1, 4, 5} form a directed cycle 1 -> 4 -> 5 -> 1. 2) {2, 3, 6} form a directed cycle 2 -> 3 -> 6 -> 2. Edges 1 -> 2 and 5 -> 6 go strictly one-way from {1, 4, 5} into {2, 3, 6} with no return edge. 3) {7} only has incoming edge 6 -> 7 and out-degree $0$. Hence there are exactly $3$ SCCs: {1, 4, 5}, {2, 3, 6}, and {7}.

Giải chi tiết (VI): Phân tích theo thuật toán Kosaraju / Tarjan: 1) Cụm {1, 4, 5} tạo chu trình khép kín 1 -> 4 -> 5 -> 1. 2) Cụm {2, 3, 6} tạo chu trình khép kín 2 -> 3 -> 6 -> 2 (các cạnh 1 -> 2 và 5 -> 6 chỉ đi một chiều từ cụm 1 sang cụm 2, không có chiều ngược lại). 3) Đỉnh {7} không có cạnh đi ra nên đứng riêng $1$ thành phần. Vậy đồ thị có đúng $3$ SCC.

Computational Thinking / Tư duy Máy tính: Strongly Connected Components — Tarjan / Kosaraju Decomposition (Phân rã thành phần liên thông mạnh).

Question 13

Khó · +30 điểm

[Part C · Hard] Consider the 2-SAT Boolean formula with $4$ variables $(x_1, x_2, x_3, x_4) \in \{\text{True}, \text{False}\}^4$: $$(x_1 \lor x_2) \land (\neg x_1 \lor x_3) \land (\neg x_2 \lor x_3) \land (\neg x_3 \lor x_4) \land (\neg x_4 \lor \neg x_3).$$ How many truth assignments $(x_1, x_2, x_3, x_4)$ satisfy the entire formula?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $0$ (Unsatisfiable)

Answer / Đáp án: $0$ (Unsatisfiable / Vô nghiệm)

Step-by-step (EN): Convert clauses $A \lor B \equiv (\neg A \Rightarrow B)$: 1) Last two clauses $(\neg x_3 \lor x_4) \land (\neg x_4 \lor \neg x_3)$ give $x_3 \Rightarrow x_4 \Rightarrow \neg x_3$, forcing $x_3 = \text{False}$. 2) With $x_3 = \text{False}$, clauses $(\neg x_1 \lor x_3)$ and $(\neg x_2 \lor x_3)$ force $x_1 = \text{False}$ and $x_2 = \text{False}$. 3) That violates the first clause $(x_1 \lor x_2)$! Hence $0$ satisfying assignments.

Giải chi tiết (VI): Biến đổi về kéo theo logic: 1) Hai mệnh đề cuối $(\neg x_3 \lor x_4)$ và $(\neg x_4 \lor \neg x_3)$ kéo theo $x_3 \Rightarrow x_4 \Rightarrow \neg x_3$, buộc $x_3 = \text{Sai}$. 2) Thay $x_3 = \text{Sai}$ vào $(\neg x_1 \lor x_3)$ và $(\neg x_2 \lor x_3)$ buộc cả $x_1 = \text{Sai}$ và $x_2 = \text{Sai}$. 3) Khi đó mệnh đề đầu $(x_1 \lor x_2)$ bị Sai! Vậy có $0$ bộ nghiệm thỏa mãn.

Computational Thinking / Tư duy Máy tính: 2-SAT Implication Graphs & Unit Propagation (Đồ thị suy diễn 2-SAT).

Question 14

Khó · +30 điểm

[Part C · Hard] To multiply three matrices $M_1$ ($10 \times 30$), $M_2$ ($30 \times 5$), and $M_3$ ($5 \times 60$), multiplying a $p \times q$ matrix by a $q \times r$ matrix requires $p \cdot q \cdot r$ scalar multiplications. What is the minimum number of scalar multiplications needed to compute the product $M_1 M_2 M_3$ by choosing the optimal parenthesization?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $4500$

Answer / Đáp án: 4500

Step-by-step (EN): Compare both parenthesizations:

  • $((M_1 M_2) M_3)$: $(M_1 M_2)$ takes $10 \times 30 \times 5 = 1{,}500$ ops and yields a $10 \times 5$ matrix; multiplying by $M_3$ ($5 \times 60$) takes $10 \times 5 \times 60 = 3{,}000$ ops. Total $= 1{,}500 + 3{,}000 = 4{,}500$.
  • $(M_1 (M_2 M_3))$: $(M_2 M_3)$ takes $30 \times 5 \times 60 = 9{,}000$ ops and yields a $30 \times 60$ matrix; multiplying $M_1$ ($10 \times 30$) by it takes $10 \times 30 \times 60 = 18{,}000$ ops. Total $= 27{,}000$ ($6\times$ slower!).

Optimal cost $= 4{,}500$.

Giải chi tiết (VI): So sánh hai cách kết hợp dấu ngoặc:

  • Cách 1: $((M_1 M_2) M_3)$ tốn $10 \times 30 \times 5 + 10 \times 5 \times 60 = 1.500 + 3.000 = 4.500$ phép nhân.
  • Cách 2: $(M_1 (M_2 M_3))$ tốn $30 \times 5 \times 60 + 10 \times 30 \times 60 = 9.000 + 18.000 = 27.000$ phép nhân (chậm gấp $6$ lần!).

Vậy số phép nhân ít nhất là $4500$.

Computational Thinking / Tư duy Máy tính: Matrix Chain Multiplication DP (Quy hoạch động nhân chuỗi ma trận).

Question 15

Khó · +30 điểm

[Part C · Hard] In the Byzantine Generals Problem, $n$ distributed servers communicate via point-to-point messages to reach strict consensus, even if up to $f$ servers are Byzantine faulty (they may lie, collude, and send contradictory messages to different peers, without cryptographic signatures). According to Lamport, Shostak, and Pease's Theorem, what is the minimum total number of servers $n$ required to tolerate $f = 2$ Byzantine traitors?

Chọn đáp án

Xem đáp án và lời giải

Đáp án: $n = 7$

Answer / Đáp án: $n = 7$

Step-by-step (EN): Byzantine Fault Tolerance (BFT) without digital signatures requires strictly more than two-thirds honest nodes: $$n \geqslant 3f + 1.$$ For $f = 2$, the minimum number of servers is $n = 3(2) + 1 = 7$.

Giải chi tiết (VI): Để đạt đồng thuận chịu lỗi Byzantine (BFT), tổng số nút phải lớn hơn $3$ lần số nút lỗi: $$n \geqslant 3f + 1.$$ Với $f = 2$, số máy chủ tối thiểu cần có là $n = 3 \times 2 + 1 = 7$.

Computational Thinking / Tư duy Máy tính: Distributed Consensus & Byzantine Fault Tolerance $3f + 1$ (Đồng thuận phân tán & Chịu lỗi Byzantine).

Cài đặt ứng dụng O₂ Education

Thêm O₂ Education vào Màn hình chính trên iPhone / iPad để học nhanh như ứng dụng gốc:

  1. Nhấn biểu tượng Chia sẻ trên thanh công cụ Safari.
  2. Cuộn xuống và chọn Thêm vào MH chính (Add to Home Screen).
  3. Nhấn Thêm ở góc trên bên phải để hoàn tất.