ILTS Computer Science (205) study materials
ILTS Computer Science (205) study resources

ILTS Computer Science (205) practice questions

One question at a time. Build your ILTS Computer Science (205) 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 Fundamentals and Algorithms

Which data structure processes elements in last-in, first-out order?

  1. Stack Correct answer.
  2. Hash table
  3. Queue
  4. Binary search tree

Explanation

A stack restricts insertion and removal to one end (the top), so the most recently pushed element is the first one popped, which is LIFO behavior. Queues remove from the opposite end from insertion, giving FIFO order, and trees and hash tables do not impose LIFO access discipline.

Question 2Computer Science Fundamentals and Algorithms

What is the average-case 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

In a balanced BST each comparison discards roughly half the remaining nodes, so the height is about log base 2 of n and search follows one root-to-leaf path. That gives O(log n) comparisons on average. O(n) applies only to a degenerate, unbalanced tree.

Question 3Computer Science Fundamentals and Algorithms

A programmer needs constant-time average insertion and lookup by unique student ID, with no need to keep the records sorted. Which structure best fits?

  1. Singly linked list
  2. Sorted array
  3. Hash table Correct answer.
  4. Stack

Explanation

A hash table maps each key through a hash function to a bucket, giving average O(1) insertion and lookup when the load factor is controlled. The other structures require linear scans or, in the sorted-array case, shifting elements on insertion.

Question 4Computer Science Fundamentals and Algorithms

Which sorting algorithm is stable and has O(n log n) worst-case time complexity while using O(n) auxiliary space?

  1. Heapsort
  2. Quicksort
  3. Selection sort
  4. Merge sort Correct answer.

Explanation

Merge sort repeatedly divides the array and merges sorted halves, preserving the relative order of equal keys. Its recurrence yields O(n log n) in the worst case, and the merge step needs an auxiliary buffer proportional to n.

Question 5Computer Science Fundamentals and Algorithms

In a singly linked list, which operation requires O(n) time when only the head reference is available?

  1. Reading the head node's value
  2. Inserting a node at the head
  3. Appending a node at the tail Correct answer.
  4. Removing the head node

Explanation

Without a tail reference, appending must traverse every node to reach the last one, so it costs O(n). Head insertion, head removal, and reading the head all touch a constant number of references.

Question 6Computer Science Fundamentals and Algorithms

Which number base is used internally by virtually all modern general-purpose computers to represent integer data?

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

Explanation

Digital circuits have two reliable voltage states, so data is stored and processed in base 2, with each bit representing a power of two. Hexadecimal and octal are compact human notations for grouping those bits, and decimal is a display convention rather than the machine representation.

Question 7Computer Science Fundamentals and Algorithms

What is the decimal value of the unsigned binary number 101101?

  1. 45 Correct answer.
  2. 43
  3. 47
  4. 53

Explanation

The bits correspond to 32 + 0 + 8 + 4 + 0 + 1, which sums to 45. Each position is a power of two read from left to right starting at 2 to the fifth.

Question 8Computer Science Fundamentals and Algorithms

Which logic gate outputs 1 only when both of its inputs are 1?

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

Explanation

The AND gate produces a high output only for the input combination 1,1 and outputs 0 for the other three combinations. OR and XOR also output 1 when just one input is high, and NOR is the complement of OR.

Question 9Computer Science Fundamentals and Algorithms

A binary search is applied to the sorted array [2, 5, 8, 12, 16, 23, 38, 56, 72, 91] to find the value 23. Which element is compared first?

  1. 16
  2. 23 Correct answer.
  3. 38
  4. 12

Explanation

With ten elements the middle index is found as (0 + 9) divided by 2, which is 4, and the element at index 4 is 16. Since 23 is greater than 16, the search continues in the upper half.

Question 10Computer Science Fundamentals and Algorithms

