BCS Written Computer Science study materials
BCS Written Computer Science study resources

BCS Written Computer Science practice questions

One question at a time. Build your BCS Written Computer Science 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 Fundamentals and Computer Architecture

In the von Neumann architecture, which unit holds the program instructions while they are being executed?

  1. The input/output subsystem
  2. Main memory Correct answer.
  3. The control unit
  4. The arithmetic logic unit

Explanation

In a stored-program machine, both instructions and data reside in the same main memory and are fetched from it during execution. The processor reads each instruction from memory and decodes it in the control unit. The ALU performs data operations but does not store the program.

Question 2Computer Fundamentals and Computer Architecture

A processor has a 12-bit address bus and a word size of one byte. What is the maximum directly addressable memory space?

  1. 1024 bytes
  2. 2048 bytes
  3. 8192 bytes
  4. 4096 bytes Correct answer.

Explanation

With 12 address lines, the number of distinct addresses is 2 raised to the power 12, which equals 4096. Since each address selects one byte, the directly addressable space is 4096 bytes. Multiplying the address count by the word size is unnecessary because the word size is already one byte.

Question 3Computer Fundamentals and Computer Architecture

Which memory type is volatile and loses its contents when power is removed, yet offers fast access used for active programs?

  1. Flash memory
  2. DRAM Correct answer.
  3. Magnetic disk
  4. ROM

Explanation

Dynamic RAM stores each bit as charge on a capacitor and needs periodic refreshing, and it loses that charge when power is cut. It is nonetheless the fast working memory in which running programs reside. Flash, disk, and ROM all retain data without power.

Question 4Computer Fundamentals and Computer Architecture

Which number system representation is used internally to execute arithmetic in most modern general-purpose processors?

  1. Two's complement binary Correct answer.
  2. Sign-magnitude binary
  3. Excess-3 code
  4. Binary-coded decimal

Explanation

Two's complement lets the same adder circuit handle both positive and negative values because subtraction becomes addition of a complemented operand. It also gives a single representation of zero and a well-defined range from negative to positive values. Sign-magnitude and decimal codes require extra correction logic.

Question 5Computer Fundamentals and Computer Architecture

What is the primary purpose of cache memory in a computer system?

  1. To convert logical addresses into physical addresses
  2. To store the operating system permanently across power cycles
  3. To reduce the average time the processor waits for data from main memory Correct answer.
  4. To increase the total capacity of main memory available to programs

Explanation

Cache exploits locality of reference by keeping recently and frequently used blocks close to the processor. A hit in cache is served far faster than a main-memory access, so the average access time falls. Cache does not enlarge memory capacity or perform address translation.

Question 6Computer Fundamentals and Computer Architecture

How many bits are required to represent the unsigned decimal value 200 in pure binary?

  1. 9 bits
  2. 8 bits Correct answer.
  3. 7 bits
  4. 6 bits

Explanation

Seven bits represent values from 0 to 127, so 200 does not fit. Eight bits cover 0 to 255, which includes 200. Nine bits would also hold the value but is more than the minimum required.

Question 7Computer Fundamentals and Computer Architecture

A CPU fetches an instruction from address 0x0100 and the instruction occupies four bytes. Assuming sequential execution with no branch, what is the address of the next instruction?

  1. 0x0103
  2. 0x0200
  3. 0x0101
  4. 0x0104 Correct answer.

Explanation

After fetching an instruction, the program counter advances by the length of that instruction. Adding four bytes to 0x0100 gives 0x0104. Sequential execution means the next fetch begins immediately after the current instruction.

Question 8Computer Fundamentals and Computer Architecture

In a pipelined processor, which condition most directly reduces the benefit of overlapping instruction stages?

  1. A larger instruction cache
  2. A higher clock frequency
  3. A wider data bus
  4. A data dependency between consecutive instructions Correct answer.

Explanation

Pipelining works best when instructions can flow through stages independently. A data dependency forces one instruction to wait for a result produced by an earlier one, creating a stall or bubble. Larger caches, wider buses, and higher clocks generally help rather than hinder throughput.

Question 9Computer Fundamentals and Computer Architecture

Which addressing mode obtains the operand from the memory location whose address is held in a register?

  1. Register direct
  2. Register indirect Correct answer.
  3. Immediate
  4. Direct

Explanation

In register indirect addressing, the register holds an address and the processor reads memory at that address to obtain the operand. Immediate mode embeds the operand in the instruction itself. Direct mode places the address in the instruction, and register direct uses the register contents as the operand.

Question 10Computer Fundamentals and Computer Architecture

A cache has 64 blocks and uses direct mapping with 16 blocks per set index position. How many index bits are needed to select a cache line?

  1. 2 bits
  2. 8 bits
  3. 4 bits Correct answer.
  4. 6 bits

Explanation

Direct mapping places each block in exactly one line determined by the block address modulo the number of lines. Selecting among 16 lines requires log base 2 of 16, which is 4 bits. The total block count of 64 would require 6 bits only if every block were individually indexed without set structure.

Question 11Computer Fundamentals and Computer Architecture

What is the main advantage of a RISC instruction set over a CISC instruction set?

  1. Larger and more complex instruction encodings
  2. Direct support for complex memory-to-memory operations
  3. Fewer registers available to the programmer
  4. Simpler instructions that suit pipelining and fixed-length decoding Correct answer.

Explanation

RISC designs use a small set of simple, fixed-length instructions that execute in few cycles. This regularity makes deep pipelining and fast decoding practical. CISC designs favour rich, variable-length instructions that often perform multi-step operations.

Question 12Computer Fundamentals and Computer Architecture

Which component of the CPU is responsible for decoding an instruction and generating the control signals that direct other units?

  1. The arithmetic logic unit
  2. The register file
  3. The control unit Correct answer.
  4. The memory management unit

Explanation

The control unit interprets the opcode of each fetched instruction and asserts the signals that coordinate the datapath. It determines which registers are read, which operation the ALU performs, and when memory is accessed. The ALU performs operations but does not schedule them.

Question 13Computer Fundamentals and Computer Architecture

A system uses 32-bit virtual addresses and 4 KiB pages. How many bits of the virtual address form the page offset?

  1. 20 bits
  2. 10 bits
  3. 14 bits
  4. 12 bits Correct answer.

Explanation

A 4 KiB page contains 4096 bytes, and selecting a byte within it requires log base 2 of 4096, which is 12 bits. Those low-order bits are passed through unchanged during translation. The remaining high-order bits identify the virtual page number.

Question 14Computer Fundamentals and Computer Architecture

What does an interrupt allow a processor to do during normal program execution?

  1. Expand the size of main memory on demand
  2. Convert a virtual address into a physical address
  3. Suspend the current program and transfer control to a handler routine Correct answer.
  4. Increase the clock speed of the processor temporarily

Explanation

An interrupt signals the processor that an event needs attention, such as completion of an I/O transfer. The processor saves its current state and branches to a handler, then resumes the interrupted program afterwards. This mechanism lets devices be serviced without constant polling.

Question 15Computer Fundamentals and Computer Architecture

Which statement correctly describes the difference between a latch and a flip-flop in sequential logic?

  1. A latch is edge-triggered while a flip-flop is level-sensitive
  2. A latch stores analog values while a flip-flop stores binary values
  3. A latch is level-sensitive while a flip-flop is edge-triggered Correct answer.
  4. A latch has no feedback path while a flip-flop always has one

Explanation

A latch changes its output whenever its enable input is at the active level, so it is transparent during that interval. A flip-flop captures its input only at a clock edge, which makes timing more predictable. Both store a binary state using feedback.

Question 16Computer Fundamentals and Computer Architecture

A disk has an average seek time of 8 ms, a rotational latency of 4 ms, and a transfer rate of 100 MB/s. What is the approximate average time to read a 1 MB block?

  1. About 22 ms Correct answer.
  2. About 4 ms
  3. About 12 ms
  4. About 8 ms

Explanation

Total access time sums seek time, rotational latency, and transfer time. Transfer of 1 MB at 100 MB/s takes about 10 ms. Adding 8 ms and 4 ms gives roughly 22 ms.

Question 17Computer Fundamentals and Computer Architecture

A processor's clock runs at 2 GHz and a program executes 10^9 instructions with an average of 4 cycles per instruction. What is the approximate execution time?

  1. 0.5 seconds
  2. 1 second
  3. 4 seconds
  4. 2 seconds Correct answer.

Explanation

Total cycles equal instructions multiplied by cycles per instruction, giving 4 times 10^9 cycles. Dividing by the clock rate of 2 times 10^9 cycles per second yields 2 seconds. Both instruction count and cycle count must be combined before dividing by frequency.

Question 18Computer Fundamentals and Computer Architecture

In a two-level memory hierarchy where the cache hit ratio is 0.9, the cache access time is 10 ns, and the main memory access time is 100 ns, what is the average access time assuming a hit costs only cache time?

  1. 10 ns
  2. 100 ns
  3. 55 ns
  4. 19 ns Correct answer.

Explanation

On a hit, which occurs 90 percent of the time, the access takes 10 ns. On a miss, the access takes the cache time plus the main memory time, 110 ns. The weighted average is 0.9 times 10 plus 0.1 times 110, which equals 19 ns.

Question 19Computer Fundamentals and Computer Architecture

Which hazard in a pipeline arises when an instruction needs a hardware resource that is still in use by an earlier instruction?

  1. Control hazard
  2. Branch hazard
  3. Structural hazard Correct answer.
  4. Data hazard

Explanation

A structural hazard occurs when two instructions in different stages require the same resource, such as a single memory port, at the same time. Data hazards concern operand dependencies, while control hazards concern changes in the instruction stream after a branch. Resolving structural hazards may require extra hardware or scheduling changes.

Question 20Computer Fundamentals and Computer Architecture

Which statement about the role of the program counter during instruction execution is correct?

  1. It stores the opcode of the instruction being decoded
  2. It holds the result of the most recent arithmetic operation
  3. It holds the address of the next instruction to be fetched Correct answer.
  4. It counts the number of instructions executed so far

Explanation

The program counter keeps the address from which the next instruction will be fetched. After each fetch it is updated, either incremented or replaced by a branch target. Other registers hold data results or the current instruction itself.

Question 21Data Structures and Algorithms

Which data structure follows the Last-In-First-Out principle?

  1. Queue
  2. Linked list
  3. Binary heap
  4. Stack Correct answer.

Explanation

A stack inserts and removes elements at the same end, called the top, so the most recently pushed element is the first one popped. This Last-In-First-Out behaviour is the defining property of the stack abstract data type.

Question 22Data Structures and Algorithms

In a singly linked list, what is the worst-case time complexity of searching for a given value?

  1. O(n log n)
  2. O(log n)
  3. O(n) Correct answer.
  4. O(1)

Explanation

A singly linked list offers only sequential access, so in the worst case every node must be visited before the target is found or the list ends. That gives linear time, O(n), in the number of nodes.

Question 23Data Structures and Algorithms

A binary search is applied to a sorted array of 1000 elements. Approximately how many comparisons are needed in the worst case?

  1. 500
  2. 10 Correct answer.
  3. 1000
  4. 100

Explanation

Binary search halves the search interval at each step, so the worst case is about log base 2 of n comparisons. Since 2^10 is 1024, roughly ten comparisons suffice for 1000 elements.

Question 24Data Structures and Algorithms

Which traversal of a binary search tree outputs the keys in ascending sorted order?

  1. Pre-order
  2. Post-order
  3. Level-order
  4. In-order Correct answer.

