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

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

Điểm: 0/15

Question 1

Dễ · +10 điểm

[Part A · Easy] Compute the bitwise XOR of the two 6-bit binary numbers 110101 and 011011, then convert the resulting 6-bit binary number into decimal.

Chọn đáp án

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

Đáp án: $46$

Answer / Đáp án: 46

Step-by-step (EN): 110101 XOR 011011 $=$ 101110 (bits differ at positions with weights $32, 8, 4, 2$). Decimal value $= 32 + 0 + 8 + 4 + 2 + 0 = 46$.

Giải chi tiết (VI): Thực hiện XOR từng cột (khác nhau = 1, giống nhau = 0): 110101 $\oplus$ 011011 $=$ 101110. Đổi sang hệ thập phân: $32 + 8 + 4 + 2 = 46$.

Computational Thinking / Tư duy Máy tính: Bitwise Manipulation (Phép toán thao tác bit).

Question 2

Dễ · +10 điểm

[Part A · Easy] A smart greenhouse triggers an alarm when the condition NOT (Temp <= 30 AND Humidity >= 40) evaluates to True. By De Morgan's Law, which condition is logically equivalent?

Chọn đáp án

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

Đáp án: Temp > 30 OR Humidity < 40

Answer / Đáp án: Temp > 30 OR Humidity < 40

Step-by-step (EN): By De Morgan's Law, $\neg(P \land Q) \equiv (\neg P) \lor (\neg Q)$. Negating Temp <= 30 gives Temp > 30, and negating Humidity >= 40 gives Humidity < 40, joined by OR.

Giải chi tiết (VI): Theo luật De Morgan: $\neg(P \land Q) \equiv (\neg P) \lor (\neg Q)$. Phủ định của Temp <= 30 là Temp > 30, phủ định của Humidity >= 40 là Humidity < 40, nối với nhau bởi OR.

Computational Thinking / Tư duy Máy tính: Boolean Algebra & De Morgan's Laws (Đại số Boole & Luật De Morgan).

Question 3

Dễ · +10 điểm

[Part A · Easy] A hash table has $7$ buckets numbered $0$ to $6$, using hash function $h(x) = x \bmod 7$ with linear probing: if bucket $b$ is occupied, try $(b+1) \bmod 7, (b+2) \bmod 7, \dots$ until an empty bucket is found. Keys 10, 24, 17, 32 are inserted in that order into an initially empty table. Into which bucket index ($0$–$6$) is 17 placed?

Chọn đáp án

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

Đáp án: $5$

Answer / Đáp án: 5

Step-by-step (EN): 1) $10 \bmod 7 = 3 \to$ bucket 3. 2) $24 \bmod 7 = 3$ (occupied!) $\to$ probes bucket 4 (empty) $\to$ bucket 4. 3) $17 \bmod 7 = 3$ (occupied), bucket 4 (occupied) $\to$ lands in bucket 5!

Giải chi tiết (VI): 1) $10 \bmod 7 = 3 \to$ vào ô 3. 2) $24 \bmod 7 = 3$ (đã đầy) $\to$ dò sang ô 4 (trống) $\to$ vào ô 4. 3) $17 \bmod 7 = 3$ (đầy), dò ô 4 (đầy) $\to$ đặt vào ô 5!

Computational Thinking / Tư duy Máy tính: Hash Tables & Open Addressing / Linear Probing (Bảng băm & Xử lý đụng độ).

Question 4

Dễ · +10 điểm

[Part A · Easy] Stack S currently contains [4, 7, 2, 9] from bottom to top (9 is on top), and Queue Q is initially empty. We execute: 1. Pop $3$ elements one by one from S and enqueue each into Q. 2. Dequeue $2$ elements one by one from Q and push each back onto S.

Which number is now on the top of Stack S?

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

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

Đáp án: 2

Answer / Đáp án: 2

Step-by-step (EN): Step 1: Pop 9, 2, 7 from S $\implies$ S = [4], and Q (front $\to$ back) = [9, 2, 7]. Step 2: Dequeue 9 (push to S $\to$ [4, 9]), then dequeue 2 (push to S $\to$ [4, 9, 2]). Top of S is 2.

Giải chi tiết (VI): Bước 1: Pop lần lượt 9, 2, 7 khỏi S $\implies$ S còn [4], còn hàng đợi Q (từ đầu đến cuối) là [9, 2, 7]. Bước 2: Lấy 9 khỏi đầu Q đẩy vào S ([4, 9]), rồi lấy tiếp 2 đẩy vào S ([4, 9, 2]). Đỉnh của S hiện là 2.

