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 Content Knowledge
In a Java program, which construct is the most appropriate when a block of code must execute exactly once regardless of whether an exception is thrown inside a try block?
- A catch block
- A throw statement
- A finally block Correct answer.
- A try-with-resources declaration
Explanation
A finally block is designed to run whether or not an exception occurs, and even when the try block exits via return. It is the standard Java mechanism for guaranteed cleanup code. Catch blocks execute only when a matching exception is thrown, so they do not guarantee execution.
Question 2Computer Science Content Knowledge
A programmer declares an array of 50 integers in a language with zero-based indexing. What is the valid index range for accessing elements of this array?
- 1 through 50
- 0 through 49 Correct answer.
- 0 through 50
- 1 through 49
Explanation
With zero-based indexing, the first element has index 0 and the last element of an array of length n has index n-1. For 50 elements the indices therefore run from 0 to 49. Accessing index 50 would be out of bounds.
Question 3Computer Science Content Knowledge
Which number base is used internally by virtually all modern digital computers to represent and process data?
- Base 2 Correct answer.
- Base 16
- Base 8
- Base 10
Explanation
Digital circuits have two stable states, so data is stored and manipulated in binary, which is base 2. Hexadecimal and octal appear in programming as compact notations but are converted to binary internally. Decimal is the human-facing base, not the machine's.
Question 4Computer Science Content Knowledge
In a relational database, which property of a candidate key ensures that no two rows can share the same value for that key?
- Normalization
- Referential integrity
- Atomicity
- Uniqueness Correct answer.
Explanation
Uniqueness is the constraint that guarantees each value of a candidate key identifies at most one row. A primary key is a chosen candidate key that is both unique and not null. The other listed properties address different concerns such as value granularity, foreign-key consistency, and schema design.
Question 5Computer Science Content Knowledge
Which protocol translates human-readable domain names such as example.org into IP addresses?
- SMTP
- DNS Correct answer.
- DHCP
- FTP
Explanation
The Domain Name System resolves hostnames to IP addresses so clients can reach servers. DHCP assigns network configuration to hosts, FTP transfers files, and SMTP sends mail. None of those perform name resolution.
Question 6Computer Science Content Knowledge
A software team wants a version control workflow in which each developer works on an isolated copy of the full repository history and commits locally before sharing changes. Which model fits this requirement?
- A single shared network folder
- Manual file-copy backup
- Distributed version control Correct answer.
- Centralized version control
Explanation
Distributed version control systems such as Git give every developer a complete local repository, so commits and history are available offline. Centralized systems require a connection to a single server for commits. Copying files or sharing a folder provides no history or branching.
Question 7Computer Science Content Knowledge
Which Boolean expression is equivalent to the negation of (A AND B)?
- A OR B
- NOT A OR NOT B Correct answer.
- A AND B
- NOT A AND NOT B
Explanation
De Morgan's law states that the negation of a conjunction equals the disjunction of the negations, so NOT (A AND B) equals (NOT A) OR (NOT B). The expression NOT A AND NOT B instead equals NOT (A OR B). The remaining options drop the negations entirely.
Question 8Computer Science Content Knowledge
Which of the following best describes the role of an operating system's scheduler?
- It converts source code into machine instructions
- It stores files in directory hierarchies
- It allocates CPU time among ready processes Correct answer.
- It maps virtual addresses to physical memory
Explanation
The scheduler decides which ready process or thread receives the CPU and for how long, implementing policies such as round-robin or priority scheduling. Address translation is handled by memory management hardware and the OS memory manager. File organization and compilation belong to other subsystems.
Question 9Computer Science Content Knowledge
A binary search is applied to a sorted array of 1,000 elements. Approximately how many comparisons are needed in the worst case?
- 10 Correct answer.
- 1,000
- 100
- 500
Explanation
Binary search halves the remaining search space with each comparison, so the worst case is about log base 2 of n. Since 2^10 is 1,024, roughly 10 comparisons suffice for 1,000 elements. Linear scanning would require up to 1,000 comparisons.
Question 10Computer Science Content Knowledge
What is the value of the postfix expression 5 3 2 * + ?
- 13
- 30
- 16
- 11 Correct answer.
Explanation
In postfix evaluation, operands are pushed and each operator pops two values. Here 3 and 2 are multiplied to give 6, then 5 and 6 are added to give 11. Reading the tokens as infix would produce a different result and is incorrect for postfix notation.
Question 11Computer Science Content Knowledge
A recursive method lacks a proper base case. What is the most likely runtime outcome?
- The compiler rejects the program
- The method returns zero
- The loop counter resets
- The call stack overflows Correct answer.
Explanation
Without a base case the recursion never terminates, and each call consumes stack space until the stack limit is exceeded, producing a stack overflow error. Compilation usually succeeds because the syntax is valid. Returning zero or resetting a counter does not follow from missing termination.
Question 12Computer Science Content Knowledge
A queue is used to manage print jobs on a shared printer. Which ordering behavior does this structure provide?
- Last in, first out
- First in, first out Correct answer.
- Random selection
- Highest priority first by default
Explanation
A queue enforces first-in, first-out order, so jobs are printed in the sequence they arrived. A stack would give last-in, first-out behavior. Priority ordering requires a separate priority queue structure rather than a plain queue.
Question 13Computer Science Content Knowledge
Which statement correctly distinguishes a class from an object in object-oriented programming?
- A class can hold data, while an object cannot
- A class is a runtime instance, while an object is its blueprint
- A class exists only at compile time, while an object exists only in source code
- A class defines structure and behavior, while an object is an instance of that class Correct answer.
Explanation
A class is the definition that specifies fields and methods, and an object is a concrete instance created from that definition at runtime. Objects hold their own copies of instance data, while the class describes the shared structure. The other options reverse or misstate this relationship.
Question 14Computer Science Content Knowledge
A superclass reference variable is assigned an object of a subclass that overrides a method. When the overridden method is called through that reference, which version executes?
- Neither version, because the call is ambiguous
- The subclass version, resolved at runtime by dynamic dispatch Correct answer.
- A compiler error occurs because the types differ
- The superclass version, because the variable type is the superclass
Explanation
Dynamic dispatch selects the method implementation based on the actual object type at runtime, not the declared reference type. This is the basis of polymorphism in languages such as Java. The call is well defined as long as the method signature exists in the superclass.
Question 15Computer Science Content Knowledge
Which SQL clause is used to filter rows after grouping has been performed?
- HAVING Correct answer.
- GROUP BY
- ORDER BY
- WHERE
Explanation
HAVING filters groups produced by GROUP BY, so it can reference aggregate results such as COUNT or SUM. WHERE filters individual rows before grouping and cannot test aggregates in that position. ORDER BY sorts results and GROUP BY forms the groups.
Question 16Computer Science Content Knowledge
An IPv4 address is written as 192.168.10.5. How many bits does an IPv4 address contain?
- 32 Correct answer.
- 128
- 16
- 64
Explanation
An IPv4 address consists of four octets, each 8 bits, for a total of 32 bits. IPv6 uses 128 bits, which is why the other large values appear as plausible distractors. The dotted-decimal notation is simply a human-readable form of those 32 bits.
Question 17Computer Science Content Knowledge
A programmer writes a loop that increments an index by one and accesses an array of length n using the condition index <= n. What defect does this introduce?
- A type mismatch between index and element
- An off-by-one error causing an out-of-bounds access Correct answer.
- An infinite loop that never terminates
- A syntax error detected by the compiler
Explanation
With zero-based indexing the valid maximum index is n-1, so allowing index equal to n accesses one element past the end of the array. This classic off-by-one defect causes an out-of-bounds error. The loop still terminates and the code is syntactically valid.
Question 18Computer Science Content Knowledge
Which sorting algorithm has an average-case time complexity of O(n log n) and sorts in place without requiring additional arrays proportional to n?
- Insertion sort
- Merge sort
- Quicksort Correct answer.
- Counting sort
Explanation
Quicksort partitions the array in place and averages O(n log n) comparisons. Merge sort also achieves O(n log n) but typically requires O(n) auxiliary space. Insertion sort is quadratic on average, and counting sort needs extra storage keyed to the value range.
Question 19Computer Science Content Knowledge
Two processes each hold one resource and each waits for the resource held by the other. Which condition does this situation illustrate?
- Thrashing
- Deadlock Correct answer.
- Starvation
- Race condition
Explanation
Deadlock occurs when processes form a circular wait and none can proceed because each holds a resource the other needs. Starvation means indefinite postponement without a cycle, and thrashing refers to excessive paging. A race condition concerns unsynchronized access to shared data.
Question 20Computer Science Content Knowledge
Which statement accurately describes the difference between the Internet and the World Wide Web?
- The Web is the physical infrastructure and the Internet is the software layer
- They are two names for the same network
- The Internet is the global network of networks, while the Web is a service that runs on it Correct answer.
- The Internet is limited to email, while the Web handles all other traffic
Explanation
The Internet is the underlying global interconnection of networks using the TCP/IP protocol suite. The World Wide Web is one application layered on top of it, using HTTP and hyperlinks. Other Internet services such as email and file transfer exist independently of the Web.
Question 21Computer Science Content Knowledge
A student needs to represent the decimal value 13 in an 8-bit unsigned binary format. Which bit pattern is correct?
- 00001110
- 00001011
- 00010011
- 00001101 Correct answer.
Explanation
The value 13 equals 8 plus 4 plus 1, so the bits for places 8, 4, and 1 are set, giving 00001101. Checking the place values confirms the sum. The other patterns correspond to different decimal values.
Question 22Computer Science Content Knowledge
A hash table stores n keys in a table of size m, and the number of collisions grows sharply as n approaches m. What does the load factor n/m measure?
- The average number of probes per insertion
- The maximum key value stored
- The number of distinct hash functions used
- The proportion of table slots that are occupied Correct answer.
Explanation
The load factor is the ratio of stored entries to available slots, indicating how full the table is. A high load factor raises collision probability and probe lengths, which is why implementations resize when it exceeds a threshold. It is not a count of probes, functions, or key magnitudes.
Question 23Computer Science Content Knowledge
A binary tree has nodes inserted in this order into a binary search tree: 50, 30, 70, 20, 40, 60, 80. Which node is visited last during an in-order traversal?
- 50
- 20
- 70
- 80 Correct answer.
Explanation
An in-order traversal of a binary search tree visits nodes in ascending key order, so the last node visited is the maximum key. In this tree the maximum is 80, found in the rightmost position. The root 50 is visited in the middle of the traversal.
Question 24Computer Science Content Knowledge
A program repeatedly appends elements to a dynamic array that doubles its capacity when full. What is the amortized cost of each append operation?
- O(log n)
- O(n log n)
- O(n)
- O(1) Correct answer.
Explanation
Although an individual append that triggers resizing costs O(n), the doubling strategy spreads that work across many cheap appends. Summing the copy costs over n appends yields O(n) total, so the amortized cost per append is constant. This is why dynamic arrays are efficient for appends.
Question 25Computer Science Content Knowledge
A sender transmits data using a sliding window protocol with a window size of 4 and stop-and-wait disabled. If acknowledgments are delayed, what is the maximum number of unacknowledged frames the sender may have outstanding?
- 8
- 1
- 4 Correct answer.
- Unlimited
Explanation
The window size bounds how many frames may be in flight before an acknowledgment is required. With a window of 4, at most 4 unacknowledged frames may be outstanding. A size of 1 would describe stop-and-wait behavior instead.
Question 26Computer Science Content Knowledge
In a relational database, which key uniquely identifies each row in a table and cannot contain null values?
- Primary key Correct answer.
- Alternate key
- Foreign key
- Composite key
Explanation
A primary key is the column or set of columns chosen to uniquely identify every row, and the relational model forbids null values in it. Foreign keys instead reference another table, alternate keys are candidate keys not chosen as primary, and composite keys are simply multi-column keys that may or may not be primary.
Question 27Computer Science Content Knowledge
A network device forwards frames only to the port on which the destination MAC address was last seen. Which device performs this behavior?
- Router
- Layer 2 switch Correct answer.
- Repeater
- Hub
Explanation
A Layer 2 switch builds a MAC address table by learning source addresses and then forwards each frame only out the port associated with the destination MAC. Routers make decisions using IP addresses, while hubs and repeaters simply regenerate signals to all ports.
Question 28Computer Science Content Knowledge
Which data structure provides last-in, first-out access and is used for function call management?
- Graph
- Queue
- Stack Correct answer.
- Linked list
Explanation
A stack supports push and pop at one end, so the most recently added item is removed first. Runtime systems use a call stack to store return addresses and local frames for nested function calls.
Question 29Computer Science Content Knowledge
In a programming language, which construct repeats a block of statements a known number of times using an explicit counter?
- A while loop
- A switch statement
- A try block
- A for loop Correct answer.
Explanation
A for loop typically combines initialization, a continuation test, and an update step, making it suited to a counted repetition. A while loop repeats on a condition without a built-in counter, and switch and try are selection and exception-handling constructs.
Question 30Computer Science Content Knowledge
What is the decimal value of the hexadecimal number 2F?
- 63
- 45
- 47 Correct answer.
- 31
Explanation
The digit 2 is in the sixteens place, giving 32, and F has value 15 in the ones place. Adding 32 and 15 yields 47.
Question 31Computer Science Content Knowledge
Which of the following is an example of application software rather than system software?
- A boot loader
- A word processor Correct answer.
- A file system manager
- A device driver
Explanation
Application software performs tasks for the end user, and a word processor is a clear example. Device drivers, file system managers, and boot loaders are all components of the operating system that manage hardware and resources.
Question 32Computer Science Content Knowledge
Which logic gate outputs 1 only when both of its inputs are 1?
- AND Correct answer.
- OR
- XOR
- NOR
Explanation
The AND gate produces a true output only for the input combination 1,1. OR and XOR also output 1 when exactly one input is 1, and NOR is the inverse of OR.
Question 33Computer Science Content Knowledge
A program stores a list of student names and must insert a new name at the front of the list many times while the total size stays small. Which structure most directly supports efficient insertion at the front?
- Binary search tree ordered by name
- Static array of fixed capacity
- Singly linked list with a head reference Correct answer.
- Hash table keyed by name
Explanation
With a head reference, inserting at the front of a singly linked list requires only creating a node and redirecting one pointer, which is constant time. A static array would shift every existing element, and the other structures do not target front insertion.
Question 34Computer Science Content Knowledge
A function is defined recursively as f(0) = 1 and f(n) = n * f(n - 1) for n > 0. What does f compute?
- The nth Fibonacci number
- The sum of integers from 1 to n
- The nth power of 2
- The factorial of n Correct answer.
Explanation
The recurrence multiplies n by the result for n - 1 down to the base case 1, which is exactly the definition of n factorial. Fibonacci adds two earlier terms, the sum adds rather than multiplies, and powers of 2 would use a constant base.
Question 35Computer Science Content Knowledge
A database table has a column that frequently appears in WHERE clauses on equality comparisons and holds mostly distinct values. Which index choice is most appropriate?
- No index, because indexes always slow queries
- A hash index on that column Correct answer.
- A clustered index on an unrelated column
- A full table scan on every query
Explanation
A hash index maps each key to a bucket, giving near-constant-time equality lookups on high-cardinality columns. It does not support range queries, but the described workload uses equality only, so it fits well.
Question 36Computer Science Content Knowledge
A TCP sender uses a sliding window and has sent bytes 1 through 5. It receives an acknowledgment for byte 3. What does this acknowledgment indicate under cumulative acknowledgment?
- Bytes 1 through 5 must be retransmitted
- The connection should be closed
- Bytes 1 through 3 arrived and byte 4 is expected next Correct answer.
- Only byte 3 arrived safely
Explanation
TCP acknowledgments are cumulative, so acknowledging byte 3 means all bytes up to and including 3 were received. The sender can slide its window forward and next expects byte 4.
Question 37Computer Science Content Knowledge
A process holds a lock on resource X and requests a lock on resource Y, while another process holds Y and requests X. Which condition for deadlock does this directly illustrate?
- Mutual exclusion only
- Lack of preemption only
- Circular wait Correct answer.
- Starvation
Explanation
Each process waits for a resource held by the other, forming a cycle in the wait-for graph, which is the circular wait condition. Mutual exclusion and no-preemption are also present, but the cycle is what the scenario directly shows.
Question 38Computer Science Content Knowledge
A class declares a private field and provides public getter and setter methods for it. Which object-oriented principle does this arrangement primarily support?
- Inheritance
- Overloading
- Polymorphism
- Encapsulation Correct answer.
Explanation
Encapsulation hides internal state behind a controlled interface, and accessors let the class validate or transform values before they are read or changed. Inheritance, polymorphism, and overloading concern type relationships and method resolution rather than data hiding.
Question 39Computer Science Content Knowledge
A student evaluates the expression (6 + 2) * 3 - 4 / 2 using standard operator precedence. What is the result?
- 20
- 10
- 22 Correct answer.
- 16
Explanation
Parentheses give 8, multiplication gives 24, and division gives 2, so 24 - 2 equals 22. Applying precedence incorrectly by evaluating left to right without regard to operators would produce other values.
Question 40Computer Science Content Knowledge
A subnet mask of 255.255.255.192 is applied to a network. How many usable host addresses does each subnet provide?
- 30
- 62 Correct answer.
- 126
- 64
Explanation
The mask leaves 6 host bits, since 192 is 11000000 and the last octet contributes 6 zero bits. Two to the sixth power is 64 total addresses, and subtracting the network and broadcast addresses leaves 62 usable hosts.
Question 41Computer Science Content Knowledge
A compiler reports a syntax error in a source file. At which stage of compilation is the error detected?
- Code optimization
- Lexical analysis
- Linking
- Parsing Correct answer.
Explanation
The parser checks whether the token stream conforms to the grammar of the language, so malformed statement structure is reported there. Lexical analysis only forms tokens, while optimization and linking operate on already-valid intermediate or object code.
Question 42Computer Science Content Knowledge
An algorithm's running time satisfies T(n) = 2T(n/2) + n for n greater than 1, with T(1) = 1. What is the asymptotic complexity?
- O(n)
- O(log n)
- O(n squared)
- O(n log n) Correct answer.
Explanation
This recurrence describes two subproblems of half the size plus linear work to combine them, as in merge sort. The recursion tree has log n levels, each contributing n work, giving O(n log n).
Question 43Computer Science Content Knowledge
A programmer wants to store key-value pairs and retrieve a value in average constant time without caring about ordering. Which structure is the best fit?
- Hash table Correct answer.
- Sorted array
- Binary search tree
- Stack
Explanation
A hash table computes a bucket index from the key, giving average O(1) insertion and lookup when the load factor is controlled. Sorted arrays and search trees give logarithmic lookup, and a stack offers no keyed access.
Question 44Computer Science Content Knowledge
Which statement best describes how a relational database enforces referential integrity?
- It stores duplicate rows to preserve history
- It requires every column to be indexed
- It rejects a foreign key value that does not match any existing primary key in the referenced table Correct answer.
- It automatically sorts rows by primary key
Explanation
Referential integrity requires each foreign key value to correspond to an existing key in the referenced table, or be null when permitted. The database rejects inserts or updates that would leave a dangling reference unless a cascading action is defined.
Question 45Computer Science Content Knowledge
A system uses 12-bit addresses and a direct-mapped cache with 16 blocks, each holding 4 bytes. How many bits of the address form the block offset?
- 6
- 2 Correct answer.
- 4
- 8
Explanation
A block of 4 bytes requires 2 offset bits because two bits address 4 distinct byte positions. The remaining bits split between the block index and the tag, but the offset is determined solely by block size.
Question 46Computer Science Content Knowledge
A deterministic finite automaton must accept all binary strings that contain an even number of 1s and end with 0. What is the minimum number of states needed?
- 6
- 3
- 4 Correct answer.
- 2
Explanation
The machine must track the parity of 1s (two possibilities) and whether the most recent symbol was 0 (two possibilities), giving four reachable combinations. No smaller automaton can distinguish these cases, so four states are required.
Question 47Computer Science Content Knowledge
A database transaction reads a row, another transaction modifies and commits that row, and the first transaction then writes based on its earlier read. Which anomaly does this describe?
- Nonrepeatable read
- Lost update Correct answer.
- Phantom read
- Dirty read
Explanation
A lost update occurs when two transactions read the same value and one overwrites the other's committed change, so one update is effectively erased. Dirty reads and nonrepeatable reads involve reading uncommitted or changing data, and phantom reads involve new rows matching a predicate.
Question 48Computer Science Content Knowledge
A binary search tree is built by inserting the keys 10, 20, 30, 40, and 50 in that order. What is the height of the resulting tree when height is counted as the number of edges on the longest root-to-leaf path?
- 2
- 3
- 4 Correct answer.
- 5
Explanation
Each new key is larger than all previous keys, so every insertion becomes the right child of the current maximum. The keys form a chain of five nodes, which has four edges on the longest path.
Question 49Computer Science Content Knowledge
A pipelined processor executes five stages with a clock period limited by the slowest stage at 4 ns. Ignoring hazards, what is the throughput once the pipeline is full?
- One instruction every 4 ns Correct answer.
- One instruction every 8 ns
- One instruction every 20 ns
- One instruction every 0.8 ns
Explanation
In a full pipeline, one instruction completes per clock cycle, and the clock period is set by the slowest stage. With a 4 ns period, throughput is one instruction every 4 ns even though latency is about 20 ns.
Question 50Computer Science Content Knowledge
A programmer writes a boolean expression in which a value is compared with a threshold using the operator == when the intent is to test whether the value is greater than or equal to the threshold. Which category of error does this mistake represent?
- A syntax error, because the comparison operator is not valid in a boolean expression
- A runtime error, because the comparison fails while the program is executing
- A logic error, because the program compiles and runs but produces incorrect results Correct answer.
- A linker error, because the operator cannot be resolved to a library symbol
Explanation
A logic error occurs when the code is syntactically valid and executes without crashing, yet the implemented behavior differs from the intended behavior. Using == instead of >= is a well-formed comparison, so the compiler accepts it and no exception is raised; only the computed result is wrong. Detecting this class of defect requires testing against expected outcomes rather than relying on compiler or runtime diagnostics.