Which statement correctly describes a difference between an array and a linked list?

  1. Arrays allow O(1) random access by index, while linked lists require traversal to reach an arbitrary position. Correct answer.
  2. Linked lists allow O(1) random access by index, while arrays require traversal.
  3. Linked lists store elements in contiguous memory, while arrays scatter elements across memory.
  4. Arrays must be allocated dynamically at run time, while linked lists always use static memory.

Explanation

Array elements occupy contiguous memory, so the address of any index is computed arithmetically in constant time. Linked list nodes are connected by references and may be scattered, so reaching position k requires following k links.

Question 11Computer Science Fundamentals and Algorithms

A recursive function has the recurrence T(n) = 2T(n/2) + n with T(1) = 1. What is its asymptotic complexity?

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

Explanation

The recurrence splits the problem into two halves of size n/2 and does linear work to combine them, which is the classic merge sort pattern. By the master theorem, log base 2 of 2 equals 1, matching the linear combining cost, so the result is O(n log n).

Question 12Computer Science Fundamentals and Algorithms

Which traversal of a binary search tree visits nodes in ascending key order?

  1. Preorder
  2. Level order
  3. Postorder
  4. Inorder Correct answer.

Explanation

An inorder traversal processes the left subtree, then the node, then the right subtree, and the BST property places smaller keys on the left and larger keys on the right. That sequence yields sorted ascending output. Preorder and postorder place the root before or after both subtrees, breaking the sort order.

Question 13Computer Science Fundamentals and Algorithms

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

  1. To compress the values into fewer bits for storage
  2. To sort the stored keys in ascending order
  3. To detect duplicate keys by comparing all entries
  4. To map a key to an index within the table's bucket range Correct answer.

Explanation

A hash function converts an arbitrary key into an integer that is reduced modulo the table size to select a bucket. Good hash functions spread keys uniformly to limit collisions. Sorting, compression, and full-table comparison are not their role.

Question 14Computer Science Fundamentals and Algorithms

A queue is implemented with a fixed-size circular array using front and rear indices. What happens when rear advances past the last slot?

  1. Rear wraps to index 0 using modular arithmetic Correct answer.
  2. The queue is automatically cleared
  3. All elements are shifted left by one position
  4. The array is resized to double its capacity

Explanation

A circular buffer reuses freed slots by computing the next index as (rear + 1) modulo capacity, so the queue continues without shifting elements. This keeps enqueue and dequeue operations O(1). Resizing or clearing would discard the efficiency the design provides.

Question 15Computer Science Fundamentals and Algorithms

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

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

Explanation

Selection sort scans the unsorted portion to find the minimum and exchanges it with the first unsorted position, growing the sorted prefix by one element per pass. It performs O(n squared) comparisons regardless of input order.

Question 16Computer Science Fundamentals and Algorithms

Using two's complement with 8 bits, what is the decimal value of the bit pattern 11110110?

  1. -9
  2. 246
  3. -10 Correct answer.
  4. -11

Explanation

The leading bit is 1, so the value is negative. Inverting the bits gives 00001001, which is 9, and adding 1 gives 10, so the pattern represents -10. The unsigned reading of 246 is irrelevant because the sign bit is set.

Question 17Computer Science Fundamentals and Algorithms

Which Boolean expression is equivalent to the XOR of inputs A and B?

  1. A AND B
  2. A OR B
  3. NOT (A OR B)
  4. (A OR B) AND NOT (A AND B) Correct answer.

Explanation

XOR is true when exactly one input is true, which equals being in the union of A and B while excluding the case where both are true. The expression (A OR B) AND NOT (A AND B) captures exactly that condition.

Question 18Computer Science Fundamentals and Algorithms

What is the main advantage of a doubly linked list over a singly linked list?

  1. It supports O(1) removal of a node given only a reference to that node Correct answer.
  2. It guarantees O(1) indexed access
  3. It uses less memory per node
  4. It automatically keeps nodes sorted

Explanation

Each node stores a back pointer, so removing a referenced node can update its predecessor without a traversal. The trade-off is extra memory for the previous pointer. Neither list supports constant-time indexing or automatic sorting.

Question 19Computer Science Fundamentals and Algorithms

A programmer writes a loop that sums the first n integers by adding one element per iteration. What is the loop's time complexity?

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

Explanation

The loop body executes once for each value from 1 through n, so the number of operations grows linearly with n. The closed-form formula n(n+1)/2 would give constant time, but the described loop performs n additions.

Question 20Computer Science Fundamentals and Algorithms

Which property must a binary tree satisfy to be classified as a binary search tree?

  1. All keys in the left subtree are less than the node's key and all keys in the right subtree are greater Correct answer.
  2. Every node has exactly two children
  3. The height of the tree is always logarithmic in the number of nodes
  4. The tree is complete at every level

Explanation

The defining invariant is the ordering relation between a node and every key in its subtrees, which enables logarithmic search when the tree is balanced. Structural properties such as fullness or balance are separate concerns and are not required for the BST definition.

Question 21Computer Science Fundamentals and Algorithms

An algorithm processes a list of n items by, for each item, scanning the entire list once. What is its time complexity?

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

Explanation

An outer loop over n items combined with an inner scan over n items performs on the order of n times n operations. This nested-loop pattern is characteristic of quadratic algorithms such as selection sort. Exponential growth requires branching recursion rather than nested iteration.

Question 22Computer Science Fundamentals and Algorithms

A hash table with 100 slots stores 75 entries and uses chaining. What is the load factor?

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

Explanation

Load factor is the number of stored entries divided by the number of buckets, so 75 divided by 100 equals 0.75. Values above 1 indicate more entries than buckets and typically trigger resizing.

Question 23Computer Science Fundamentals and Algorithms

Why does a naive recursive computation of the Fibonacci sequence run in exponential time?

  1. Because it uses too much stack memory for each call
  2. Because it recomputes the same subproblems many times without storing results Correct answer.
  3. Because integer addition is a linear-time operation
  4. Because the recursion depth exceeds the number of bits in an integer

Explanation

Each call branches into two smaller calls, and identical subproblems such as fib(n-2) are solved repeatedly, so the call tree grows exponentially. Memoization or an iterative approach reduces the work to linear time by caching results.

Question 24Computer Science Fundamentals and Algorithms

A min-heap stores 15 elements. Where is the smallest element located, and what is the worst-case cost of finding the largest element?

  1. Smallest at the root; largest found in O(1) by reading the last array slot
  2. Smallest at the root; largest found in O(n) by scanning all elements Correct answer.
  3. Smallest at a leaf; largest at the root
  4. Smallest at the root; largest found in O(log n) by following right children

Explanation

The heap property guarantees only that each parent is no larger than its children, so the minimum sits at the root. The maximum can be any leaf, and there are roughly n/2 leaves, so locating it requires examining all elements in the worst case.

Question 25Computer Science Fundamentals and Algorithms

Which statement about the master theorem case in which the combining cost f(n) dominates the recursive term is correct?

  1. The master theorem cannot be applied when f(n) is polynomial
  2. The solution is Theta of the recursive term when f(n) is smaller
  3. The solution is always Theta of n log n regardless of f(n)
  4. The solution is Theta of f(n) when f(n) grows polynomially faster than n raised to log base b of a Correct answer.

Explanation

When the work done outside the recursive calls grows by a polynomial factor faster than the number of leaves, the total cost is dominated by the top-level combining work. The solution is then Theta of f(n). The other cases cover balanced growth and leaf-dominated growth.

Question 26Computer Science Fundamentals and Algorithms

A stack is used to evaluate the postfix expression 6 2 3 * - 4 +. Assuming single-digit operands and standard integer arithmetic, what value does the evaluation produce?

  1. -4
  2. 4 Correct answer.
  3. 16
  4. 8

Explanation