Computational Thinking / Tư duy Máy tính: Interplay of LIFO Stacks and FIFO Queues (Kết hợp Ngăn xếp & Hàng đợi).

Question 5

Dễ · +10 điểm

[Part A · Easy] A complete binary tree has height $h = 4$ (Level $0$ has $1$ root node, Level $1$ has $2$ nodes, Level $2$ has $4$ nodes, Level $3$ has $8$ nodes, and Level $4$ has $16$ leaf nodes). How many nodes in total are in this tree?

Chọn đáp án

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

Đáp án: $31$

Answer / Đáp án: 31

Step-by-step (EN): Sum of geometric series: $1 + 2 + 4 + 8 + 16 = 2^5 - 1 = 31$ nodes.

Giải chi tiết (VI): Tổng số nút trên cả $5$ tầng là $1 + 2 + 4 + 8 + 16 = 2^5 - 1 = 31$ nút.

Computational Thinking / Tư duy Máy tính: Properties of Complete Binary Trees (Cấu trúc cây nhị phân đầy đủ).

Question 6

Trung bình · +20 điểm

[Part B · Medium] An archipelago connects $6$ data centers (A–F) with undersea fiber cables (costs in million USD shown on edges). What is the minimum total cost to select a subset of cables that connects all $6$ data centers?

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

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

Đáp án: $14$

Answer / Đáp án: 14

Step-by-step (EN): Sort edges by weight (Kruskal's MST, need $5$ edges): 1) B–D ($2$) 2) E–F ($2$) 3) A–D ($3$) 4) C–E ($3$) 5) Next weight-$4$ edges: A–B ($4$) forms cycle A–B–D (skip!); D–E ($4$) connects {A,B,D} with {C,E,F} (accept!). Total MST cost $= 2 + 2 + 3 + 3 + 4 = 14$.

Giải chi tiết (VI): Dùng thuật toán Kruskal chọn $5$ cạnh rẻ nhất không tạo chu trình: 1) B–D ($2$) 2) E–F ($2$) 3) A–D ($3$) 4) C–E ($3$) 5) Xét cạnh trọng số $4$: A–B tạo chu trình A-B-D nên bỏ qua; chọn D–E ($4$) nối thông hai cụm {A,B,D} và {C,E,F}. Tổng chi phí nhỏ nhất $= 2 + 2 + 3 + 3 + 4 = 14$.

Computational Thinking / Tư duy Máy tính: Cycle Detection & Minimum Spanning Trees (Phát hiện chu trình & Cây khung nhỏ nhất).

Question 7

Trung bình · +20 điểm

[Part B · Medium] In a genetics lab, we compare two DNA sequences S1 = "ACGTAC" and S2 = "AGTCA". A common subsequence is formed by deleting zero or more letters from each string without changing the relative order of the remaining letters. What is the length of the Longest Common Subsequence (LCS) of S1 and S2?

Chọn đáp án

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

Đáp án: $4$

Answer / Đáp án: 4

Step-by-step (EN): S2 has length $5$ (A G T C A). Can all $5$ appear in S1 = A C G T A C? After A, G, T (A _ G T _ _), only A C remains in S1, so we cannot match both C and then A! However, "AGTA" (A[1], G[3], T[4], A[5]) and "AGTC" (A[1], G[3], T[4], C[6]) both appear in S1 and S2 with length $4$.

Giải chi tiết (VI): Chuỗi S2 dài $5$ (A G T C A). Trong S1 = A C G T A C, sau khi khớp A, G, T thì phần đuôi của S1 chỉ còn A C (không thể có C đứng trước A), nên độ dài $5$ là bất khả thi. Ngược lại, dãy "AGTA" hoặc "AGTC" đều xuất hiện ở cả hai chuỗi với độ dài $4$.

Computational Thinking / Tư duy Máy tính: Longest Common Subsequence — Bioinformatics DP (Quy hoạch động Dãy con chung dài nhất).

Question 8

Trung bình · +20 điểm

[Part B · Medium] This 3-state automaton reads a binary number bit-by-bit from most significant bit to least significant bit (starting at R0). Every time a new bit $b \in \{0, 1\}$ is read, the value of the binary number becomes $2v + b$. What mathematical property holds for every binary number that finishes in accepting state R0?

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

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

