














































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!















































Which statement best describes an algorithm? A. A programming language used to write software B. A physical component inside a computer C. ANSWER: A finite sequence of unambiguous instructions for solving a problem D. A collection of randomly selected test data Rationale: An algorithm is a precisely defined sequence of steps used to solve a problem or perform a computation. It should be sufficiently unambiguous that each step can be interpreted consistently. A programming language is used to implement an algorithm, but is not itself the definition of an algorithm.
A programmer wants to solve a problem by ignoring unnecessary details and concentrating only on the information relevant to the solution. Which computational-thinking technique is being used? A. Iteration B. Decomposition C. ANSWER: Abstraction D. Selection Rationale: Abstraction involves removing unnecessary detail so that the important features of a problem remain. Decomposition instead breaks a large problem into smaller manageable parts.
A problem is divided into several smaller problems, each of which can be solved independently. What technique is being applied? A. Abstraction B. ANSWER: Decomposition C. Encapsulation D. Compilation Rationale: Decomposition involves breaking a complex problem into smaller sub-problems. These sub- problems can then be designed, implemented and tested separately.
What are the final values of x and y? A. x = 4, y = 7 B. x = 2, y = 7 C. ANSWER: x = 7, y = 2 D. x = 2, y = 4 Rationale: x initially becomes 4. The statement x ← y copies the current value of y, which is 7, into x. Changing y afterwards to 2 does not change x.
What is the output?
total ← 0 FOR count ← 1 TO 4 total ← total + count NEXT count OUTPUT totalA. 4 B. 6 C. ANSWER: 10 D. 11 Rationale: The loop adds 1, 2, 3 and 4: 1 + 2 + 3 + 4 = 10.
What is the main purpose of iteration? A. To permanently remove variables B. ANSWER: To repeatedly execute a set of instructions C. To convert source code into machine code D. To store data permanently Rationale: Iteration allows a sequence of instructions to be repeated. Common forms include count-controlled loops and condition-controlled loops.
Rationale: The values are 3, 5, 7, 9 and finally 11. At 11, the condition x < 10 becomes false, so the loop terminates.
Which Boolean expression evaluates to TRUE? A. 5 < 2 B. 7 = 9 C. ANSWER: 8 >= 8 D. 4 > 10 Rationale: The >= operator means greater than or equal to. Since 8 is equal to 8, the expression is TRUE.
What does the Boolean operator AND require? A. At least one condition to be TRUE B. Neither condition to be TRUE C. ANSWER: Both conditions to be TRUE D. Exactly one condition to be TRUE
Rationale: An AND operation returns TRUE only when every operand is TRUE.
Which expression is equivalent to:
NOT (A AND B)A. NOT A AND NOT B B. ANSWER: NOT A OR NOT B C. A OR B D. A AND NOT B Rationale: This follows De Morgan's law: NOT(A AND B) = NOT A OR NOT B.
A program accepts a person's age. Which is most clearly a boundary value for an age restriction of 18 or over? A. 25
Rationale: The valid interval is 0 through 100 inclusive. Therefore 101 is outside the permitted range.
What is the purpose of validation? A. To prove that a program contains no logical errors B. ANSWER: To check that input satisfies specified requirements C. To translate source code D. To make an algorithm execute faster Rationale: Validation checks whether input is sensible and conforms to defined rules. It does not prove that the program itself is logically correct.
Which validation check would be appropriate for ensuring that a user enters a number between 1 and 50? A. Presence check B. Format check C. ANSWER: Range check D. Length check only
Rationale: A range check ensures that the input falls between specified minimum and maximum values.
What is the primary purpose of a dry run? A. To compile a program B. ANSWER: To manually execute an algorithm to determine its behaviour C. To encrypt source code D. To delete test data Rationale: A dry run follows an algorithm step by step, usually using a trace table, to determine what happens for selected input values.
Consider:
a ← 6 b ← 3 IF a > b THEN OUTPUT a ELSE If an array contains: ```text [14, 21, 8, 30]and indexing begins at 0, what is stored at index 2? A. 14 B. 21 C. ANSWER: 8 D. 30 Rationale: With zero-based indexing, index 0 contains 14, index 1 contains 21, index 2 contains 8, and index 3 contains 30.
What is the purpose of a stack? A. To guarantee alphabetical ordering B. ANSWER: To store items using a last-in-first-out principle C. To store items using random access only D. To ensure first-in-first-out processing Rationale: A stack operates using LIFO: Last In, First Out. The most recently added item is the first one removed.
A stack contains:
A, B, Cwhere C is at the top. If D is pushed and then one item is popped, which item is removed? A. A B. B C. C D. ANSWER: D Rationale: Pushing D places it on top of C. The next pop therefore removes D.
Which principle does a queue normally use? A. LIFO B. Random access C. ANSWER: FIFO D. FILO only
B. ANSWER: Push C. Pop D. Peek only Rationale: Push adds an item to the stack. Pop removes the top item.
Which operation normally removes an item from a queue? A. Push B. Pop C. ANSWER: Dequeue D. Insert-top Rationale: A queue uses enqueue to add an item and dequeue to remove an item.
Which algorithm is designed to locate a specific item by repeatedly dividing a sorted search area? A. Bubble sort B. Linear search C. ANSWER: Binary search D. Insertion sort
Rationale: Binary search examines the middle element and eliminates approximately half of the remaining search space after each comparison.
What condition must normally be satisfied before binary search can be used? A. The data must contain only integers B. The data must contain no duplicates C. ANSWER: The data must be sorted D. The data must contain exactly 100 items Rationale: Binary search relies on ordering to determine which half of the data can be discarded.
A sorted list contains 64 elements. Approximately how many comparisons are required in the worst case by binary search? A. 6 B. ANSWER: 7 C. 32 D. 64 Rationale:
What is the general worst-case complexity of binary search? A. O(n²) B. O(n) C. ANSWER: O(log n) D. O(2ⁿ) Rationale: Each binary-search comparison approximately halves the remaining search space, producing logarithmic growth.
Which sorting algorithm repeatedly compares adjacent elements and swaps them when they are in the wrong order? A. Insertion sort B. Merge sort C. ANSWER: Bubble sort D. Binary search Rationale: Bubble sort repeatedly compares neighbouring values. Larger or smaller values gradually move toward their correct positions through successive swaps.
What is the main effect of one complete pass through a typical ascending bubble sort? A. The smallest element is always placed at the beginning B. ANSWER: The largest unsorted element moves toward the end C. The entire list becomes sorted D. The middle element is removed Rationale: In ascending bubble sort, larger values move toward the right during a pass because adjacent out-of- order pairs are swapped.
Consider the list:
5, 2, 4After one left-to-right bubble-sort pass in ascending order, what is the result? A. 2, 4, 5 B. ANSWER: 2, 4, 5 C. 5, 4, 2 D. 4, 2, 5