Scanning left to right, push 6, 2, and 3; the '*' pops 2 and 3 to give 6, which is pushed. The '-' then pops 6 and 2 and pushes 2 minus 6 equals -4. Finally 4 is pushed and '+' combines -4 and 4 to yield 0... wait, correcting: the operands are 6 and 6, so 6 - 6 = 0, then 0 + 4 = 4.

Question 27Computer Science Fundamentals and Algorithms

In Big-O notation, which growth rate dominates all the others as n becomes very large?

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

Explanation

Exponential growth outpaces every polynomial and logarithmic function, so O(2^n) eventually exceeds O(n^2), O(n log n), and O(log n) for sufficiently large n. The ordering by dominance is logarithmic, linear-times-log, quadratic, then exponential.

Question 28Computer Science Fundamentals and Algorithms

A binary tree has 31 nodes and is perfectly balanced with every internal node having exactly two children. What is its height measured in edges from the root to the deepest leaf?

  1. 30
  2. 4 Correct answer.
  3. 5
  4. 15

Explanation

A perfect binary tree with height h (edges) contains 2^(h+1) - 1 nodes. Setting 2^(h+1) - 1 = 31 gives 2^(h+1) = 32, so h + 1 = 5 and h = 4.

Question 29Computer Science Fundamentals and Algorithms

Which algorithm-design strategy does merge sort primarily use to achieve its O(n log n) worst-case running time?

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

Explanation

Merge sort splits the array into halves, recursively sorts each half, and merges the sorted halves, which is the divide-and-conquer pattern. The recurrence T(n) = 2T(n/2) + O(n) reflects that structure.

Question 30Computer Science Fundamentals and Algorithms

A hash table uses open addressing with linear probing. The table has 11 slots, and the hash function is h(k) = k mod 11. Keys 22, 33, and 44 are inserted in that order. In which slot does key 44 finally reside?

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

Explanation

Key 22 hashes to slot 0 and is placed there. Key 33 hashes to slot 0, is occupied, and probes to slot 1. Key 44 also hashes to slot 0, probes past 0 and 1, and lands in slot 2.

Question 31Computer Science Fundamentals and Algorithms

Which statement best describes the worst-case time complexity of quicksort and the reason for it?

  1. O(log n), because recursion depth is bounded by the logarithm of n
  2. O(n), because each element is compared once
  3. O(n log n), because the array is always split in half
  4. O(n^2), because a poor pivot choice can produce highly unbalanced partitions Correct answer.

Explanation

Quicksort's worst case is O(n^2), which occurs when the pivot is consistently the smallest or largest element, yielding partitions of size 0 and n-1. The average case is O(n log n) only because partitions are typically reasonably balanced.

Question 32Computer Science Fundamentals and Algorithms

A directed graph is stored as an adjacency matrix with V vertices. What is the space complexity of this representation, and what is the cost to test whether a single edge (u, v) exists?

  1. O(V) space and O(V) edge lookup
  2. O(V + E) space and O(1) edge lookup
  3. O(V^2) space and O(V) edge lookup
  4. O(V^2) space and O(1) edge lookup Correct answer.

Explanation

An adjacency matrix allocates a V-by-V grid regardless of edge count, so it uses O(V^2) space. Checking edge (u, v) is a single indexed access to cell [u][v], which is O(1).

Question 33Computer Science Fundamentals and Algorithms

Dijkstra's algorithm is run on a weighted graph that contains an edge with a negative weight. Which statement about the algorithm's behavior is correct?

  1. It may return incorrect distances because a finalized vertex is never reconsidered Correct answer.
  2. It automatically switches to the Bellman-Ford strategy
  3. It still returns correct shortest paths because it relaxes every edge
  4. It fails only if the negative edge lies on a cycle

Explanation

Dijkstra's algorithm assumes that once a vertex is extracted with the minimum tentative distance, that distance is final. A negative edge can later provide a shorter route to an already-finalized vertex, which the algorithm never revisits, so results may be wrong.

Question 34Computer Science Fundamentals and Algorithms