Đáp án: Divisible by $3$

Answer / Đáp án: Divisible by $3$ (Chia hết cho $3$)

Step-by-step (EN): Check $(2r + b) \bmod 3$ for $r \in \{0, 1, 2\}$:

  • From R0 ($r=0$): bit 0 $\to 0$ (R0), bit 1 $\to 1$ (R1).
  • From R1 ($r=1$): bit 0 $\to 2$ (R2), bit 1 $\to 3 \equiv 0$ (R0).
  • From R2 ($r=2$): bit 0 $\to 4 \equiv 1$ (R1), bit 1 $\to 5 \equiv 2$ (R2).

State Rk tracks the exact remainder modulo $3$, so R0 accepts numbers divisible by $3$!

Giải chi tiết (VI): Kiểm tra phép chuyển số dư $(2r + b) \bmod 3$: từ R0 ($r=0$), đọc 0 ra $0$, đọc 1 ra $1$ (R1); từ R1 ($r=1$), đọc 0 ra $2$ (R2), đọc 1 ra $3 \equiv 0$ (R0); từ R2 ($r=2$), đọc 0 ra $4 \equiv 1$ (R1), đọc 1 ra $5 \equiv 2$ (R2). Vậy R0 chính là tập các số nhị phân chia hết cho $3$!

Computational Thinking / Tư duy Máy tính: Modular Arithmetic Automata (Ô-tô-mát kiểm tra chia hết).

Question 9

Trung bình · +20 điểm

[Part B · Medium] A vending system has unlimited coins of denominations $1$, $4$, and $6$ credits (note: there is NO $5$-credit coin!). A greedy algorithm that picks the largest possible coin first would pay $8$ credits as $6 + 1 + 1$ ($3$ coins), which is NOT optimal because $4 + 4$ uses only $2$ coins! What is the minimum number of coins needed to make exact change for $14$ credits?

Chọn đáp án

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

Đáp án: $3$

Answer / Đáp án: 3

Step-by-step (EN): Can $2$ coins reach $14$? Max sum of $2$ coins is $6 + 6 = 12 < 14$, so $2$ coins is impossible. With $3$ coins: $6 + 4 + 4 = 14$ (whereas greedy $6 + 6 + 1 + 1$ would take $4$ coins!). Minimum $= 3$.

Giải chi tiết (VI): Với $2$ đồng xu, tổng lớn nhất chỉ là $6 + 6 = 12 < 14$ nên không thể. Với $3$ đồng xu, ta có cách đổi $14 = 6 + 4 + 4$ (nếu tham lam lấy $6 + 6 + 1 + 1$ sẽ mất tới $4$ đồng!). Vậy số đồng ít nhất là $3$.

Computational Thinking / Tư duy Máy tính: Failure of Greedy vs. Dynamic Programming Coin Change (Phản ví dụ tham lam & Quy hoạch động đổi tiền).

Question 10

Trung bình · +20 điểm

[Part B · Medium] In a computer operating system, Process P1 currently holds Resource R1 and waits for R2, while Process P2 currently holds Resource R2 and waits for R1 (forming a directed cycle in the Resource-Allocation Graph). Neither process will release its held resource until it finishes. What is this system state called?

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

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

Đáp án: Deadlock

Answer / Đáp án: Deadlock (Khóa chết / Bế tắc)

Step-by-step (EN): A directed cycle of mutual resource waiting where no process can proceed or preempt resources is a classic Deadlock (Coffman circular-wait condition).

Giải chi tiết (VI): Chu trình chờ đợi vòng tròn giữa các tiến trình giữ tài nguyên độc quyền không thu hồi được chính là trạng thái Deadlock (Khóa chết / Bế tắc) kinh điển trong Hệ điều hành.

Computational Thinking / Tư duy Máy tính: Concurrency & Deadlock Detection via Cycle Finding (Đồng thời hóa & Phát hiện khóa chết).

Question 11

Khó · +30 điểm

[Part C · Hard] A deep-space transmitter protects 4-bit data (d1, d2, d3, d4) using the Hamming(7,4) code (p1, p2, d1, p3, d2, d3, d4) at bit positions $1..7$, where each parity check group must have an even number of 1s:

  • Check 1 (positions $1, 3, 5, 7$): $b_1 \oplus b_3 \oplus b_5 \oplus b_7 = 0$
  • Check 2 (positions $2, 3, 6, 7$): $b_2 \oplus b_3 \oplus b_6 \oplus b_7 = 0$
  • Check 3 (positions $4, 5, 6, 7$): $b_4 \oplus b_5 \oplus b_6 \oplus b_7 = 0$

