The following flowchart represents an algorithm that processes a positive integer. (a) Trace through the flowchart for N = 16, showing the value of N and Co...

Assessment: Computer Science 0478 | Paper 2 Mock 01 | Algorithms, Programming and Logic Subject: Computer Science - 0478

Question 1 Report

The following flowchart represents an algorithm that processes a positive integer.

diagram

(a) Trace through the flowchart for N = 16, showing the value of N and Count at each step. [4]

(b) State the output when N = 16. [1]

(c) State what this algorithm calculates for any given positive integer input. [2]

Answer Details

(a) The flowchart repeatedly divides N by 2 (integer division) and increments Count, stopping when N is no longer greater than 1:

IterationN (start)N > 1?N DIV 2Count
Initial16--0
116TRUE81
28TRUE42
34TRUE23
42TRUE14
Check1FALSE-4

Each iteration halves N and adds 1 to Count. After 4 iterations, N reaches 1 and the loop exits. [4]

(b) The output is 4. [1]

(c) The algorithm calculates how many times N can be halved (using integer division by 2) before reaching 1. [1] For inputs that are exact powers of 2, this gives the exponent, equivalent to log base 2 of N. For example, 16 = 24, so Count = 4. For non-powers of 2, integer division still counts the halvings, but the result is the floor of log2(N). [1] [2]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning