IB Computer Science SL study materials
IB Computer Science SL study resources

IB Computer Science SL practice questions

One question at a time. Build your IB Computer Science SL understanding.

First 50 of 200 questions. Each one lists the choices, the correct answer, and an explanation. The checker at the top of this page saves progress in this browser when it is available.

Continue in the practice tool above to load more questions, 50 at a time.

Question 1Computer science (DP sciences group subject)

In a computer system, what is the main function of the control unit within the CPU?

  1. It decodes instructions and coordinates the flow of data between components Correct answer.
  2. It performs arithmetic and Boolean operations on register values
  3. It stores the program currently being executed on a long-term basis
  4. It converts analogue signals into digital values for the processor

Explanation

The control unit fetches and decodes each instruction and then generates the control signals that direct other components, such as the ALU, registers and memory, to carry out that instruction. It does not itself perform the calculations; it coordinates them.

Question 2Computer science (DP sciences group subject)

A student writes the binary value 1011 0100 as an unsigned integer. What is its decimal value?

  1. 180 Correct answer.
  2. 196
  3. 148
  4. 172

Explanation

For an unsigned binary number, add the place values where a 1 appears: 128 + 32 + 16 + 4 = 180. The bit positions set are 7, 5, 4 and 2 counting from zero on the right.

Question 3Computer science (DP sciences group subject)

Which statement best describes the role of a primary key in a relational database table?

  1. It stores the largest numeric value found in the table
  2. It uniquely identifies each record and cannot contain duplicate values Correct answer.
  3. It encrypts sensitive fields so they cannot be read directly
  4. It links every record to a record in a different table

Explanation

A primary key is a field or combination of fields whose value is unique for every record and is never null, so each row can be identified unambiguously. Foreign keys, by contrast, are used to reference records in another table.

Question 4Computer science (DP sciences group subject)

In the context of operating systems, what does virtual memory allow a computer to do?

  1. Store files permanently without any secondary storage device
  2. Share a single processor core between several users simultaneously
  3. Execute instructions without using the CPU cache at any stage
  4. Run programs whose combined memory demand exceeds the available physical RAM Correct answer.

Explanation

Virtual memory uses part of secondary storage as an extension of RAM, paging blocks of data between disk and memory so that programs larger than physical RAM can run. This can cause thrashing if the demand greatly exceeds real memory.

Question 5Computer science (DP sciences group subject)

A company network uses the private address range 192.168.10.0/24. How many usable host addresses does this subnet provide?

  1. 256
  2. 128
  3. 254 Correct answer.
  4. 255

Explanation

A /24 prefix leaves 8 host bits, giving 2^8 = 256 addresses. The all-zero host part is the network address and the all-ones host part is the broadcast address, so 256 - 2 = 254 usable host addresses remain.

Question 6Computer science (DP sciences group subject)

Which of the following is the best example of lossy compression being an appropriate choice?

  1. Streaming a feature film to a mobile device over a limited connection Correct answer.
  2. Storing a database backup that must restore to the exact original
  3. Compressing the source code of a program before distribution
  4. Archiving legal contracts that must remain byte-for-byte identical

Explanation

Lossy compression permanently discards data that human perception is unlikely to notice, which greatly reduces file size and is acceptable for video streaming where small quality losses are tolerable. Situations requiring exact reconstruction need lossless methods.

Question 7Computer science (DP sciences group subject)

What is the main purpose of a flowchart in the program development process?

  1. To translate high-level source code into machine code
  2. To measure the execution time of a finished program
  3. To store test data used when validating a program
  4. To represent the logic and sequence of steps in an algorithm visually Correct answer.

Explanation

A flowchart uses standard symbols to show the order of operations, decisions and loops in an algorithm, making the logic easier to design, check and communicate before coding begins. It is a design tool, not an execution or translation tool.

Question 8Computer science (DP sciences group subject)

Which statement correctly distinguishes a stack from a queue as an abstract data type?

  1. A stack removes the most recently added item, while a queue removes the least recently added item Correct answer.
  2. A stack allows access to any item by index, while a queue only allows access at one end
  3. A stack can only store numbers, while a queue can store any data type
  4. A stack removes the least recently added item, while a queue removes the most recently added item