Explanation

In a binary search tree every key in the left subtree is smaller than the root and every key in the right subtree is larger. Visiting left subtree, then root, then right subtree therefore emits keys in non-decreasing order.

Question 25Data Structures and Algorithms

What is the primary purpose of a hash function in a hash table?

  1. To balance the height of a tree
  2. To map a key to an index in the table Correct answer.
  3. To sort the stored keys
  4. To compress the stored values

Explanation

A hash function converts a key into an integer that is reduced modulo the table size to give a bucket index. A good hash spreads keys uniformly so that collisions and average probe lengths stay small.

Question 26Data Structures and Algorithms

Which sorting algorithm repeatedly selects the smallest remaining element and swaps it into position?

  1. Quick sort
  2. Selection sort Correct answer.
  3. Insertion sort
  4. Merge sort

Explanation

Selection sort scans the unsorted suffix to find its minimum and exchanges it with the first unsorted position. This yields quadratic time regardless of input order but performs at most n-1 swaps.

Question 27Data Structures and Algorithms

What does the Big-O notation O(g(n)) describe for an algorithm?

  1. An asymptotic upper bound on growth Correct answer.
  2. The number of lines of source code
  3. The average memory usage of the program
  4. The exact running time on every input

Explanation

Big-O gives an asymptotic upper bound: for large inputs the growth of the cost function is dominated by g(n) up to a constant factor. It deliberately ignores machine-specific constants and lower-order terms.

Question 28Data Structures and Algorithms

A queue is implemented with a circular array of capacity 8. After enqueueing 5 items, the front index is 2 and the rear index is 6. How many items does the queue hold?

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

Explanation

The number of stored items equals (rear - front + capacity) mod capacity, which gives (6 - 2 + 8) mod 8 = 4 positions occupied beyond the front, plus the item at the rear, totalling 5. An alternative check is that the queue was stated to contain 5 items after those enqueues.

Question 29Data Structures and Algorithms

Which collision resolution scheme stores colliding entries in linked lists attached to each table slot?

  1. Quadratic probing
  2. Separate chaining Correct answer.
  3. Double hashing
  4. Linear probing

Explanation

Separate chaining keeps a secondary container, typically a linked list, per bucket and appends colliding keys to it. Open addressing schemes instead search for another free slot inside the table array itself.

Question 30Data Structures and Algorithms

What is the worst-case time complexity of quicksort when the pivot is always the smallest or largest element?

  1. O(n)
  2. O(n log n)
  3. O(n^2) Correct answer.
  4. O(2^n)

Explanation

A consistently extreme pivot splits the array into parts of sizes 0 and n-1, so the recursion depth becomes n and the total partitioning work is quadratic. Randomised or median-based pivot selection makes this degenerate behaviour very unlikely.

Question 31Data Structures and Algorithms

Which property must a binary heap satisfy?

  1. Each parent is ordered relative to its children and the tree is complete Correct answer.
  2. All leaves are at the same depth and keys are sorted
  3. The in-order traversal produces sorted keys
  4. Every node is smaller than its parent

Explanation

A heap maintains the heap-order property, so a min-heap has every parent no larger than its children, and it is a complete binary tree filling levels left to right. Completeness allows the array representation with parent and child indices computed arithmetically.

Question 32Data Structures and Algorithms

A hash table with 1000 slots stores 750 keys using separate chaining. What is the load factor?

  1. 1.33
  2. 0.75 Correct answer.
  3. 0.25
  4. 7.5

Explanation

The load factor is the number of stored keys divided by the number of slots, here 750/1000 = 0.75. It estimates the average chain length and therefore the expected cost of an unsuccessful search.

Question 33Data Structures and Algorithms

In a max-heap stored as an array with indices starting at 0, where is the largest element located?

  1. At the last occupied index
  2. At index n/2
  3. At index 0 Correct answer.
  4. In the deepest leftmost leaf

