Docsity

# AS-LEVEL COMPUTER SCIENCE ## H046/02 — ALGORITHMS AND PROBLEM SOLVING ## PRACTICE EXAM Q, Exams of Nursing

Toggle sidebar
bg1
# AS-LEVEL COMPUTER SCIENCE
## H046/02 — ALGORITHMS AND
PROBLEM SOLVING
## PRACTICE EXAM QUESTIONS
WITH CORRECT ANSWERS
### Question 1
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.
---
### Question 2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36

Partial preview of the text

Download # AS-LEVEL COMPUTER SCIENCE ## H046/02 — ALGORITHMS AND PROBLEM SOLVING ## PRACTICE EXAM Q and more Exams Nursing in PDF only on Docsity!

# AS-LEVEL COMPUTER SCIENCE

## H046/02 — ALGORITHMS AND

PROBLEM SOLVING

## PRACTICE EXAM QUESTIONS

WITH CORRECT ANSWERS

Question 1

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.

Question 2

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.

Question 3

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.

Question 4

x ← 4 y ← 7 x ← y y ← 2

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.

Question 7

What is the output?

total ← 0 FOR count ← 1 TO 4 total ← total + count NEXT count OUTPUT total

A. 4 B. 6 C. ANSWER: 10 D. 11 Rationale: The loop adds 1, 2, 3 and 4: 1 + 2 + 3 + 4 = 10.

Question 8

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.

Question 9

D. 12

Rationale: The values are 3, 5, 7, 9 and finally 11. At 11, the condition x < 10 becomes false, so the loop terminates.

Question 11

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.

Question 12

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.

Question 13

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.

Question 14

A program accepts a person's age. Which is most clearly a boundary value for an age restriction of 18 or over? A. 25

D. ANSWER: 101

Rationale: The valid interval is 0 through 100 inclusive. Therefore 101 is outside the permitted range.

Question 17

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.

Question 18

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.

Question 19

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.

Question 20

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.

Question 23

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.

Question 24

A stack contains:

A, B, C

where 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.

Question 25

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.

Question 28

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.

Question 29

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.

Question 30

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.

Question 31

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:

Question 34

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.

Question 35

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.

Question 36

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.

Question 37

Consider the list:

5, 2, 4

After 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