Explanation

A stack follows last-in-first-out order, so the most recently pushed item is the first popped. A queue follows first-in-first-out order, so the item that has waited longest is removed first.

Question 9Computer science (DP sciences group subject)

A CPU executes an instruction using the fetch-execute cycle. Which sequence correctly describes the order of events?

  1. The instruction is executed, then decoded, then fetched from memory using the program counter
  2. The instruction is decoded, then fetched using the program counter, then executed
  3. The program counter is incremented, the instruction is executed, then it is fetched and decoded
  4. The address in the program counter is used to fetch the instruction, the instruction is decoded, then it is executed Correct answer.

Explanation

During the fetch stage the program counter holds the address of the next instruction, which is copied to memory and retrieved. The instruction is then decoded so the control unit can determine the required operation, after which it is executed and the program counter updated.

Question 10Computer science (DP sciences group subject)

A temperature sensor produces values between 0 and 40 degrees Celsius and the reading must be stored in 6 bits as an unsigned integer. What is the resolution of this representation?

  1. Approximately 0.63 degrees per step Correct answer.
  2. Approximately 0.16 degrees per step
  3. Approximately 1.00 degrees per step
  4. Approximately 6.40 degrees per step

Explanation

Six bits give 2^6 = 64 distinct values. Dividing the 40-degree range by 64 steps gives 40/64 = 0.625 degrees per step, so the resolution is about 0.63 degrees.

Question 11Computer science (DP sciences group subject)

A logic circuit outputs 1 only when exactly one of its two inputs is 1. Which single gate produces this behaviour?

  1. AND
  2. NAND
  3. XOR Correct answer.
  4. NOR

Explanation

The exclusive-OR gate outputs 1 when the inputs differ and 0 when they are the same, which matches exactly-one-input-high. An AND gate outputs 1 only when both inputs are 1.

Question 12Computer science (DP sciences group subject)

A relational database has a Students table and a Clubs table linked by a StudentClub table containing student ID and club ID. What is the main reason for this design?

  1. It resolves a many-to-many relationship between students and clubs Correct answer.
  2. It guarantees that every student joins at least one club
  3. It allows club names to be stored repeatedly in the Students table
  4. It removes the need for a primary key in the Students table

Explanation

A many-to-many relationship cannot be represented directly in a relational database, so a linking table with foreign keys to both entities is used. Each row of the linking table records one valid pairing of a student and a club.

Question 13Computer science (DP sciences group subject)

Which statement about the Transmission Control Protocol is accurate?

  1. It is connectionless and does not guarantee that packets arrive in order
  2. It converts domain names into IP addresses for client devices
  3. It establishes a connection and retransmits lost packets to provide reliable delivery Correct answer.
  4. It assigns a unique MAC address to every device on a network

Explanation

TCP performs a handshake to open a connection, numbers segments, acknowledges received data and retransmits anything lost, giving reliable, ordered delivery. This contrasts with UDP, which offers no such guarantees.

Question 14Computer science (DP sciences group subject)

A company holds personal data about customers. Which measure best supports the principle that data should be kept accurate and up to date?

  1. Encrypting the database so that unauthorised users cannot read it
  2. Restricting database access to a small number of administrators
  3. Providing a process for customers to review and correct their stored details Correct answer.
  4. Taking daily backups of the database to a remote location

Explanation

Accuracy concerns whether stored data reflects reality, so allowing data subjects to review and correct their records directly addresses that principle. The other measures protect confidentiality or availability rather than correctness.

Question 15Computer science (DP sciences group subject)

Consider the pseudocode below. x = 7 y = 3 while x > y x = x - 2 y = y + 1 end while What is the value of x when the loop terminates?

  1. 1 Correct answer.
  2. 5
  3. 3
  4. -1

Explanation

Trace the loop: after one pass x = 5 and y = 4, after two passes x = 3 and y = 5. The condition x > y is now false, so the loop stops with x equal to 3. Checking carefully, the loop runs exactly twice.

Question 16Computer science (DP sciences group subject)

A programmer needs to search an unsorted array of 5000 records for a single matching value. Which approach is most appropriate and why?

  1. A binary search, because it works on any order of data without preparation
  2. A linear search, because a binary search requires the data to be sorted first Correct answer.
  3. A linear search, because it guarantees finding the item faster than any other method
  4. A binary search, because it always examines fewer than ten elements

