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 1Computational Thinking and Algorithms
Which of the following best defines an algorithm?
- A programming language used to write software
- A finite sequence of unambiguous steps that transforms input into output Correct answer.
- A graphical representation of a database schema
- A physical device that stores data permanently
Explanation
An algorithm is an ordered, finite set of well-defined instructions that takes some input and produces a result. Its defining properties include finiteness, definiteness, and effectiveness, independent of any particular language or machine.
Question 2Computational Thinking and Algorithms
What is the time complexity of binary search on a sorted array of n elements?
- O(log n) Correct answer.
- O(n)
- O(n log n)
- O(1)
Explanation
Binary search halves the search interval at each step, so the number of comparisons grows with the logarithm of the input size. After k steps the remaining interval has size n/2^k, giving O(log n) total work.
Question 3Computational Thinking and Algorithms
A stack data structure follows which access discipline?
- Last in, first out Correct answer.
- First in, first out
- Priority-ordered removal
- Random access by index
Explanation
A stack pushes and pops at the same end, so the most recently added element is the first removed. This last-in-first-out behavior is what distinguishes it from a queue.
Question 4Computational Thinking and Algorithms
Which sorting algorithm repeatedly compares adjacent elements and swaps them when out of order?
- Quick sort
- Heap sort
- Bubble sort Correct answer.
- Merge sort
Explanation
Bubble sort makes repeated passes over the list, swapping neighboring elements that are out of order until no swaps remain. This local adjacent comparison is its signature behavior.
Question 5Computational Thinking and Algorithms
In a flowchart, which symbol conventionally represents a decision?
- A rectangle
- A parallelogram
- A diamond Correct answer.
- An oval
Explanation
A diamond denotes a decision point where the flow branches based on a condition. Rectangles show processes, parallelograms show input or output, and ovals mark start or end.
Question 6Computational Thinking and Algorithms
What does the Big-O notation O(n^2) describe about an algorithm?
- An upper bound on growth rate as input size increases Correct answer.
- The exact number of operations performed
- The memory used regardless of input size
- The fastest possible running time for any input
Explanation
Big-O expresses an asymptotic upper bound on how resource usage grows with input size, ignoring constant factors. It characterizes the growth class rather than an exact operation count.
Question 7Computational Thinking and Algorithms
A queue is best described by which behavior?
- Elements are always removed by largest value
- Elements are removed in the same order they arrived Correct answer.
- Elements are removed in the reverse order they arrived
- Elements are accessed only at both ends simultaneously
Explanation
A queue enqueues at the rear and dequeues from the front, producing first-in-first-out order. This matches fair, arrival-order processing such as print jobs or task scheduling.
Question 8Computational Thinking and Algorithms
Which of these is a defining characteristic that every valid algorithm must satisfy?
- It must run in constant time
- It must terminate after a finite number of steps Correct answer.
- It must be written in a high-level language
- It must use recursion
Explanation
Finiteness requires that an algorithm halt after a bounded number of steps for valid input. Language, recursion, and speed are implementation choices, not definitional requirements.
Question 9Computational Thinking and Algorithms
An algorithm makes one pass through an array of n elements, performing constant work per element. What is its time complexity?
- O(1)
- O(n) Correct answer.
- O(log n)
- O(n^2)
Explanation
Visiting each of n elements once with constant work per visit gives total work proportional to n. Therefore the growth is linear, written O(n).
Question 10Computational Thinking and Algorithms
A sorted list contains 1024 elements. Approximately how many comparisons does binary search need in the worst case?
- 10 Correct answer.
- 1024
- 32
- 512
Explanation
Binary search needs about log2(n) comparisons, and log2(1024) equals 10. Each comparison halves the remaining interval, so ten halvings reduce 1024 to one.
Question 11Computational Thinking and Algorithms
What is the primary purpose of a hash table?
- To keep keys in sorted order for range queries
- To guarantee worst-case constant-time operations
- To map keys to values with average constant-time lookup Correct answer.
- To store elements in a balanced tree structure
Explanation
A hash function converts a key into an index, letting a hash table locate entries in expected O(1) time. It trades ordering for fast average-case insertion, deletion, and lookup.
Question 12Computational Thinking and Algorithms
A recursive function solves a problem of size n by making two recursive calls on size n-1. What recurrence best describes its time?
- T(n) = 2T(n-1) + O(1) Correct answer.
- T(n) = T(n-1) + O(1)
- T(n) = T(n/2) + O(1)
- T(n) = 2T(n/2) + O(n)
Explanation
Two calls each of size n-1 plus constant overhead yields T(n) = 2T(n-1) + O(1), which expands to exponential time. The coefficient counts the calls and the argument shows how size shrinks.
Question 13Computational Thinking and Algorithms
In a binary search tree with distinct keys, where is the smallest key located?
- At the leftmost node Correct answer.
- At the rightmost node
- At the root node
- In the last inserted node
Explanation
The binary search tree property places all smaller keys in the left subtree, so following left children from the root reaches the minimum. The maximum is found symmetrically by following right children.
Question 14Computational Thinking and Algorithms
Which statement correctly describes merge sort's behavior?
- It builds a heap and extracts elements one at a time
- It divides the list, sorts halves recursively, then merges them Correct answer.
- It repeatedly selects the minimum and moves it to the front
- It partitions in place around a pivot and needs no extra array
Explanation
Merge sort splits the array into halves, sorts each recursively, and merges the sorted halves into order. This divide-and-conquer structure yields O(n log n) time in all cases but requires auxiliary space.
Question 15Computational Thinking and Algorithms
A student writes a loop that runs while a counter starts at 0 and increments by 1 until it is less than n. How many times does the loop body execute?
- 2n times
- n - 1 times
- n + 1 times
- n times Correct answer.
Explanation
The counter takes values 0 through n-1, and each value triggers one execution before the condition fails at n. Counting those values gives exactly n iterations.
Question 16Computational Thinking and Algorithms
What is the main advantage of a linked list over an array for frequent insertions at the front?
- It uses less memory per element than an array
- It keeps elements sorted automatically
- It inserts at the front in constant time without shifting elements Correct answer.
- It provides constant-time random access by index
Explanation
Inserting at the head of a linked list only requires updating a few pointers, so it costs O(1). An array must shift all existing elements, costing O(n) per front insertion.
Question 17Computational Thinking and Algorithms
Which problem is a classic example of a problem solved by dynamic programming?
- Checking whether a number is even
- Sorting an array of integers in place
- Computing the nth Fibonacci number without recomputing subproblems Correct answer.
- Finding the shortest path in a weighted graph with negative edges
Explanation
Dynamic programming stores results of overlapping subproblems so each is computed once, as with memoized Fibonacci. This avoids the exponential recomputation of naive recursion.
Question 18Computational Thinking and Algorithms
A graph has 5 vertices and is a simple cycle. How many edges does it contain?
- 25
- 5 Correct answer.
- 4
- 10
Explanation
A simple cycle visits every vertex once and returns to the start, so a cycle on n vertices has exactly n edges. With 5 vertices, that means 5 edges.
Question 19Computational Thinking and Algorithms
A sorted array of 1000 elements is searched with binary search. About how many comparisons are needed in the worst case?
- About 1000
- About 500
- About 10 Correct answer.
- About 100
Explanation
Binary search performs roughly log2(n) comparisons, and log2(1000) is just under 10. Each comparison halves the interval, so around ten halvings reduce 1000 to one.
Question 20Computational Thinking and Algorithms
An algorithm's running time satisfies T(n) = 2T(n/2) + n. What is its asymptotic complexity?
- O(n^2)
- O(log n)
- O(n)
- O(n log n) Correct answer.
Explanation
By the master theorem, a = 2, b = 2, and f(n) = n, so n^(log_b a) = n matches f(n), giving O(n log n). This is the classic merge sort recurrence.
Question 21Computational Thinking and Algorithms
What is the worst-case time complexity of quick sort, and when does it occur?
- O(n), when the array is already sorted
- O(log n), when all elements are equal
- O(n^2), when the pivot is consistently the smallest or largest element Correct answer.
- O(n log n), when the pivot splits the array evenly
Explanation
Quick sort degrades to O(n^2) when each partition is maximally unbalanced, such as always choosing the minimum or maximum as pivot. Sorted input with a naive first-element pivot produces exactly this case.
Question 22Computational Thinking and Algorithms
A hash table with n keys uses a hash function that maps every key to the same bucket. What is the resulting average lookup time?
- O(n) Correct answer.
- O(n^2)
- O(log n)
- O(1)
Explanation
When all keys collide into one bucket, the table degenerates into a single list that must be scanned. Lookup then costs linear time in the number of stored keys, O(n).
Question 23Computational Thinking and Algorithms
Which statement about a breadth-first search from a source vertex in an unweighted graph is correct?
- It finds shortest paths in terms of edge count from the source Correct answer.
- It requires a stack to track frontier vertices
- It always visits vertices in alphabetical order
- It cannot detect cycles in the graph
Explanation
Breadth-first search explores vertices in order of increasing distance, so the first time a vertex is reached gives its minimum edge count from the source. A queue manages the frontier to preserve this level-by-level order.
Question 24Computational Thinking and Algorithms
An algorithm solves a problem by trying every possible subset of n items to find the best valid one. What is its time complexity?
- O(n log n)
- O(2^n) Correct answer.
- O(log n)
- O(n^2)
Explanation
There are 2^n subsets of an n-element set, and evaluating each one costs at least constant time. Enumerating all subsets therefore takes exponential time, O(2^n).
Question 25Computational Thinking and Algorithms
Which algorithmic technique builds a solution by solving overlapping subproblems once and storing each result for later reuse?
- Divide and conquer
- Dynamic programming Correct answer.
- Greedy choice
- Brute-force enumeration
Explanation
Dynamic programming exploits overlapping subproblems by storing each subproblem's result in a table, so it is never recomputed. This memoization or tabulation turns exponential naive recursion into polynomial time for problems with optimal substructure.
Question 26Computational Thinking and Algorithms
In a stack, which element is removed by a pop operation?
- A uniformly random element
- The element most recently pushed Correct answer.
- The element with the largest value
- The element pushed first
Explanation
A stack follows last-in, first-out order, so the top of the stack, which is the most recently pushed element, is the one removed. Push and pop both act at the same end of the structure.
Question 27Computational Thinking and Algorithms
Which traversal of a binary tree visits the root, then the entire left subtree, then the entire right subtree?
- Postorder
- Inorder
- Level order
- Preorder Correct answer.
Explanation
Preorder traversal processes a node before its children, giving the order root, left subtree, right subtree. This ordering is useful for copying a tree or producing a prefix expression.
Question 28Computational Thinking and Algorithms
A function calls itself with a smaller input on every call and stops when the input reaches a base value. Which term describes this structure?
- Recursion Correct answer.
- Memoization
- Backtracking
- Iteration
Explanation
Recursion occurs when a function invokes itself on a smaller instance of the same problem, relying on a base case to terminate. Each recursive call must move toward that base case to avoid infinite descent.
Question 29Computational Thinking and Algorithms
What does an abstract data type specify about a collection such as a list?
- The programming language required to use it
- Its operations and their behavior, not their implementation Correct answer.
- The exact CPU instructions used by each operation
- Its memory layout on the target machine
Explanation
An abstract data type defines a set of values and the operations on them, together with the behavior of those operations, while hiding how they are implemented. Any concrete data structure that satisfies the contract can realize the type.
Question 30Computational Thinking and Algorithms
An algorithm performs n comparisons on an input of size n, and each comparison costs constant time. What is its time complexity?
- O(n) Correct answer.
- O(log n)
- O(n^2)
- O(1)
Explanation
When a constant-cost operation is repeated n times, the total cost grows linearly with n, which is written O(n). The constant factor is dropped in asymptotic notation.
Question 31Computational Thinking and Algorithms
A loop runs for i from 0 to n-1, and inside it a second loop runs for j from 0 to n-1. Each inner step costs constant time. What is the total time complexity?
- O(n^2) Correct answer.
- O(2^n)
- O(n)
- O(n log n)
Explanation
The outer loop executes n times, and for each outer iteration the inner loop executes n times, giving n multiplied by n constant-cost steps. The product is n^2, so the complexity is O(n^2).
Question 32Computational Thinking and Algorithms
A binary search tree stores distinct integer keys. Which traversal outputs the keys in ascending sorted order?
- Reverse preorder
- Preorder
- Postorder
- Inorder Correct answer.
Explanation
In a binary search tree every key in a node's left subtree is smaller than the node's key and every key in its right subtree is larger. An inorder traversal visits left subtree, node, then right subtree, which therefore emits the keys in ascending order.
Question 33Computational Thinking and Algorithms
A min-heap stores its elements in an array. Where is the smallest element located?
- At index 0, the root Correct answer.
- In the middle of the array
- It depends on insertion order
- At the last occupied index
Explanation
A min-heap maintains the heap property that every parent is less than or equal to its children, so the minimum must be at the root, which is stored at index 0. The remaining elements are only partially ordered.
Question 34Computational Thinking and Algorithms
What is the worst-case time complexity of insertion sort on an array of n elements?
- O(n^2) Correct answer.
- O(log n)
- O(n)
- O(n log n)
Explanation
Insertion sort inserts each element into its correct position among the previously sorted elements, shifting larger elements to the right. When the input is in reverse order, each insertion shifts all earlier elements, giving about n^2/2 shifts in total, so the worst case is O(n^2).
Question 35Computational Thinking and Algorithms
A hash table uses separate chaining, and its load factor is alpha. Assuming a good hash function, what is the expected time for an unsuccessful search?
- O(n log n)
- O(alpha^2)
- O(1 + alpha) Correct answer.
- O(log n)
Explanation
With separate chaining, an unsuccessful search must examine every element in the bucket chosen by the hash function. The average chain length equals the load factor alpha, so the expected cost is constant plus alpha, written O(1 + alpha).
Question 36Computational Thinking and Algorithms
What is the time complexity of Dijkstra's algorithm when implemented with a binary heap on a graph with V vertices and E edges?
- O(E^2)
- O(V log E)
- O(V^2)
- O((V + E) log V) Correct answer.
Explanation
Using a binary heap, Dijkstra's algorithm performs V extract-min operations and up to E decrease-key operations, each costing O(log V). Summing these gives O((V + E) log V).
Question 37Computational Thinking and Algorithms
Which property must a problem have for a greedy algorithm to be guaranteed to find an optimal solution?
- A hash function that distributes states uniformly
- A Hamiltonian path in its state graph
- The greedy-choice property together with optimal substructure Correct answer.
- Overlapping subproblems together with a polynomial-time verifier
Explanation
A greedy algorithm is correct when a locally optimal choice can be extended to a globally optimal solution, which is the greedy-choice property, and when optimal solutions contain optimal subsolutions, which is optimal substructure. Without both properties, greedy choices can be suboptimal.
Question 38Computational Thinking and Algorithms
A sorting algorithm must be comparison-based and stable. Which algorithm satisfies both requirements?
- Heap sort
- Merge sort Correct answer.
- Quick sort with median-of-three pivot
- Selection sort
Explanation
Merge sort compares elements and, when merging, takes from the left run on ties, which preserves the relative order of equal keys and makes it stable. Its worst-case time is O(n log n).
Question 39Computational Thinking and Algorithms
Which statement about the halting problem is correct?
- The halting problem is decidable for programs that use loops
- No algorithm can decide, for every program and input, whether the program halts Correct answer.
- A program that halts can always be detected by its source code length
- Every program can be shown to halt by simulating it for a fixed number of steps
Explanation
Turing proved that no general algorithm can decide halting for every program-input pair; the problem is undecidable. A proof by contradiction constructs a program whose behavior contradicts any supposed decider.
Question 40Computational Thinking and Algorithms
A problem is in NP. What does this guarantee about the problem?
- A proposed solution can be verified in polynomial time Correct answer.
- The problem is undecidable
- The problem can be solved in polynomial time
- The problem requires exponential time in the worst case
Explanation
NP is the class of decision problems for which a yes answer has a certificate that can be checked in polynomial time. Membership in NP does not imply that the problem itself is solvable in polynomial time.
Question 41Programming and Software Development
Which data structure removes the most recently added element first?
- Queue
- Stack Correct answer.
- Priority queue
- Binary search tree
Explanation
A stack follows last-in-first-out ordering, so the element pushed most recently is the one popped next. A queue instead removes the oldest element, and a priority queue removes by key rather than insertion time.
Question 42Programming and Software Development
A variable declared inside a function body without any storage keyword has which lifetime and visibility?
- Static lifetime, initialized once
- Local to the function, lifetime limited to each call Correct answer.
- Visible in the whole file, lifetime limited to each call
- Global lifetime, visible everywhere
Explanation
An ordinary local variable is created when the function is entered and destroyed when it returns, and its name is only visible inside that block. Persisting a value between calls requires an explicit static or module-level declaration.
Question 43Programming and Software Development
What does a compiler do that an interpreter typically does not?
- Store variables in memory during execution
- Detect runtime errors before execution begins
- Translate the whole program into another form before execution Correct answer.
- Execute source code line by line without producing output files
Explanation
A compiler translates an entire program into a target form such as machine code or bytecode ahead of execution. An interpreter instead processes the program incrementally while it runs.
Question 44Programming and Software Development
In most programming languages, which operator has higher precedence?
- Addition
- Logical OR
- Assignment
- Multiplication Correct answer.
Explanation
Multiplicative operators bind more tightly than additive ones, so multiplication is evaluated before addition. Assignment has very low precedence, and logical OR is lower still.
Question 45Programming and Software Development
What is the main purpose of a version control system?
- Enforcing code style automatically
- Allocating memory to running programs
- Tracking changes to files over time Correct answer.
- Compiling source files into executables
Explanation
Version control records successive changes to files so that history can be inspected, compared, and restored. It does not build programs or manage runtime memory.
Question 46Programming and Software Development
Which of these is a primitive data type in most statically typed languages?
- Linked list
- Record
- Boolean Correct answer.
- Array
Explanation
A Boolean is a basic built-in type holding one of two truth values and needs no composition. Arrays, records, and linked lists are composite types built from other values.
Question 47Programming and Software Development
What does the expression 17 % 5 evaluate to?
- 3
- 3.4
- 12
- 2 Correct answer.
Explanation
The modulo operator returns the remainder after integer division. Since 17 divided by 5 is 3 with remainder 2, the result is 2.
Question 48Programming and Software Development
Which term describes a function that calls itself to solve a smaller instance of the same problem?
- Generic
- Iterative
- Recursive Correct answer.
- Virtual
Explanation
A recursive function solves a problem by invoking itself on a reduced input until a base case is reached. Iterative solutions use loops instead of self-invocation.
Question 49Programming and Software Development
A loop condition is checked before the body runs. For what values of n does the loop `while (n < 3) { n = n + 1; }` execute its body zero times if n starts as an integer?
- n less than 0 only
- n greater than or equal to 3 Correct answer.
- n equal to 0 only
- n equal to 2 only
Explanation
A pre-test loop evaluates the condition before any iteration, so the body is skipped whenever the condition is already false. The condition n < 3 is false exactly when n is 3 or larger.
Question 50Programming and Software Development
What is printed by the following pseudocode? `x = 5; y = 2; x = y; y = 10; print x`
- 10
- 5
- 2 Correct answer.
- 7
Explanation
Assignment copies the current value of the right-hand side into the variable on the left. After x = y, x holds 2, and the later change to y does not affect x for simple value types.