Explanation

The heap-order property places the maximum at the root, and the array representation stores the root at index 0. The remaining elements are arranged so that each parent dominates its children.

Question 34Data Structures and Algorithms

What is the time complexity of building a heap from an unsorted array of n elements using the bottom-up heapify procedure?

  1. O(log n)
  2. O(n^2)
  3. O(n) Correct answer.
  4. O(n log n)

Explanation

Bottom-up construction heapifies nodes from the last internal node to the root, and the total work sums to a linear bound because most nodes sit near the bottom and sift down only a little. This is tighter than heapifying each element separately.

Question 35Data Structures and Algorithms

Which graph traversal uses a queue and visits vertices in order of increasing distance in edges from the source?

  1. Topological sort
  2. Breadth-first search Correct answer.
  3. Depth-first search
  4. Dijkstra's algorithm

Explanation

Breadth-first search explores all vertices at distance k before any at distance k+1, and a FIFO queue enforces exactly that frontier order. On unweighted graphs it therefore yields shortest path distances in edge counts.

Question 36Data Structures and Algorithms

A connected undirected graph has 20 vertices. What is the minimum number of edges it can have?

  1. 21
  2. 19 Correct answer.
  3. 190
  4. 20

Explanation

A connected graph on n vertices needs at least n-1 edges, achieved exactly by a spanning tree. With 20 vertices the minimum is therefore 19 edges.

Question 37Data Structures and Algorithms

Which algorithm design technique does merge sort illustrate?

  1. Greedy choice
  2. Dynamic programming
  3. Backtracking
  4. Divide and conquer Correct answer.

Explanation

Merge sort splits the input into halves, recursively sorts each half, and merges the results, which is the divide-and-conquer pattern of dividing, conquering and combining. The merge step does linear work per level across logarithmic levels.

Question 38Data Structures and Algorithms

What does a topological ordering of a directed graph require?

  1. The graph must be undirected and connected
  2. All vertices must have equal in-degree
  3. Every edge must point from an earlier vertex to a later one in the order Correct answer.
  4. The graph must contain at least one cycle

Explanation

A topological order lists vertices so that for every directed edge u to v, u appears before v. Such an order exists precisely when the directed graph is acyclic, and it is used to schedule dependency-constrained tasks.

Question 39Data Structures and Algorithms

An array contains 7 elements. A binary search for a key absent from the array is performed. What is the maximum number of comparisons of array elements?

  1. 3 Correct answer.
  2. 4
  3. 2
  4. 7

Explanation

Each comparison halves the remaining interval, and the interval sizes go from 7 to 3 to 1 before becoming empty, so at most three element comparisons occur. In general the bound is the ceiling of log base 2 of n plus one.

Question 40Data Structures and Algorithms

A priority queue must support millions of insertions interleaved with extractions of the minimum. Which implementation gives the best worst-case guarantee per operation?

  1. Binary heap Correct answer.
  2. Sorted array
  3. Unsorted array
  4. Singly linked list

Explanation

A binary heap supports insertion and extract-min in O(log n) worst-case time, which balances both operations well under interleaving. The array alternatives make one of the two operations linear.

Question 41Data Structures and Algorithms

An AVL tree stores 1000 keys. What is the guaranteed upper bound on its height?

  1. About 15 Correct answer.
  2. About 500
  3. About 10
  4. About 1000

Explanation

AVL trees keep the heights of sibling subtrees within one, which bounds height by roughly 1.44 times log base 2 of n. For 1000 keys that is around 15 levels, close to but slightly above the ideal of 10.

Question 42Data Structures and Algorithms

Which statement about the average-case complexity of successful search in a hash table with separate chaining and load factor alpha is correct?

  1. It is O(log n) regardless of alpha
  2. It is O(alpha log n) for uniform hashing
  3. It is O(1) when alpha is bounded by a constant Correct answer.
  4. It is O(n) whenever alpha is below 1