Explanation

Binary search repeatedly halves the search space but relies on the data being in sorted order. On unsorted data it may discard the region containing the target, so a linear search that checks each element in turn is the correct choice.

Question 17Computer science (DP sciences group subject)

Which statement about the fetch-execute cycle is true for a processor that uses pipelining?

  1. Each instruction must complete all stages before the next is fetched
  2. Instructions are executed in a random order to balance the workload
  3. Several instructions can be at different stages of the cycle at the same time Correct answer.
  4. The clock speed is automatically doubled compared with a non-pipelined CPU

Explanation

Pipelining overlaps stages so that while one instruction is being executed another is being decoded and a third fetched. This increases throughput, though individual instruction latency is not necessarily reduced.

Question 18Computer science (DP sciences group subject)

A colour is stored using 8 bits per pixel in a bitmap image of 800 by 600 pixels. What is the uncompressed file size in kilobytes, treating 1 KB as 1000 bytes?

  1. 384 KB
  2. 480 KB Correct answer.
  3. 48 KB
  4. 4800 KB

Explanation

The number of pixels is 800 x 600 = 480000. At 8 bits (1 byte) per pixel this is 480000 bytes, which equals 480 KB when 1 KB is 1000 bytes.

Question 19Computer science (DP sciences group subject)

Which situation is best modelled by a queue rather than a stack?

  1. Browser history being revisited with the back button
  2. Print jobs waiting to be processed by a shared printer in arrival order Correct answer.
  3. Undo operations in a text editor being reversed one at a time
  4. Nested procedure calls returning to their callers

Explanation

Print jobs should be handled in the order they arrive, which is first-in-first-out behaviour and therefore a queue. The other examples all require the most recent item to be handled first.

Question 20Computer science (DP sciences group subject)

A company wants to reduce the risk of a single hard disk failing and losing data. Which solution best addresses this specific risk?

  1. Installing a faster network card in the server
  2. Increasing the size of the RAM installed in the server
  3. Scheduling a weekly full backup to an external drive
  4. Configuring two disks in a RAID 1 mirror so data is written to both Correct answer.

Explanation

RAID 1 writes identical data to two disks, so if one fails the other still holds a complete copy and the system can continue running. Backups address recovery but not continuous availability after a single disk failure.

Question 21Computer science (DP sciences group subject)

A recursive function is written without a correct base case. What is the most likely consequence when it is called?

  1. It runs more slowly but always produces the correct result
  2. It continues calling itself until the call stack overflows and the program fails Correct answer.
  3. It returns zero automatically after a fixed number of calls
  4. It is converted into a loop by the compiler and runs normally

Explanation

Without a base case the recursion never reaches a stopping condition, so each call adds a new frame to the call stack. Eventually the stack space is exhausted and a stack overflow error terminates the program.

Question 22Computer science (DP sciences group subject)

Two programs implement the same algorithm. Program A runs in O(n^2) time and Program B runs in O(n log n) time. For very large input sizes, which conclusion is justified?

  1. Program A will be faster because quadratic growth uses fewer operations
  2. Both programs will take identical time once n exceeds one million
  3. Program B will grow more slowly in running time as n increases Correct answer.
  4. Program B will always run faster for every possible input size

Explanation

Big-O notation describes how running time grows as input size increases, so an O(n log n) algorithm scales better than an O(n^2) one for large n. It does not guarantee a faster time for every specific input, because constants and overheads matter at small sizes.

Question 23Computer science (DP sciences group subject)

A system stores signed integers in 8-bit two's complement form. What is the decimal value of the bit pattern 1110 0110?

  1. -122
  2. -25
  3. -26 Correct answer.
  4. 230

Explanation

In two's complement the leading 1 indicates a negative value. Invert the bits to get 0001 1001 (25) and add 1, giving a magnitude of 26, so the value is -26. Alternatively, -128 + 64 + 32 + 4 + 2 = -26.

Question 24Computer science (DP sciences group subject)