Which technique allows a dynamic-programming solution to avoid recomputing overlapping subproblems?

  1. Splitting the input into independent halves
  2. Storing subproblem results in a table for reuse Correct answer.
  3. Choosing the locally best option at each step
  4. Randomizing pivot selection during partitioning

Explanation

Dynamic programming exploits overlapping subproblems by memoizing or tabulating results so each distinct subproblem is solved once. This trades extra memory for reduced time.

Question 35Computer Science Fundamentals and Algorithms

A program must repeatedly retrieve the minimum element from a collection while new elements are being inserted. Which data structure gives the best combination of insertion and minimum-extraction performance?

  1. Hash table
  2. Binary min-heap Correct answer.
  3. Singly linked list
  4. Sorted array

Explanation

A binary min-heap supports insertion and minimum extraction in O(log n) while keeping the minimum at the root in O(1). A sorted array makes extraction cheap but insertion O(n), and the other structures do not maintain a minimum ordering.

Question 36Computer Science Fundamentals and Algorithms

Which statement correctly characterizes the difference between breadth-first search and depth-first search on an unweighted graph?

  1. BFS finds shortest paths in edge count, while DFS may find longer paths first Correct answer.
  2. DFS always visits fewer vertices than BFS
  3. DFS uses a queue, while BFS uses a stack
  4. BFS cannot detect cycles, while DFS can

Explanation

BFS explores vertices in order of distance from the source, so the first time it reaches a vertex it has found a path with the fewest edges. DFS follows one branch deeply and may reach a vertex by a longer route before finding the shortest one.

Question 37Computer Science Fundamentals and Algorithms

A Boolean function of two inputs A and B outputs 1 only when the inputs differ. Which standard gate implements this function?

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

Explanation

The XOR gate outputs 1 when exactly one input is 1, which is precisely the condition that the inputs differ. Its truth table gives 1 for (0,1) and (1,0) and 0 for (0,0) and (1,1).

Question 38Computer Science Fundamentals and Algorithms

A process must be scheduled among several runnable processes on a single CPU. Which scheduling policy is non-preemptive by definition?

  1. Round robin
  2. Shortest remaining time first
  3. Multilevel feedback queue
  4. First-come, first-served Correct answer.

Explanation

First-come, first-served lets each process run to completion or until it voluntarily blocks, so it does not forcibly interrupt a running process. The other listed policies rely on preemption triggered by time slices or newly arriving shorter jobs.

Question 39Computer Science Fundamentals and Algorithms

A page-reference string is processed with 3 physical frames under the FIFO page-replacement policy. The reference string is 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5, starting with empty frames. How many page faults occur?

  1. 9 Correct answer.
  2. 7
  3. 10
  4. 8

Explanation

The first three references fault to fill the frames. FIFO then evicts the oldest page each time a new page is needed: faults occur on 1, 2, 3, 4, 1, 2, 5, 3, and 4, totaling 9. The later references to 1, 2, and 5 hit because those pages are still resident.

Question 40Computer Science Fundamentals and Algorithms

In relational database theory, which statement correctly describes third normal form (3NF)?

  1. All foreign keys must reference the primary key of another relation
  2. The relation contains no repeating groups and every row is unique
  3. Every determinant is a candidate key, eliminating transitive dependencies on non-keys Correct answer.
  4. Every non-key attribute depends on the whole primary key and nothing else

Explanation

A relation is in 3NF when it is in 2NF and no non-prime attribute is transitively dependent on a candidate key, equivalently every non-trivial determinant is a candidate key. This removes dependencies of non-key attributes on other non-key attributes.

Question 41Programming and Software Development

In Java, which access modifier makes a field visible only to code inside the same class?

  1. protected
  2. public
  3. private Correct answer.
  4. default (no modifier)

Explanation

A private member is accessible only within the body of the class that declares it, which is the tightest access level Java offers. Protected also grants package and subclass access, while default grants package-wide access.

