NEB 12 Computer Science study materials
NEB 12 Computer Science study resources

NEB 12 Computer Science practice questions

One question at a time. Build your NEB 12 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 Science

In a singly linked list, which operation is performed in O(1) time when a pointer to the node immediately before the target position is available?

  1. Searching for a value stored in the list
  2. Inserting a new node after that node Correct answer.
  3. Deleting the last node of the list
  4. Traversing the list to count its nodes

Explanation

Insertion after a known node only requires allocating a node and reassigning two pointers, so the cost is constant regardless of list length. Operations that must walk the list, such as searching, counting, or reaching the tail without a tail pointer, take linear time.

Question 2Computer Science

A binary search is applied to a sorted array of 1024 elements. What is the maximum number of comparisons needed to determine whether a value is present?

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

Explanation

Each comparison halves the remaining search space, so the number of steps is bounded by the base-2 logarithm of the array size. Since 2^10 = 1024, at most 10 halvings are needed.

Question 3Computer Science

Which statement correctly describes the relationship between a stack and the order in which items are removed?

  1. Items are removed in the same order in which they were added
  2. Items are removed according to a priority value assigned at insertion
  3. Items are removed in sorted order of their stored values
  4. Items are removed in the reverse of the order in which they were added Correct answer.

Explanation

A stack is a last-in-first-out structure, so the most recently pushed item is the first popped. This reversal of insertion order is the defining property that distinguishes a stack from a queue.

Question 4Computer Science

What is the decimal value of the binary number 101101?

  1. 43
  2. 54
  3. 45 Correct answer.
  4. 46

Explanation

Evaluating the place values from left to right gives 32 + 0 + 8 + 4 + 0 + 1, which totals 45. Each bit contributes 2 raised to its position index counted from the right starting at zero.

Question 5Computer Science

A network uses the subnet mask 255.255.255.192. How many usable host addresses does each subnet provide?

  1. 64
  2. 126
  3. 62 Correct answer.
  4. 30

Explanation

The mask 255.255.255.192 leaves six host bits, giving 2^6 = 64 addresses per subnet. Subtracting the network and broadcast addresses leaves 62 usable host addresses.

Question 6Computer Science

Which SQL clause is used to filter rows after grouping has been performed?

  1. HAVING Correct answer.
  2. WHERE
  3. GROUP BY
  4. ORDER BY

Explanation

HAVING applies conditions to groups produced by GROUP BY, so it can reference aggregate functions such as COUNT or SUM. WHERE filters individual rows before grouping takes place.

Question 7Computer Science

In a relational database, which key uniquely identifies each row and is chosen by the database designer as the principal means of identification?

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

Explanation

The primary key is the candidate key selected to uniquely identify tuples in a relation, and it cannot contain null values. Other candidate keys remain unique but are not designated as the main identifier.

Question 8Computer Science

What is the result of the Boolean expression (A AND B) OR (NOT A AND B)?

  1. A OR B
  2. A
  3. B Correct answer.
  4. A AND B

Explanation

Factoring out B gives B AND (A OR NOT A), and A OR NOT A is always true, so the expression simplifies to B. This is a direct application of the distributive and complement laws of Boolean algebra.

Question 9Computer Science

Which logic gate produces a HIGH output only when its two inputs are different?

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

Explanation

The exclusive-OR gate outputs 1 when exactly one input is 1, which means the inputs differ. This behaviour makes XOR useful for parity and comparison circuits.

Question 10Computer Science

A student writes a recursive function to compute the nth Fibonacci number without memoisation. What is the time complexity of this approach?

  1. Quadratic, O(n^2)
  2. Exponential, approximately O(2^n) Correct answer.
  3. Logarithmic, O(log n)
  4. Linear, O(n)

Explanation

Each call branches into two further calls, and the recursion tree grows roughly by a factor related to the golden ratio per level, giving exponential time. Many subproblems are recomputed because no results are stored.

Question 11Computer Science

Which of the following is the binary representation of the denary number 90?

  1. 1011010 Correct answer.
  2. 1001100
  3. 1010100
  4. 1101010

Explanation