A hospital stores patient records in a database and must comply with data protection legislation. Which combination of measures best reflects the principle of data minimisation alongside access control?

  1. Encrypt the whole database and allow all staff to read every record after logging in
  2. Keep full historical copies of all records indefinitely and restrict access to managers
  3. Collect only the fields needed for treatment and grant each role access only to the fields it requires Correct answer.
  4. Store records on a single server and take backups every night to the same disk

Explanation

Data minimisation means collecting no more personal data than is necessary for the stated purpose, while role-based access control ensures each user sees only what their role requires. Together they limit both the amount stored and who can see it.

Question 25Computer science (DP sciences group subject)

A network administrator must divide the address block 172.16.0.0/16 into subnets that each support at least 500 hosts. What is the smallest prefix length that satisfies this requirement?

  1. /21
  2. /24
  3. /23 Correct answer.
  4. /22

Explanation

A /23 leaves 9 host bits, giving 2^9 - 2 = 510 usable host addresses, which meets the requirement of 500. A /24 would provide only 254, so it is too small, and a /22 would waste addresses.

Question 26Computer science (DP sciences group subject)

In a computer system, which component is responsible for carrying out arithmetic operations and logical comparisons?

  1. The Arithmetic Logic Unit (ALU) Correct answer.
  2. The address bus
  3. The program counter
  4. The control unit

Explanation

The ALU is the part of the CPU that performs arithmetic operations such as addition and logical operations such as AND and comparison. The control unit coordinates instruction execution rather than performing the calculations itself.

Question 27Computer science (DP sciences group subject)

A secondary storage device is required to hold a 4 GB video file. Which characteristic of secondary storage makes it suitable for this purpose, unlike main memory?

  1. It is stored inside the CPU registers
  2. It is faster than cache memory
  3. It is directly accessed by the ALU during every instruction
  4. It is non-volatile and retains data when power is removed Correct answer.

Explanation

Secondary storage such as a hard disk or SSD is non-volatile, so large files persist after the machine is switched off. Main memory is volatile and also generally smaller and more costly per unit of capacity.

Question 28Computer science (DP sciences group subject)

Which statement best describes the role of an operating system in managing memory?

  1. It routes packets between different networks
  2. It stores the backup copy of every file on a remote server
  3. It allocates memory to processes and prevents one process from overwriting another's memory Correct answer.
  4. It converts source code into machine code before execution

Explanation

Memory management is a core operating system function: the OS allocates and reclaims memory and isolates processes so they cannot corrupt each other. Compilation, routing and remote backup are handled by other software or hardware.

Question 29Computer science (DP sciences group subject)

A school network uses a star topology with a central switch. Which statement describes a consequence of this topology?

  1. Data collisions are impossible because devices are wired in a ring
  2. Every device must share one common transmission medium
  3. Failure of the central switch isolates all connected devices Correct answer.
  4. A single cable break always disables the entire network

Explanation

In a star topology all traffic passes through the central device, so if that device fails every connected node loses connectivity. A break in one branch cable, however, affects only that device.

Question 30Computer science (DP sciences group subject)

Which of the following is a valid reason for using a wireless network instead of a wired one in a small office?

  1. Devices can be repositioned without installing new cabling Correct answer.
  2. Wireless networks remove the need for any security configuration
  3. Wireless links are immune to interference from walls
  4. Wireless networks always offer higher throughput than wired links

Explanation

Mobility and avoidance of cabling costs are the main practical advantages of wireless networking. Wireless links are generally slower and more susceptible to interference and therefore require careful security configuration.

Question 31Computer science (DP sciences group subject)

In a relational database, which key uniquely identifies each record in a table?

  1. Composite attribute
  2. Candidate index
  3. Foreign key
  4. Primary key Correct answer.

Explanation

A primary key is a field or combination of fields whose value is unique for every record and never null, so it identifies each row. A foreign key instead references a primary key in another table.

Question 32Computer science (DP sciences group subject)

Which of the following best describes a local variable in a programming language?

  1. It is declared inside a subroutine and is accessible only within that subroutine Correct answer.
  2. It must be passed as a parameter to every subroutine
  3. It is declared at the top of the program and is accessible everywhere
  4. It is stored permanently in a file between program runs

Explanation

A local variable has scope limited to the block or subroutine in which it is declared, so it cannot be referenced elsewhere. This limits unintended interference between parts of a program.