Exactly 1 bit was flipped during transmission, and Earth receives 1 0 1 1 0 0 0 (positions $1..7$). Which bit position ($1$ to $7$) was corrupted?

Chọn đáp án

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

Đáp án: $6$

Answer / Đáp án: 6

Step-by-step (EN): For received bits $b_1..b_7 = 1, 0, 1, 1, 0, 0, 0$, compute the three parity syndromes:

  • $s_1 = b_1 \oplus b_3 \oplus b_5 \oplus b_7 = 1 \oplus 1 \oplus 0 \oplus 0 = 0$ (passes)
  • $s_2 = b_2 \oplus b_3 \oplus b_6 \oplus b_7 = 0 \oplus 1 \oplus 0 \oplus 0 = 1$ (fails!)
  • $s_3 = b_4 \oplus b_5 \oplus b_6 \oplus b_7 = 1 \oplus 0 \oplus 0 \oplus 0 = 1$ (fails!)

Only position $6$ belongs to Check 2 and Check 3 while NOT belonging to Check 1 (equivalently, binary $(s_3 s_2 s_1)_2 = (110)_2 = 6$). Flipping $b_6$ to 1 restores the valid codeword 1011010!

Giải chi tiết (VI): Tính bit kiểm tra của $3$ nhóm trên dãy nhận được 1 0 1 1 0 0 0:

  • Nhóm 1 ($1{,}3{,}5{,}7$): $1 \oplus 1 \oplus 0 \oplus 0 = 0$ (Đúng)
  • Nhóm 2 ($2{,}3{,}6{,}7$): $0 \oplus 1 \oplus 0 \oplus 0 = 1$ (Sai)
  • Nhóm 3 ($4{,}5{,}6{,}7$): $1 \oplus 0 \oplus 0 \oplus 0 = 1$ (Sai).

Bit bị lỗi phải thuộc Nhóm 2 và Nhóm 3 nhưng không thuộc Nhóm 1 — đó chính là vị trí $6$ (hoặc đọc số nhị phân $(s_3 s_2 s_1)_2 = 110_2 = 6$).

Computational Thinking / Tư duy Máy tính: Error-Correcting Codes — Hamming(7,4) Syndrome Decoding (Mã tự sửa lỗi Hamming).

Question 12

Khó · +30 điểm

[Part C · Hard] A trading bot analyzes daily profit changes over $8$ consecutive days: [-3, 5, -2, 6, -1, 4, -8, 5]. Using Kadane's Maximum Subarray idea, what is the maximum possible total profit over any contiguous block of consecutive days?

Chọn đáp án

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

Đáp án: $12$

Answer / Đáp án: 12

Step-by-step (EN): Run Kadane's scan (cur = max(x, cur + x)):

  • -3: cur = -3, best = -3
  • 5: cur = 5, best = 5
  • -2: cur = 3, best = 5
  • 6: cur = 9, best = 9
  • -1: cur = 8, best = 9
  • 4: cur = 12, best = 12 (subarray [5, -2, 6, -1, 4])
  • -8: cur = 4, best = 12
  • 5: cur = 9, best = 12.

Maximum contiguous sum $= 12$.

Giải chi tiết (VI): Duyệt theo thuật toán Kadane (cur = max(x, cur + x)): đoạn liên tiếp từ ngày thứ $2$ đến ngày thứ $6$ là [5, -2, 6, -1, 4] cho tổng lớn nhất $5 - 2 + 6 - 1 + 4 = 12$ (sau đó cộng -8 giảm xuống 4, cộng tiếp 5 chỉ lên 9). Đáp số: $12$.

Computational Thinking / Tư duy Máy tính: Kadane's $O(N)$ Maximum Subarray Algorithm (Quy hoạch động đoạn con có tổng lớn nhất).

Question 13

Khó · +30 điểm

[Part C · Hard] Six files have sizes 5, 7, 10, 13, 18, 25 MB. Merging any two files of sizes $x$ and $y$ into a single file costs $x + y$ I/O operations. We want to merge all $6$ files into one single archive file using $5$ pairwise merges. What is the minimum total I/O cost?