Subtracting the largest powers of two gives 64 + 16 + 8 + 2, which corresponds to bits set at positions 6, 4, 3 and 1. Writing those bits from position 6 down to 0 yields 1011010.

Question 12Computer Science

In the OSI reference model, at which layer does a router primarily operate when forwarding packets between networks?

  1. Transport layer
  2. Network layer Correct answer.
  3. Data link layer
  4. Physical layer

Explanation

Routers forward packets using logical addressing such as IP addresses, which is the responsibility of the network layer. They examine destination addresses to choose the next hop toward the target network.

Question 13Computer Science

Which protocol translates human-readable domain names into IP addresses?

  1. SMTP
  2. DNS Correct answer.
  3. DHCP
  4. FTP

Explanation

The Domain Name System resolves names such as example.com into numeric IP addresses so that clients can reach servers. It works as a distributed hierarchy of name servers.

Question 14Computer Science

What is the primary purpose of a checksum in a data transmission protocol?

  1. To encrypt the payload so eavesdroppers cannot read it
  2. To detect errors introduced during transmission Correct answer.
  3. To compress the payload to reduce bandwidth use
  4. To authenticate the sender with a shared secret key

Explanation

A checksum is computed over the data and sent alongside it; the receiver recomputes it and compares, revealing corruption. It detects accidental errors but does not correct them or provide security.

Question 15Computer Science

In a compiler's processing of source code, which phase is responsible for checking that variables are declared before use and that types match?

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

Explanation

Semantic analysis follows parsing and enforces meaning-level rules such as declaration before use and type compatibility. It typically builds and consults a symbol table during this check.

Question 16Computer Science

A loop is written as: FOR i = 1 TO 5, then FOR j = 1 TO 4 inside it, with the inner body executed once per iteration. How many times does the inner body execute?

  1. 9
  2. 20 Correct answer.
  3. 25
  4. 16

Explanation

The outer loop runs 5 times and the inner loop runs 4 times for each outer iteration. Multiplying the iteration counts gives 5 × 4 = 20 executions of the inner body.

Question 17Computer Science

When a function is called, which structure typically stores its parameters, local variables and return address?

  1. The program counter
  2. The call stack Correct answer.
  3. The heap
  4. The instruction register

Explanation

Each call pushes an activation record, or stack frame, containing arguments, locals and the return address, and the frame is popped when the function returns. This is why deep recursion can exhaust stack memory.

Question 18Computer Science

Which sorting algorithm has a worst-case time complexity of O(n log n) and is stable?

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

Explanation

Merge sort divides the array in halves, sorts each recursively and merges them, giving O(n log n) in the worst case while preserving the relative order of equal elements. Its main cost is the extra memory needed for merging.

Question 19Computer Science

Which property of an object-oriented class prevents external code from modifying its internal data directly?

  1. Overloading
  2. Inheritance
  3. Encapsulation Correct answer.
  4. Polymorphism

Explanation

Encapsulation hides internal state behind a controlled interface, usually by making fields private and exposing methods. This protects invariants and lets the implementation change without breaking callers.

Question 20Computer Science

A program reads an integer from the user but the user types letters. Which construct is most appropriate for handling this failure without terminating the program?

  1. A function that returns the converted value
  2. A while loop that repeats the same conversion
  3. A try-catch block around the input and conversion Correct answer.
  4. A global variable that stores the last input

Explanation

Exception handling isolates the risky conversion and lets the program respond to invalid input while continuing execution. The catch block can prompt the user again instead of crashing.

Question 21Computer Science

What is the main advantage of a relational database over a flat-file system when the same customer data appears in many orders?

  1. Data redundancy is reduced through normalisation and relationships Correct answer.
  2. Queries can only retrieve one record at a time
  3. Each application must maintain its own copy of the data
  4. Records are always stored in a single file for speed

Explanation

Normalisation stores shared data once and links records through keys, which removes duplication and the update anomalies it causes. Flat files repeat the same values in every record that refers to the customer.

Question 22Computer Science

A 3-input AND gate has inputs A = 1, B = 0 and C = 1. What is the output?

  1. Undefined
  2. Equal to A OR C
  3. 1
  4. 0 Correct answer.