Question 33Computer science (DP sciences group subject)

Which statement about a compiler is accurate?

  1. It detects all runtime errors before the program is executed
  2. It links object code to produce an executable but performs no translation
  3. It executes the source code one line at a time without producing a file
  4. It translates the whole source program into machine code before the program is run Correct answer.

Explanation

A compiler translates an entire source program into object or machine code, which can then be executed repeatedly without recompilation. It reports syntax errors but cannot detect all runtime errors in advance.

Question 34Computer science (DP sciences group subject)

A bitmap image is 200 pixels wide and 100 pixels high, with a colour depth of 24 bits per pixel. What is the uncompressed file size in bytes?

  1. 20000 bytes
  2. 60000 bytes Correct answer.
  3. 2400 bytes
  4. 480000 bytes

Explanation

The image has 200 x 100 = 20000 pixels, and at 24 bits each that is 480000 bits. Dividing by 8 bits per byte gives 60000 bytes.

Question 35Computer science (DP sciences group subject)

A student needs to store the result of the comparison 5 > 3 in a single variable for later use in a condition. Which data type is most appropriate?

  1. Boolean Correct answer.
  2. String
  3. Real
  4. Integer

Explanation

A comparison such as 5 > 3 evaluates to true or false, which is exactly the Boolean data type. Integers, strings and reals hold numeric or textual values rather than truth values.

Question 36Computer science (DP sciences group subject)

Consider the pseudocode below. count = 0 for i = 1 to 5 if i mod 2 = 0 then count = count + 1 end if next i What is the value of count after the loop finishes?

  1. 0
  2. 2 Correct answer.
  3. 5
  4. 3

Explanation

The loop runs for i = 1 to 5 and increments count only when i is even, which happens for i = 2 and i = 4. That gives count = 2.

Question 37Computer science (DP sciences group subject)

A queue is used to manage print jobs on a shared printer. Which behaviour results from this choice?

  1. Jobs are printed in order of file size
  2. The most recently submitted job is always printed first
  3. Jobs are printed in the order in which they were submitted Correct answer.
  4. Jobs can be removed only from the middle of the queue

Explanation

A queue is a first-in, first-out structure, so the earliest submitted job leaves the queue first. This matches fair handling of print jobs in arrival order.

Question 38Computer science (DP sciences group subject)

A function is defined as follows. function f(n) if n = 0 then return 1 else return n * f(n - 1) end if end function What value does f(4) return?

  1. 4
  2. 24 Correct answer.
  3. 16
  4. 10

Explanation

The function computes the factorial of n: f(4) = 4 x 3 x 2 x 1 x f(0), and f(0) returns 1, giving 24. The base case stops the recursion.

Question 39Computer science (DP sciences group subject)

A binary search is applied to the sorted array [3, 8, 12, 17, 21, 29, 34] to find the value 29. Which element is compared first?

  1. 29
  2. 12
  3. 21
  4. 17 Correct answer.

Explanation

Binary search examines the middle element first; the array has seven elements, so index 4 (value 17) is the midpoint. The target 29 is larger, so the search then continues in the right half.

Question 40Computer science (DP sciences group subject)

A logic circuit must output 1 only when both of its inputs are 1. Which gate implements this behaviour?

  1. AND Correct answer.
  2. XOR
  3. OR
  4. NOT

Explanation

An AND gate produces a 1 output only when every input is 1, which matches the stated condition. OR, XOR and NOT do not satisfy this truth table.

Question 41Computer science (DP sciences group subject)

A user reports that a web page fails to load, but the same page loads correctly on another device on the same network. Which troubleshooting step is most appropriate first?

  1. Check the network configuration and connectivity of the affected device Correct answer.
  2. Contact the internet service provider to report an outage
  3. Replace the network switch serving the whole building
  4. Reinstall the operating system on the affected device

Explanation

Because another device on the same network succeeds, the fault is most likely local to the affected device, so its configuration and connection should be checked first. Replacing shared hardware or reporting a provider outage is premature.

Question 42Computer science (DP sciences group subject)

