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)
Following and writing algorithms:练习题
5 道选择题即时批改,另有 5 道文字题附完整解题步骤,全部围绕「Following and writing algorithms」。
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生成,可能并非总是准确或最新。请将其用作辅助资源,并与官方材料进行核实。
想多做几道同类题目?立即开始练习这个课题,边做边批改。
立即练习