Question 42Programming and Software Development

A recursive method lacks a proper base case. What runtime outcome should a developer expect?

  1. The compiler rejects the method because recursion requires a base case
  2. The call stack keeps growing until a stack overflow error is thrown Correct answer.
  3. The JVM silently converts the recursion into a loop
  4. The method returns null once the stack limit is reached

Explanation

Each recursive call pushes a new frame onto the call stack, and without a terminating base case the frames accumulate until the stack space is exhausted. The JVM then throws a StackOverflowError, which is an Error rather than an ordinary exception.

Question 43Programming and Software Development

Which data structure provides last-in, first-out ordering for its elements?

  1. Stack Correct answer.
  2. Heap
  3. Queue
  4. Hash table

Explanation

A stack pushes and pops at the same end, so the most recently added element is the first removed. This LIFO discipline is what makes stacks suitable for call management and expression evaluation.

Question 44Programming and Software Development

What is the primary purpose of version control in a software project?

  1. Measuring code coverage of the test suite
  2. Tracking changes to files over time so revisions can be reviewed and restored Correct answer.
  3. Compiling source files into executable binaries
  4. Enforcing coding style during the build

Explanation

Version control records the history of changes, allowing developers to inspect, compare, and revert to earlier revisions. It also supports collaboration through branching and merging rather than build or analysis tasks.

Question 45Programming and Software Development

In an object-oriented design, what does encapsulation primarily achieve?

  1. Letting one interface stand for several unrelated concrete types
  2. Sharing a single method name across classes with different parameter lists
  3. Hiding internal state behind methods that control how it is read or changed Correct answer.
  4. Allowing a subclass to replace a parent method with a new implementation

Explanation

Encapsulation bundles data with the operations that act on it and restricts direct access to that data. Accessors and mutators then enforce invariants and hide representation details from clients.

Question 46Programming and Software Development

Which of the following is an example of a primitive data type in most general-purpose programming languages?

  1. Array
  2. String
  3. Object
  4. Integer Correct answer.

Explanation

Integer types such as int store a single numeric value directly and are primitive in languages like Java, C, and C#. Arrays, strings, and objects are composite or reference types built from simpler values.

Question 47Programming and Software Development

In a relational database, what does a primary key guarantee about a table?

  1. Each row is uniquely identified and the key columns cannot be null Correct answer.
  2. Queries on the table return rows in insertion order
  3. Every column in the table has a default value
  4. Each foreign key in the table references a valid parent row

Explanation

A primary key enforces both uniqueness and non-nullness on the designated column or columns. That combination lets each row be identified unambiguously by its key value.

Question 48Programming and Software Development

A program computes the sum of the first n integers with a single loop. What is its time complexity?

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

Explanation

The loop body executes once per value from 1 through n, so the running time grows linearly with n. The closed-form formula would be O(1), but the stated loop performs n iterations.

Question 49Programming and Software Development

A developer writes a loop that should run while a counter is less than 10, but the counter is never incremented inside the loop. What defect results?

  1. A null pointer exception on the first iteration
  2. An off-by-one error that skips the last iteration
  3. A syntax error caught at compile time
  4. An infinite loop that never terminates on its own Correct answer.

Explanation

Because the loop condition never becomes false, the body repeats indefinitely and the program fails to make progress. Fixing it requires updating the counter within the loop body or revising the condition.

Question 50Programming and Software Development

A class declares a method that accepts a parameter of type List<String> and calls add on it. What design principle does this violate if the method should not modify the caller's collection?

  1. It should declare the parameter as private to hide it from callers
  2. It should return void so the list is not exposed
  3. It should make the method static so callers cannot pass a list
  4. It should accept an unmodifiable or read-only view to prevent unintended mutation Correct answer.

Explanation

Passing a mutable collection by reference lets the method alter the caller's data, which can cause surprising side effects. Accepting a read-only interface or defensive copy documents and enforces the no-modification contract.