Explanation

Under uniform hashing the expected probe length is Theta(1 + alpha), so keeping the load factor below a fixed constant yields constant expected time. Resizing the table when the load factor grows preserves this guarantee.

Question 43Data Structures and Algorithms

A dynamic programming solution fills an n by n table, and each cell is computed from a constant number of previously filled cells. What are the time and space complexities?

  1. Time O(n), space O(n)
  2. Time O(n^2), space O(n)
  3. Time O(2^n), space O(n)
  4. Time O(n^2), space O(n^2) Correct answer.

Explanation

Filling every one of the n squared cells with constant work per cell costs quadratic time, and retaining the whole table costs quadratic space. Rolling-array optimisation can reduce space but is not assumed here.

Question 44Data Structures and Algorithms

Dijkstra's algorithm is run on a graph containing an edge with negative weight. Why may the result be incorrect?

  1. The algorithm requires all edge weights to be equal
  2. Negative weights make the graph necessarily cyclic
  3. A vertex may be finalised before a cheaper path through a later vertex is discovered Correct answer.
  4. The priority queue cannot store negative numbers

Explanation

Dijkstra's correctness relies on the assumption that once the minimum-distance vertex is extracted, no later path can improve it, which fails when negative edges exist. Bellman-Ford handles negative weights and can also detect negative cycles.

Question 45Programming Languages and Software Development

In C, what does the declaration `int *p[10];` declare?

  1. A function returning a pointer to int
  2. A pointer to an array of ten ints
  3. An array of ten pointers to int Correct answer.
  4. A pointer to a pointer to int

Explanation

In C declarators, the postfix subscript operator binds more tightly than the prefix asterisk, so `p` is first an array of ten elements, and each element is a pointer to int. A pointer to an array would require parentheses, as in `int (*p)[10];`.

Question 46Programming Languages and Software Development

Which phase of compilation typically detects that a variable is used without being declared?

  1. Semantic analysis Correct answer.
  2. Instruction scheduling
  3. Code generation
  4. Lexical analysis

Explanation

Semantic analysis checks the program against language rules that cannot be expressed by grammar alone, including name resolution and type consistency. An undeclared identifier is a scope violation discovered once the parser has built a syntax tree and symbol tables are consulted.

Question 47Programming Languages and Software Development

What is the time complexity of searching for a key in a balanced binary search tree with n nodes?

  1. O(n log n)
  2. O(n)
  3. O(log n) Correct answer.
  4. O(1)

Explanation

A balanced binary search tree keeps its height proportional to the logarithm of the node count, so each comparison descends one level and at most O(log n) levels are visited. Degradation to O(n) only happens when the tree becomes a path, which balancing prevents.

Question 48Programming Languages and Software Development

Which principle states that a subclass should be usable wherever its superclass is expected without breaking correctness?

  1. Liskov substitution principle Correct answer.
  2. Open-closed principle
  3. Interface segregation principle
  4. Single responsibility principle

Explanation

The Liskov substitution principle constrains inheritance so that a derived type preserves the observable behaviour promised by its base type. Code written against the base class must keep working when a subtype instance is supplied, which forbids strengthening preconditions or weakening postconditions.

Question 49Programming Languages and Software Development

In Java, what is the effect of marking a method `final` in a class?

  1. The method must be static
  2. The method's return value becomes immutable
  3. The method cannot be called outside its package
  4. Subclasses cannot override that method Correct answer.

Explanation

The `final` modifier on a method forbids further overriding in any subclass, allowing the compiler to bind the call statically. It does not change the method's linkage, visibility, or the mutability of returned objects.

Question 50Programming Languages and Software Development

Which HTTP status code class indicates that the client's request was successfully received, understood, and accepted?

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

Explanation

HTTP groups status codes by their first digit, and the 2xx class signals successful processing of the request, as with 200 OK or 201 Created. The other classes communicate redirection, client error, and server error respectively.