A company wants to ensure that only authorised employees can view a confidential database. Which access control measure best supports this goal?

  1. Displaying a warning banner when the database is opened
  2. Taking daily incremental backups of the database
  3. Assigning users to roles with defined permissions and requiring authentication Correct answer.
  4. Encrypting the database backup tapes stored off site

Explanation

Role-based permissions combined with authentication restrict access to identified, authorised users. Backups and banners support other aspects of security but do not control who can view the live data.

Question 43Computer science (DP sciences group subject)

Which statement correctly distinguishes the internet from the World Wide Web?

  1. The internet is a browser, while the web is the underlying hardware
  2. The internet is the global network of networks, while the web is a service that runs on it Correct answer.
  3. The web is a physical cable system, while the internet is a set of web pages
  4. The internet and the web are two names for exactly the same thing

Explanation

The internet is the infrastructure of interconnected networks using common protocols such as TCP/IP. The World Wide Web is one application-layer service, accessed through browsers, that uses that infrastructure.

Question 44Computer science (DP sciences group subject)

A company stores a list of employee records in a database table. A new column is added to record each employee's date of birth. Which statement about the effect on the table is accurate?

  1. All existing records are automatically deleted when a column is added
  2. The primary key of the table must change to the new column
  3. Every existing record must already contain a value for the new column
  4. Existing records will have a null value in the new column unless a default is supplied Correct answer.

Explanation

Adding a column to an existing table does not populate old rows automatically; without a default, the new field is null for existing records. The primary key remains unchanged and no rows are deleted.

Question 45Computer science (DP sciences group subject)

A 6-bit binary number is used to store unsigned integers. What is the largest decimal value that can be represented?

  1. 31
  2. 32
  3. 63 Correct answer.
  4. 64

Explanation

With 6 bits there are 2^6 = 64 distinct patterns, and unsigned values range from 0 to 63. The largest value is therefore 63.

Question 46Computer science (DP sciences group subject)

A program repeatedly searches a large sorted collection of records for many different keys. Which data structure change would most improve search efficiency?

  1. Store the records in an unsorted linked list instead of an array
  2. Store the records in a balanced binary search tree instead of an unsorted array Correct answer.
  3. Store the records in a queue instead of an array
  4. Store the records in a stack instead of an array

Explanation

A balanced binary search tree supports search in O(log n) time, which is far better than the O(n) linear scan of an unsorted array. Stacks, queues and unsorted linked lists do not provide efficient key-based search.

Question 47Computer science (DP sciences group subject)

A recursive procedure processes a list by halving it on each call. If the list initially has 1024 elements, how many recursive calls are needed before the list size reaches 1?

  1. 11
  2. 10 Correct answer.
  3. 1024
  4. 512

Explanation

Halving repeatedly gives 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1, which requires ten halving steps. This reflects the logarithmic relationship log2(1024) = 10.

Question 48Computer science (DP sciences group subject)

A system uses 8-bit two's complement representation. What is the decimal value of the bit pattern 1011 0100?

  1. 180
  2. -76 Correct answer.
  3. -75
  4. -77

Explanation

The leading bit is 1, so the value is negative. Inverting the bits gives 0100 1011 (75) and adding 1 gives 76, so the pattern represents -76.

Question 49Computer science (DP sciences group subject)

A network must be split so that each subnet supports at least 500 hosts, starting from 172.16.0.0/16. Which subnet mask provides the smallest subnet that still meets the requirement?

  1. 255.255.254.0 Correct answer.
  2. 255.255.252.0
  3. 255.255.255.128
  4. 255.255.255.0

Explanation

Supporting 500 hosts needs at least 9 host bits, since 2^9 - 2 = 510 usable addresses. That corresponds to a /23 prefix, whose mask is 255.255.254.0.

Question 50Computer science (DP sciences group subject)

A company must choose between storing data on its own servers and using cloud storage. Which consideration most directly favours the cloud option for a small start-up?

  1. The data is guaranteed to be immune to network outages
  2. Physical control of the storage hardware remains with the start-up
  3. No data protection obligations apply to cloud-hosted data
  4. Capacity can be scaled up or down without buying additional hardware Correct answer.

Explanation

Cloud storage allows elastic scaling, so a start-up can avoid large upfront hardware costs and adjust capacity as demand changes. Cloud use does not remove legal obligations or guarantee freedom from outages.