A linear search algorithm is used to find the value 25 in the following list: [10, 5, 25, 40, 15].
Assuming the algorithm stops as soon as the item is found, how many comparisons are made?
Oxford AQA International A-level · Computer Science (9645)
解讀與撰寫演算法:練習題
5 條多項選擇題即時批改,另有 5 條文字題附完整解題步驟,全部圍繞「解讀與撰寫演算法」。
Which of the following statements accurately compares the worst-case time efficiency of Binary Search and Linear Search on a very large, sorted list containing \(n\) elements?
Hand-trace the following algorithm and determine the final value of B:A = 6B = 1REPEAT A = A - 2 B = B * 3UNTIL B > A
What is the defining characteristic of an algorithm according to the standard definition in computer science?
Consider the list [8, 3, 6, 1]. After the first complete pass of the bubble sort algorithm (starting from the left and comparing adjacent elements), what is the state of the list?
What is the fundamental characteristic of an algorithm, as defined in computer science?
先自己寫一次答案,再對照解題步驟。
Explain the primary purpose of hand-tracing an algorithm using a set of test data.
先自己寫一次答案,再對照解題步驟。
Explain the importance of using erroneous test data when hand-tracing an algorithm intended for a production environment.
先自己寫一次答案,再對照解題步驟。
Consider the following algorithm expressed in pseudocode:
START
X = 15
Y = 7
Z = 0
IF X > Y THEN
Z = X MOD Y
X = X DIV Y
ELSE
Z = Y - X
X = Y * 2
END IF
Y = Y + Z
OUTPUT X
OUTPUT Y
OUTPUT Z
END
Trace the execution of this algorithm, assuming standard integer arithmetic (DIV is integer division and MOD is the remainder), and state the final output values of X, Y, and Z.
先自己寫一次答案,再對照解題步驟。
The following pseudocode processes an array Items of integers. Assume Items = [10, 4, 1, 9, 6] and the array indices run from 1 to 5 (
=5).
FUNCTION ProcessList(Items, n)
1. Total = 0
2. FOR I = 1 TO n DO
3. Current = Items[I]
4. IF Current < 5 AND Current MOD 2 == 0 THEN
5. Total = Total + 1
6. ELSE IF Current >= 10 OR Current MOD 3 == 0 THEN
7. Total = Total + 2
8. ELSE
9. Total = Total + 0
10. END IF
11. END FOR
12. RETURN Total
Hand-trace the execution of ProcessList(Items, 5) and state the final value returned by the function.
先自己寫一次答案,再對照解題步驟。
* thinka提供的內容由AI生成,可能並非總是準確或最新。請將其用作輔助資源,並與官方材料進行核實。
想多做幾條同類題目?立即開始練習呢個課題,即做即批改。
立即練習