Chọn đáp án

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

Đáp án: $190$

Answer / Đáp án: 190

Step-by-step (EN): By Optimal Merge Pattern (Huffman's greedy min-heap rule), always merge the two smallest current files: 1) $5 + 7 = 12$ $\to$ {10, 12, 13, 18, 25} 2) $10 + 12 = 22$ $\to$ {13, 18, 22, 25} 3) $13 + 18 = 31$ $\to$ {22, 25, 31} 4) $22 + 25 = 47$ $\to$ {31, 47} 5) $31 + 47 = 78$ $\to$ {78}. Total I/O cost $= 12 + 22 + 31 + 47 + 78 = 190$.

Giải chi tiết (VI): Theo thuật toán Gộp tệp tối ưu (cây Huffman / hàng đợi ưu tiên cực tiểu), ở mỗi bước luôn chọn gộp $2$ tệp nhỏ nhất hiện có: 1) $5 + 7 = 12$ $\to$ {10, 12, 13, 18, 25} 2) $10 + 12 = 22$ $\to$ {13, 18, 22, 25} 3) $13 + 18 = 31$ $\to$ {22, 25, 31} 4) $22 + 25 = 47$ $\to$ {31, 47} 5) $31 + 47 = 78$. Tổng chi phí nhỏ nhất $= 12 + 22 + 31 + 47 + 78 = 190$.

Computational Thinking / Tư duy Máy tính: Optimal Merge Pattern & Min-Priority Queues (Gộp tệp tối ưu bằng Heap cực tiểu).

Question 14

Khó · +30 điểm

[Part C · Hard] Given the sequence of $8$ integers [4, 2, 5, 3, 7, 6, 9, 8], what is the length of its Longest Strictly Increasing Subsequence (LIS) (elements need not be contiguous, but must keep their left-to-right order and strictly increase)?

Chọn đáp án

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

Đáp án: $4$

Answer / Đáp án: 4

Step-by-step (EN): Compute dp[i] = LIS ending at element $i$:

  • 4: 1
  • 2: 1
  • 5: 2 (2, 5 or 4, 5)
  • 3: 2 (2, 3)
  • 7: 3 (2, 5, 7 or 2, 3, 7)
  • 6: 3 (2, 5, 6)
  • 9: 4 (2, 5, 7, 9 or 2, 5, 6, 9)
  • 8: 4 (2, 5, 7, 8).

Maximum length $= 4$.

Giải chi tiết (VI): Tính dp[i] là độ dài dãy con tăng dài nhất kết thúc tại phần tử thứ $i$: lần lượt được [1, 1, 2, 2, 3, 3, 4, 4] (ví dụ dãy 2, 5, 7, 9 hoặc 2, 3, 6, 8). Không thể có độ dài $5$ vì mỗi cặp nghịch thế liên tiếp (4,2), (5,3), (7,6), (9,8) chỉ chọn được tối đa $1$ số! Vậy đáp số là $4$.

Computational Thinking / Tư duy Máy tính: Longest Increasing Subsequence & Dilworth's Decomposition (Quy hoạch động LIS & Định lý Dilworth).

Question 15

Khó · +30 điểm

[Part C · Hard] A network graph $G$ is bipartite (2-colorable) if its vertices can be colored Red and Blue so every edge connects a Red vertex to a Blue vertex. Which structural condition is necessary and sufficient for a graph $G$ to be bipartite?

Chọn đáp án

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

Đáp án: $G$ contains no cycles of odd length

Answer / Đáp án: $G$ contains no cycles of odd length ($G$ không chứa chu trình độ dài lẻ)

Step-by-step (EN): Alternating colors along any cycle requires an even number of steps to return to the starting color; conversely, BFS 2-coloring succeeds on every connected component whenever there is no odd-length cycle ($C_3, C_5, C_7, \dots$).

Giải chi tiết (VI): Khi đi dọc một chu trình và đổi màu luân phiên Đỏ – Xanh, ta chỉ quay lại đúng màu ban đầu nếu chu trình có độ dài chẵn. Ngược lại, nếu đồ thị không có chu trình lẻ ($C_3, C_5, \dots$), thuật toán duyệt chiều rộng BFS luôn tô $2$ màu thành công.

Computational Thinking / Tư duy Máy tính: Bipartite Graphs & König's Odd-Cycle Theorem (Đồ thị hai phía & Kiểm tra 2-màu bằng BFS).

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.