Explanation

An AND gate outputs 1 only when every input is 1. Because B is 0, the output is 0 regardless of the other inputs.

Question 23Computer Science

In a hash table with chaining, what happens when two different keys hash to the same index?

  1. The table automatically doubles its size
  2. The second key overwrites the first entry
  3. Both entries are stored in a list at that index Correct answer.
  4. The second key is rejected and an error is raised

Explanation

Separate chaining keeps a collection, usually a linked list, at each bucket so colliding entries coexist. Lookup then scans that short chain comparing the full keys.

Question 24Computer Science

Which statement best describes the difference between lossy and lossless compression?

  1. Lossless compression only works on text, while lossy compression only works on images
  2. Lossy compression reduces file size, while lossless compression does not
  3. Lossy compression discards some data permanently, while lossless compression allows exact reconstruction Correct answer.
  4. Lossy compression is always reversible, while lossless compression is not

Explanation

Lossless methods such as run-length encoding preserve all original data so the file can be restored exactly. Lossy methods such as JPEG discard detail the human eye is unlikely to notice, so the original cannot be recovered perfectly.

Question 25Computer Science

A programmer traces a loop and finds that an index variable is incremented before the terminating condition is tested, causing one extra pass. Which type of error is this?

  1. A lexical error
  2. A syntax error
  3. A runtime error
  4. A logic error Correct answer.

Explanation

The program is syntactically valid and runs without crashing, but it produces the wrong result because the algorithm's reasoning is flawed. Such off-by-one mistakes are classic logic errors found by tracing or testing.

Question 26Computer Science

Which number base is used internally by the processor when it stores and manipulates the value of an integer variable?

  1. Octal
  2. Denary
  3. Hexadecimal
  4. Binary Correct answer.

Explanation

Digital circuits have two stable states, so all data is physically stored and processed as binary digits. Denary, hexadecimal and octal are only human-facing notations produced by conversion for display or source code.

Question 27Computer Science

A colour is stored using 8 bits for red, 8 bits for green and 8 bits for blue. How many distinct colours can be represented?

  1. 16 777 216 Correct answer.
  2. 256
  3. 24
  4. 8 388 608

Explanation

Each channel uses 8 bits giving 2^8 = 256 levels, and the three channels are independent, so the total is 256 × 256 × 256 = 2^24 = 16 777 216 colours. Multiplying the bit depths together instead of the value counts is a common error.

Question 28Computer Science

Which statement correctly describes the role of the program counter (PC) in the fetch-decode-execute cycle?

  1. It stores the instruction currently being decoded
  2. It holds the address of the next instruction to be fetched Correct answer.
  3. It holds the result of the arithmetic logic unit
  4. It counts how many instructions the program has run

Explanation

The program counter holds the memory address of the next instruction so the processor knows where to fetch from; it is then incremented. The instruction itself is held in the current instruction register, not the PC.

Question 29Computer Science

Which of these is an example of a system software component rather than application software?

  1. A photo-editing package
  2. An operating system kernel Correct answer.
  3. A web browser
  4. A spreadsheet used for budgeting

Explanation

System software manages and controls the hardware and provides a platform for other programs; the operating system kernel is the core example. Spreadsheets, browsers and photo editors are application software that perform tasks for the end user.

Question 30Computer Science

A student writes the denary value 45 in 8-bit two's complement form. Which bit pattern results?

  1. 11010010
  2. 00101101 Correct answer.
  3. 11010011
  4. 10101101

Explanation

Positive values in two's complement are stored as ordinary 8-bit binary: 32 + 8 + 4 + 1 = 45, giving 00101101. The leading 0 confirms the value is positive.

Question 31Computer Science

Which statement best defines a data type in a high-level language?

  1. The maximum number of characters a variable name may contain
  2. The order in which statements in a program are executed
  3. The set of values a variable may hold together with the operations permitted on them Correct answer.
  4. The physical memory address assigned to a variable at run time

Explanation

A data type determines which values are legal, how much storage is needed and which operations make sense, such as arithmetic on integers. It is a compile-time concept about meaning, not a memory address or naming rule.

Question 32Computer Science

Which HTML element is used to create a hyperlink to another page?

  1. <a> Correct answer.
  2. <img>
  3. <div>
  4. <p>

Explanation

The anchor element <a> with an href attribute defines a hyperlink to another resource. The other elements create a paragraph, embed an image, and group content for layout respectively.

Question 33Computer Science

Which of the following is a valid IPv4 address for a host on a network?

  1. 256.100.1.5
  2. 192.168.1.10 Correct answer.
  3. 192.168.1
  4. 192.168.1.10.20

Explanation

An IPv4 address consists of exactly four octets, each an integer from 0 to 255, so 192.168.1.10 is valid. Values above 255, too few octets, or too many octets break that rule.

Question 34Computer Science

A program stores the same value in a variable repeatedly inside a loop. Which construct is being used when the loop body runs a fixed number of times known in advance?

  1. A condition-controlled loop
  2. A recursive call
  3. An exception handler
  4. A count-controlled loop Correct answer.

Explanation

A count-controlled loop repeats a known number of times, typically using a FOR loop with a counter. A condition-controlled loop instead repeats until a Boolean test changes, which is not fixed in advance.

Question 35Computer Science

A linear search is performed on an unsorted list of 500 items and the target is the last element. How many comparisons are needed?

  1. 250
  2. 500 Correct answer.
  3. 1
  4. 9

Explanation

A linear search checks items one at a time from the start, so finding the last of 500 items requires 500 comparisons in the worst case. Binary search would need about 9 comparisons, but it requires sorted data.

Question 36Computer Science

A function is defined as f(n) = 3 × f(n − 1) with f(0) = 2. What is f(3)?

  1. 54 Correct answer.
  2. 6
  3. 18
  4. 162

Explanation

Applying the recurrence: f(1) = 3 × 2 = 6, f(2) = 3 × 6 = 18, f(3) = 3 × 18 = 54. Each step multiplies the previous result by 3, so the base case is reached three times.

Question 37Computer Science

In a stack, the operations push(A), push(B), push(C), pop(), push(D) are performed in order. Which item is on the top of the stack afterwards?

  1. C
  2. A
  3. D Correct answer.
  4. B

Explanation

A stack is last-in-first-out: after pushing A, B and C the top is C, the pop removes C, and pushing D leaves D on top. The remaining contents from bottom to top are A, B, D.

Question 38Computer Science

Which of these is a characteristic of a relational database that a flat-file system lacks?

  1. Each record is stored as a single line of text
  2. Tables can be linked through common keys to avoid storing redundant data Correct answer.
  3. The whole file must be rewritten to update one record
  4. Records can only be accessed in the order they were written

Explanation

Relational databases relate tables via primary and foreign keys, which removes duplication and supports queries across entities. Flat files store one record type per file and cannot enforce such relationships.

Question 39Computer Science

Which statement about the TCP and UDP transport protocols is correct?

  1. Neither TCP nor UDP uses port numbers
  2. TCP guarantees ordered delivery with acknowledgements, whereas UDP does not Correct answer.
  3. UDP guarantees ordered delivery, whereas TCP does not
  4. Both TCP and UDP retransmit lost segments

Explanation

TCP establishes a connection, numbers segments, acknowledges receipts and retransmits losses, so delivery order is guaranteed. UDP sends datagrams without acknowledgements, which suits streaming and DNS where speed matters more than reliability.

Question 40Computer Science

Which addressing mode does the instruction LOAD #25 use?

  1. Indirect addressing
  2. Indexed addressing
  3. Direct addressing
  4. Immediate addressing Correct answer.

Explanation

The # symbol denotes an immediate operand, so the value 25 is encoded in the instruction itself rather than being an address. Direct addressing names a memory location holding the operand.

Question 41Computer Science

A logic circuit output is 1 when at least two of its three inputs are 1, and 0 otherwise. Which gate implements this function?

  1. A majority function built from AND and OR gates Correct answer.
  2. A single 3-input XOR gate
  3. A single 3-input NOR gate
  4. A single 3-input NAND gate

Explanation

The required function is true for input combinations with two or three ones, which can be expressed as the OR of pairwise AND terms. A single XOR, NAND or NOR gate does not produce that truth table.

Question 42Computer Science

A file is compressed from 4 MB to 1 MB and later restored exactly to its original bytes. Which compression method was used?

  1. Encryption
  2. Lossy compression
  3. Lossless compression Correct answer.
  4. Run-length encoding with data discarded

Explanation

Exact restoration of the original bytes is only possible with lossless compression, which removes redundancy without discarding information. Lossy methods permanently discard detail and cannot reproduce the original exactly.

Question 43Computer Science

Which statement best describes the purpose of an operating system's scheduler?

  1. It decides which ready process receives CPU time and for how long Correct answer.
  2. It stores the file allocation table on the disk
  3. It translates source code into machine code before execution
  4. It resolves domain names into IP addresses

Explanation

The scheduler is part of process management and chooses among ready processes according to a policy such as round robin or priority. Compilation, name resolution and file-system metadata are handled by other components.

Question 44Computer Science

A program contains the assignment total ← total + 1 inside a loop but total is never initialised before the loop. Which category of error does this represent?

  1. A logic error that may produce an unpredictable result Correct answer.
  2. A syntax error detected by the parser
  3. A run-time error caused by division by zero
  4. A compile-time error caused by a missing semicolon

Explanation

The code is syntactically valid and may run, but using an uninitialised variable means the result is not what the programmer intended, which is a logic error. Syntax errors and division by zero are detected differently.

Question 45Computer Science

Which statement correctly distinguishes a compiler from an interpreter?

  1. An interpreter detects all syntax errors before any statement runs
  2. An interpreter produces a standalone executable file, while a compiler does not
  3. A compiler executes source code directly without translating it
  4. A compiler translates the whole program before execution, while an interpreter translates and executes line by line Correct answer.

Explanation

A compiler performs translation of the complete source into object code before the program runs, whereas an interpreter translates and runs statements one at a time. This explains why compilers report errors before execution and interpreters often stop at the first error encountered.

Question 46Computer Science

A network uses the subnet mask 255.255.255.0 with the address 192.168.4.37. Which address is the network address of this subnet?

  1. 192.168.4.37
  2. 192.168.4.255
  3. 192.168.4.0 Correct answer.
  4. 192.168.0.0

Explanation

The mask 255.255.255.0 keeps the first three octets as the network part, so the network address is 192.168.4.0. The broadcast address is 192.168.4.255 and the host address is 192.168.4.37.

Question 47Computer Science

A recursive binary search is applied to a sorted array of 1024 elements. What is the maximum number of recursive calls needed to determine whether a value is present?

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

Explanation

Each call halves the search space, so the number of calls is ceil(log2(1024)) + 1 = 10 + 1 = 11, including the final call on a one-element range. Halving continues until the range is empty or the item is found.

Question 48Computer Science

A hash function maps keys to indices 0–9. Keys 23, 33 and 43 all hash to index 3, and the table uses linear probing. Where is key 43 stored if keys are inserted in the order 23, 33, 43?

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

Explanation

Key 23 occupies index 3 and key 33 probes to index 4 because 3 is taken. Key 43 finds 3 and 4 occupied, so linear probing places it at the next free slot, index 5.

Question 49Computer Science

A database table is in first normal form but contains a partial dependency: a non-key attribute depends on only part of a composite primary key. Which normal form does the table violate?

  1. Second normal form Correct answer.
  2. Boyce-Codd normal form only
  3. Third normal form
  4. Fourth normal form

Explanation

Second normal form requires that no non-key attribute depend on part of a composite key, so a partial dependency is precisely a violation of 2NF. Third normal form then removes transitive dependencies between non-key attributes.

Question 50Computer Science

A processor executes 2 × 10^9 instructions per second and each instruction takes an average of 4 clock cycles. What is the approximate clock speed?

  1. 8 GHz Correct answer.
  2. 4 GHz
  3. 0.5 GHz
  4. 2 GHz

Explanation

Clock speed equals instructions per second multiplied by cycles per instruction: 2 × 10^9 × 4 = 8 × 10^9 cycles per second, or 8 GHz. Dividing instead of multiplying is the usual mistake.