SQU IT Exit study materials
SQU IT Exit study resources

SQU IT Exit practice questions

One question at a time. Build your SQU IT Exit 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 1Programming Fundamentals and Problem Solving

In a C-style language, a variable of type int is declared inside a function without any initializer. What is the value of that variable immediately after the declaration?

  1. Indeterminate, because automatic variables are not initialized Correct answer.
  2. A null reference, because the variable has no object
  3. Zero, because all variables are zero-initialized
  4. The compiler rejects the declaration as a syntax error

Explanation

Local (automatic) variables in C-style languages are not automatically initialized, so reading one before assigning a value yields an indeterminate result. Static and global variables are the ones that get zero-initialized by default. The rule matters because relying on uninitialized storage is a common source of nondeterministic bugs.

Question 2Programming Fundamentals and Problem Solving

A loop is written as 'for (int i = 0; i < n; i++) { total += a[i]; }'. Which statement best describes how many times the loop body executes when n equals 5?

  1. Six times, for indices 0 through 5
  2. Five times, for indices 0 through 4 Correct answer.
  3. A number of times that depends on the array contents
  4. Four times, for indices 1 through 4

Explanation

The condition i < n is checked before each iteration, so the body runs for i = 0, 1, 2, 3, 4 and stops when i reaches 5. That is exactly n iterations for a zero-based index. The array contents never affect the iteration count because the condition depends only on i and n.

Question 3Programming Fundamentals and Problem Solving

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

  1. Queue
  2. Heap
  3. Graph
  4. Stack Correct answer.

Explanation

A stack pushes and pops at the same end, so the most recently added element is the first removed, which is last-in, first-out behavior. A queue instead removes the oldest element first. Choosing the right structure determines the order in which pending work is processed.

Question 4Programming Fundamentals and Problem Solving

What is the primary purpose of a function in a program?

  1. To convert source code into machine instructions before execution
  2. To package a named, reusable unit of behavior that can take inputs and return a result Correct answer.
  3. To store persistent data between separate runs of the program
  4. To guarantee that the program uses less memory at run time

Explanation

A function groups statements under a name so the logic can be called repeatedly with different arguments, which supports reuse and abstraction. Memory savings and compilation are separate concerns handled by other mechanisms. Persistence across runs requires files or databases, not functions.

Question 5Programming Fundamentals and Problem Solving

An expression evaluates to true only when both operands are true. Which logical operator produces this behavior?

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

Explanation

The AND operator yields true only for the combination true AND true, and false for every other combination. OR yields true when at least one operand is true, and XOR yields true when exactly one is true. NOT is unary and simply inverts a single operand.

Question 6Programming Fundamentals and Problem Solving

Which statement correctly describes the difference between a syntax error and a runtime error?

  1. A syntax error violates the grammar and is detected before execution, while a runtime error occurs during execution Correct answer.
  2. Both are detected by the parser before any code runs
  3. A syntax error occurs only at run time, while a runtime error is caught by the parser
  4. A runtime error always prevents the program from being compiled

Explanation

Syntax errors break the grammar of the language, so the parser rejects the program before it can run. Runtime errors, such as division by zero or a failed lookup, only surface while the program is executing. This distinction guides whether a developer fixes the code structure or adds runtime handling.

Question 7Programming Fundamentals and Problem Solving

A function is documented to compute the average of a list of numbers. Which input should be tested first to expose a likely edge-case defect?

  1. A list containing the value zero among other numbers
  2. An empty list Correct answer.
  3. A list of two equal numbers
  4. A list of ten positive integers

Explanation

Averaging divides the sum by the number of elements, so an empty list forces a division by zero or an undefined result. Edge cases at the boundaries of valid input are where defects concentrate. Lists with several ordinary values exercise the normal path but rarely reveal boundary problems.

Question 8Programming Fundamentals and Problem Solving

A recursive function has no base case. What is the most likely outcome when it is called?

  1. It recurses until the call stack is exhausted and the program fails Correct answer.
  2. It returns the value zero after a fixed number of calls
  3. It compiles but never executes any statement
  4. It automatically converts itself into an iterative loop

Explanation

A base case is the condition that stops the recursion; without one, each call adds a new frame to the call stack. Eventually the stack space is exhausted and the program terminates with a stack overflow. The runtime does not rewrite recursion into iteration or supply a default return value.

Question 9Programming Fundamentals and Problem Solving

A developer writes a loop that scans an array of n elements once, doing constant work per element. What is the time complexity of this loop?

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

Explanation

The number of operations grows linearly with the input size because every element is visited exactly once. Constant work inside the loop does not change the growth rate. This is why a single pass over a collection is described as linear time.

Question 10Programming Fundamentals and Problem Solving

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

  1. About 32
  2. About 10 Correct answer.
  3. About 512
  4. About 1024

Explanation

Binary search halves the remaining search range on each comparison, so the worst case is about log base 2 of the input size. Since 2 to the tenth power is 1024, roughly ten comparisons suffice. Linear scanning would instead require up to 1024 comparisons.

Question 11Programming Fundamentals and Problem Solving

What does it mean for a sorting algorithm to be stable?

  1. The algorithm always runs in linear time
  2. Elements that compare as equal keep their original relative order Correct answer.
  3. The algorithm produces the same output regardless of input order
  4. The algorithm never uses additional memory

Explanation

Stability concerns equal keys: a stable sort preserves the order in which equal elements appeared in the input. This matters when records are sorted by one field after being sorted by another. Stability is independent of time complexity and memory use.

Question 12Programming Fundamentals and Problem Solving

A function receives a large list and modifies it in place, and the caller observes the changes afterward. What does this illustrate?

  1. Pass-by-value semantics, where the function receives an independent copy
  2. Type coercion, where the list is converted to another type
  3. Pass-by-reference semantics, where the function works on the caller's object Correct answer.
  4. Lazy evaluation, where the list is computed only when read

Explanation

When changes made inside the function are visible to the caller, the function is operating on the same underlying object rather than a copy. This is reference semantics, whether achieved through explicit references or through references passed by value. Pass-by-value would leave the caller's data unchanged.

Question 13Programming Fundamentals and Problem Solving

A developer needs to look up values by a unique key many times and wants average constant-time access. Which structure best fits this requirement?

  1. Sorted linked list
  2. Hash table Correct answer.
  3. Binary search tree
  4. Stack

Explanation

A hash table maps keys to buckets via a hash function, giving average O(1) lookup when keys are well distributed. A sorted linked list requires linear scanning, and a balanced tree gives logarithmic lookup. A stack supports only last-in, first-out access and no keyed lookup.

Question 14Programming Fundamentals and Problem Solving

In a language with short-circuit evaluation, how is the expression 'a != 0 && b / a > 2' evaluated when a equals 0?

  1. The whole expression evaluates to true by default
  2. The expression is rejected at compile time because a can be zero
  3. Both operands are evaluated and a division-by-zero error occurs
  4. The right operand is skipped because the left operand is false Correct answer.

Explanation

Short-circuit AND stops evaluating as soon as the left operand is false, because the result cannot become true. Here a != 0 is false, so the division is never performed. This idiom is a standard way to guard against division by zero.

Question 15Programming Fundamentals and Problem Solving

A program must read a file and then close it even if an error occurs during reading. Which construct best expresses this requirement?

  1. A while loop that retries the read until it succeeds
  2. A global variable that records whether the file is open
  3. A recursive function that reopens the file on each call
  4. A try/finally or equivalent scope-based cleanup block Correct answer.

Explanation

A try/finally block (or a language's scope-based resource management) guarantees that the cleanup runs whether the body succeeds or throws. This keeps resource release independent of the error path. Retry loops and global flags do not guarantee cleanup on exceptional exit.

Question 16Programming Fundamentals and Problem Solving

Two functions are written to compute the same result, but one sorts the input first and the other does not. What property must hold for the outputs to be considered equivalent?

  1. The result must not depend on the order of the input elements Correct answer.
  2. The functions must run in the same amount of time
  3. The input must always be sorted before either function is called
  4. Both functions must use the same sorting algorithm internally

Explanation

If sorting the input cannot change the result, the computation is order-independent, so both versions agree on every input. Requiring callers to pre-sort merely hides the difference. Internal algorithm choice and running time are irrelevant to output equivalence.

Question 17Programming Fundamentals and Problem Solving

A nested loop runs an outer loop n times and, for each outer iteration, an inner loop n times. What is the total number of inner-loop body executions?

  1. n plus n
  2. Two raised to the power n
  3. n multiplied by n Correct answer.
  4. n

Explanation

For each of the n outer iterations the inner loop performs n executions, so the counts multiply to n squared. Adding the loop counts would only be correct if the loops ran sequentially rather than nested. This multiplication is why nested loops over the same input are quadratic.

Question 18Programming Fundamentals and Problem Solving

A variable declared inside a block is referenced after the block ends. What kind of problem does this typically cause?

  1. A type error, because the variable's type changes at the block boundary
  2. A scope violation, because the name is not visible outside the block Correct answer.
  3. A performance problem, because the variable stays in memory
  4. No problem at all, because block scope is only a style convention

Explanation

Block scope limits a name's visibility to the region where it was declared, so referencing it afterward is a compile-time error in statically checked languages. The variable's lifetime and visibility end with the block. Scope is enforced by the language, not merely a stylistic guideline.

Question 19Programming Fundamentals and Problem Solving

A loop is meant to sum the integers from 1 to 10 inclusive, but it is written as 'for (i = 1; i < 10; i++)'. What defect does this introduce?

  1. An off-by-one error that omits the final value, 10 Correct answer.
  2. An infinite loop because the condition never becomes false
  3. A type error because i is compared with a constant
  4. A syntax error because the loop lacks a body

Explanation

The condition i < 10 stops the loop when i reaches 10, so the value 10 is never added to the sum. Using i <= 10 would include it. This is the classic off-by-one boundary mistake, and it produces a plausible but incorrect total.

Question 20Programming Fundamentals and Problem Solving

Which practice most directly reduces the chance that a function's caller misunderstands what arguments it accepts?

  1. Making the function as long as possible so all logic is in one place
  2. Documenting the preconditions and validating arguments at the function boundary Correct answer.
  3. Relying on callers to read the implementation before calling
  4. Removing all comments so the code speaks for itself

Explanation

Stating preconditions and checking them at the boundary makes the contract explicit and fails fast on misuse. Long functions and missing documentation increase the chance of misunderstanding. Callers should not have to reverse-engineer behavior from implementation details.

Question 21Programming Fundamentals and Problem Solving

A memoized recursive function stores each computed result the first time it is produced. What is the main benefit of this technique?

  1. Repeated subproblems are answered from the cache instead of being recomputed Correct answer.
  2. The recursion depth is reduced to a constant
  3. The function no longer needs a base case
  4. The function becomes immune to stack overflow

Explanation

Memoization trades memory for time by caching results keyed on the arguments, so overlapping subproblems are solved once. It does not shorten the recursion depth or remove the need for a base case. Stack overflow can still occur if the recursion goes too deep.

Question 22Programming Fundamentals and Problem Solving

Two algorithms solve the same problem: one runs in O(n log n) time and the other in O(n squared) time. For very large inputs, which conclusion is justified?

  1. The O(n log n) algorithm grows more slowly and is preferable for large inputs Correct answer.
  2. The O(n squared) algorithm is always faster because it has fewer operations
  3. The O(n log n) algorithm uses no memory at all
  4. Both algorithms take identical time for all input sizes

Explanation

Asymptotic notation describes growth rate as input size increases, and n log n grows far more slowly than n squared. For large inputs the slower-growing algorithm wins, though constants and memory can matter for small inputs. Complexity classes say nothing about memory use being zero.

Question 23Programming Fundamentals and Problem Solving

A developer replaces a linear search in a sorted array with binary search but forgets that the array is no longer guaranteed to be sorted after updates. What is the likely consequence?

  1. The search becomes faster but still correct
  2. The array automatically re-sorts itself before each search
  3. Binary search may return an incorrect result because its precondition is violated Correct answer.
  4. Binary search degrades gracefully into a correct linear search

Explanation

Binary search relies on the ordering invariant to decide which half can be discarded, so unsorted data can cause the target to be skipped entirely. The algorithm does not detect the violation or fall back to linear scanning. Maintaining the sort order after updates is therefore part of the contract.

Question 24Programming Fundamentals and Problem Solving

A function mutates a shared global counter that many other functions also read and write. Why does this make reasoning about the program harder?

  1. Global variables are always slower to read than local variables
  2. Global state prevents the program from being compiled at all
  3. The compiler cannot type-check any function that reads a global
  4. The counter creates hidden coupling, so a function's behavior depends on call order and other code Correct answer.

Explanation

Shared mutable state means a function's result depends on what other code did to the counter earlier, so behavior is no longer determined by its arguments alone. This hidden coupling makes testing and reasoning difficult. The concern is semantic, not a matter of compilation or typing.

Question 25Programming Fundamentals and Problem Solving

A recursive function computes Fibonacci numbers as f(n) = f(n-1) + f(n-2) with base cases f(0) = 0 and f(1) = 1, without caching. Why does its running time grow exponentially?

  1. Each call allocates a new array whose size doubles on every level
  2. The function sorts its inputs before each recursive call
  3. The base cases are evaluated once per level of recursion
  4. Each call spawns two overlapping subproblems, so the same values are recomputed many times Correct answer.

Explanation

The naive recurrence branches into two calls, and the subtrees overlap heavily, so the number of calls grows roughly like the Fibonacci sequence itself. Memoization collapses the recomputation to linear work. The blow-up comes from redundant calls, not from array allocation or sorting.

Question 26Programming Fundamentals and Problem Solving

In a programming context, what distinguishes an algorithm from a program?

  1. An algorithm is a finite, ordered set of unambiguous steps, while a program is that logic expressed in a concrete language for a machine. Correct answer.
  2. An algorithm may contain infinite loops by design, while a program must always terminate on every input.
  3. An algorithm must be written in pseudocode, while a program must be compiled before it can express any logic.
  4. An algorithm is tied to one specific processor, while a program is independent of any hardware.

Explanation

An algorithm is an abstract, language-independent procedure: a finite sequence of unambiguous steps that transforms input into output. A program is a concrete realization of algorithmic logic in a specific language, with syntax, data types, and runtime constraints. The distinction matters because you can design and analyze an algorithm before committing to any implementation language.

Question 27Programming Fundamentals and Problem Solving

A developer writes an expression in which a value of type string is added to a value of type integer, and the language rejects it at compile time. What does this demonstrate?

  1. The language performs type checking and refuses operations that violate its type rules. Correct answer.
  2. The language performs automatic memory management and reclaimed the string before use.
  3. The runtime raised an exception because the two operands were stored in different registers.
  4. The compiler optimized the expression away because its result was never printed.

Explanation

A compile-time rejection of an operation between incompatible types is the signature of static type checking: the compiler verifies that each operator receives operands of acceptable types. Because the error is reported before execution, no runtime exception or memory activity is involved. Type checking exists to catch such mismatches early rather than at the point of failure in production.

Question 28Programming Fundamentals and Problem Solving

A programmer traces code by hand and records the value of each variable after every statement. Which debugging benefit does this technique provide?

  1. It guarantees that the program contains no syntax errors before it is compiled.
  2. It reveals the exact statement at which a variable first departs from the intended value. Correct answer.
  3. It measures the asymptotic complexity of the routine being traced.
  4. It removes the need to write test cases for the routine under study.

Explanation

A hand trace, or dry run, follows the state of variables step by step, so the first point where a value diverges from expectation is exposed directly. This localizes logic errors that are hard to see by reading code alone. It complements testing rather than replacing it, since the trace only checks the specific inputs the programmer chooses.

Question 29Programming Fundamentals and Problem Solving

Which statement best describes the role of a return value in a function?

  1. It permanently stores the function's local variables for later calls.
  2. It must always be printed to standard output before the function exits.
  3. It carries a result back to the caller, which can then use or ignore that value. Correct answer.
  4. It signals to the operating system that the whole program has finished.

Explanation

A return value is the mechanism by which a function hands a computed result back to the code that called it; the caller may assign it, pass it onward, or discard it. It is distinct from output, which is a side effect, and from program termination. Local variables are not preserved by returning a value.

Question 30Programming Fundamentals and Problem Solving

A developer stores records in a hash table keyed by a student ID and later needs to retrieve all records whose ID begins with a given prefix. Why is the hash table a poor fit for that second operation?

  1. Hash tables forbid string keys and therefore cannot store identifiers at all.
  2. Hashing scatters keys by hash value, so records sharing a prefix are not stored adjacently and a scan of every entry is required. Correct answer.
  3. Hash tables require the number of stored records to be fixed before any insertion occurs.
  4. Hash tables keep entries sorted by key, so a prefix query must start from the largest key.

Explanation

A hash function maps a key to a bucket position that bears no relation to key order, so keys with a common prefix end up in unrelated buckets. Answering a prefix query therefore degrades to examining every entry, which is linear rather than the constant-time average of a point lookup. An ordered structure such as a balanced tree or trie supports prefix ranges far better.

Question 31Programming Fundamentals and Problem Solving

A queue is used to schedule print jobs, and a stack is used to record the pages a user navigates in a browser. Which pairing of access disciplines explains why each structure suits its task?

  1. The queue is first-in-first-out so jobs are printed in arrival order, and the stack is last-in-first-out so the most recent page is revisited first. Correct answer.
  2. The queue is last-in-first-out so the newest job prints first, and the stack is first-in-first-out so the oldest page returns first.
  3. Both structures are first-in-first-out, differing only in whether removal happens at the front or the back.
  4. Both structures are last-in-first-out, differing only in whether insertion happens at the front or the back.

Explanation

A queue removes from the front and inserts at the back, giving first-in-first-out order, which matches fair scheduling of print jobs by arrival. A stack inserts and removes at the same end, giving last-in-first-out order, which matches the back button returning to the most recently visited page. The access discipline, not the storage details, is what makes each structure appropriate.

Question 32Programming Fundamentals and Problem Solving

A function is documented to accept a positive integer and return its square. A caller passes a negative integer and receives a positive result that looks plausible. What does this episode most directly illustrate?

  1. The caller should have compiled the program with optimizations enabled to catch the mistake.
  2. The function's time complexity is higher than documented because of the extra sign handling.
  3. The function should have been declared to return a floating-point value instead of an integer.
  4. A violated precondition can produce output that appears correct, so the function should validate its input or state the contract explicitly. Correct answer.

Explanation

Squaring a negative number yields a positive value, so an invalid input slips through without an obviously wrong answer, which is exactly why preconditions matter. Explicit validation or a clearly documented contract turns a silent contract violation into a detectable failure. The danger is not the arithmetic but the false confidence that a plausible result creates.

Question 33Programming Fundamentals and Problem Solving

A developer writes a helper that accepts a list and returns a new list with each element doubled, leaving the caller's list untouched. What property does this helper have?

  1. It is an in-place algorithm because it visits each element exactly once.
  2. It is a pure transformation with respect to its argument, since it produces a new value without mutating the input. Correct answer.
  3. It is a recursive function because it processes every element of the list.
  4. It relies on pass-by-reference semantics to avoid copying the caller's data.

Explanation

Returning a new list while leaving the argument unchanged is the hallmark of a non-mutating, or pure, transformation: the caller's data is preserved and the result is a separate value. This supports reasoning about code because the call cannot introduce hidden state changes. Visiting each element once describes iteration, not purity.

Question 34Programming Fundamentals and Problem Solving

A loop is written to process every element of an array, but the code reads the element at index equal to the array length on the final iteration. What is the most likely consequence?

  1. An out-of-bounds access occurs, which may raise an error or silently read unrelated memory depending on the language. Correct answer.
  2. The final element is processed twice because the index is reused.
  3. The loop terminates early because the array length is recomputed on each pass.
  4. The array is automatically resized to accommodate the extra index.

Explanation

Valid indices for an array of length n run from 0 to n-1, so reading index n addresses one position past the end. In a checked language this raises an out-of-bounds exception; in an unchecked language it reads adjacent memory and yields undefined behavior. This off-by-one error is a classic boundary defect in loop conditions.

Question 35Programming Fundamentals and Problem Solving

Two nested loops each iterate over the same collection of n items, and the inner loop starts from the outer loop's current position rather than from zero. How many total inner iterations occur?

  1. n squared, because both loops always run the full range.
  2. n times (n + 1) divided by 2, which grows quadratically in n. Correct answer.
  3. n, because the inner loop runs only once per outer iteration.
  4. log base 2 of n, because the starting position halves each time.

Explanation

When the inner loop begins at the outer index, it runs n times on the first outer pass, n-1 on the second, and so on down to 1. The sum n + (n-1) + ... + 1 equals n(n+1)/2, which is still quadratic in n, just with half the constant factor. Recognizing this triangular sum is essential when estimating the cost of pairwise algorithms.

Question 36Programming Fundamentals and Problem Solving

A developer needs to store a set of values and repeatedly answer whether a given value is already present, with no requirement to keep the values ordered. Which choice best fits?

  1. A linked list, which stores elements contiguously for fast indexing.
  2. A stack, which keeps the most recently added value on top.
  3. A sorted array with binary search, which requires re-sorting after each insertion.
  4. A hash-based set, which offers average constant-time membership tests. Correct answer.

Explanation

Membership testing on unordered data is the canonical use of a hash-based set, which gives average constant-time insert and lookup. A sorted array supports logarithmic search but pays to maintain order on every insertion. A stack or plain linked list provides no efficient membership test at all.

Question 37Programming Fundamentals and Problem Solving

A function computes a result by calling itself on a smaller input and combining the returned value with the current one. What must be true for this function to terminate on every valid input?

  1. Each recursive call must move strictly closer to a base case that returns without recursing. Correct answer.
  2. The function must be memoized so that repeated arguments are never recomputed.
  3. The function must declare its return type as void so that intermediate values are discarded.
  4. The number of recursive calls must be bounded by the size of the program's stack.

Explanation

Termination of recursion rests on a well-founded measure that strictly decreases with each call and reaches a base case, which then returns without further recursion. If any path fails to reduce that measure, the recursion can continue indefinitely. Memoization may reduce repeated work but cannot rescue a recursion whose progress is not guaranteed.

Question 38Programming Fundamentals and Problem Solving

A developer writes a loop that scans a list of n items and, for each item, performs a binary search over the same sorted list. What is the overall time complexity?

  1. O(n), because the binary search runs in constant time for each item.
  2. O(n squared), because the search examines every element for each item.
  3. O(log n), because binary search dominates the loop's cost.
  4. O(n log n), because n scans each cost a logarithmic number of comparisons. Correct answer.

Explanation

The outer loop performs n iterations, and each iteration runs a binary search costing O(log n) comparisons. Multiplying the per-iteration cost by the number of iterations gives O(n log n). This combination of a linear scan with a logarithmic lookup is common in algorithms that compare each element against a sorted reference.

Question 39Programming Fundamentals and Problem Solving

A developer writes a sorting routine and tests it only on lists that are already in ascending order. It passes every test. Why is this test set inadequate?

  1. Sorted input exercises a narrow path and misses cases such as reversed, duplicated, or empty data where defects often hide. Correct answer.
  2. The tests should have measured running time instead of verifying the output order.
  3. Sorted input is invalid for sorting routines because it violates the routine's input contract.
  4. The tests are adequate, since a correct result on sorted input generalizes to all permutations.

Explanation

Testing only pre-sorted data exercises the best-case path and leaves boundary and adversarial inputs unexplored. Reversed lists, lists with many duplicates, single-element lists, and empty lists frequently expose comparison or index defects that sorted input never triggers. Adequate test design partitions the input space rather than sampling one convenient case.

Question 40Programming Fundamentals and Problem Solving

A developer must choose between an iterative loop and recursion for a routine whose recursion depth could reach one million on large inputs. Which consideration is decisive?

  1. Each recursive call consumes stack space, so deep recursion risks stack overflow, whereas an iterative loop uses constant stack space. Correct answer.
  2. Iteration cannot express the same logic as recursion and therefore limits correctness.
  3. Recursion is always faster because the compiler eliminates the function call overhead entirely.
  4. Recursion uses no memory because each frame is discarded as soon as it is created.

Explanation

Each pending recursive call keeps a stack frame alive until it returns, so depth proportional to the input can exhaust the call stack. An iterative loop reuses a single frame and therefore runs in constant stack space. When depth is large, converting to iteration or using an explicit stack is the safer engineering choice.

Question 41Data Structures and Algorithms

In a singly linked list, what is the worst-case time complexity to access the element at position k when only the head pointer is stored?

  1. O(k), which is O(n) in the worst case Correct answer.
  2. O(n log n)
  3. O(1)
  4. O(log n)

Explanation

A singly linked list has no index arithmetic; reaching position k requires traversing k nodes from the head. In the worst case k is n-1, so the operation is O(n).

Question 42Data Structures and Algorithms

A stack is used to evaluate expressions. Which operation order matches the LIFO discipline?

  1. Enqueue at the rear, dequeue from the front
  2. Insert at the front, remove from the front
  3. Insert at the rear, remove from the rear and front
  4. Push onto the top, pop from the top Correct answer.

Explanation

A stack inserts and removes at the same end, called the top, giving last-in-first-out behavior. This is what makes stacks suitable for matching parentheses and evaluating postfix expressions.

Question 43Data Structures and Algorithms

A binary search is applied to an array of 1024 sorted integers. What is the maximum number of comparisons needed in the worst case?

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

Explanation

Binary search halves the remaining range each step, so the worst case is about log2(n) rounded up. Since log2(1024) equals 10, an off-by-one search that compares down to a single element needs 11 comparisons.

Question 44Data Structures and Algorithms

In a min-heap stored in an array with 1-based indexing, where is the parent of the node at index i located?

  1. i/2 (integer division) Correct answer.
  2. 2i
  3. i-1
  4. 2i+1

Explanation

In a 1-based array heap, the children of index i sit at 2i and 2i+1, so the parent is found by integer division i/2. This implicit layout removes the need for pointers.

Question 45Data Structures and Algorithms

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

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

Explanation

Inorder traversal visits the left subtree, then the node, then the right subtree. Because all left keys are smaller and all right keys are larger, the output is sorted ascending.

Question 46Data Structures and Algorithms

A hash table uses open addressing with linear probing. Which condition must hold for the load factor to keep probe sequences short?

  1. The load factor must equal exactly 1
  2. The load factor is irrelevant once a hash function exists
  3. The load factor should stay well below 1, for example under 0.7 Correct answer.
  4. The load factor must exceed 1 to fill all buckets

Explanation

Linear probing degrades toward O(n) probes as the table fills because occupied clusters grow and merge. Keeping the load factor low, typically under about 0.7, preserves near-constant expected probe length.

Question 47Data Structures and Algorithms

What is the worst-case running time of quicksort with a naive last-element pivot on an already sorted array?

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

Explanation

Choosing the last element as pivot on sorted input splits off only one element per partition. The recurrence becomes T(n)=T(n-1)+O(n), which sums to O(n^2).

Question 48Data Structures and Algorithms

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

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

Explanation

Merge sort splits and merges while preserving the relative order of equal keys, and its recurrence guarantees O(n log n) in all cases. The merge step needs an auxiliary buffer proportional to n.

Question 49Data Structures and Algorithms

A graph has V vertices and E edges. Which representation uses O(V^2) memory regardless of edge count?

  1. Adjacency list
  2. Incidence list
  3. Edge list
  4. Adjacency matrix Correct answer.

Explanation

An adjacency matrix stores a V by V grid of entries, so its memory is always proportional to V^2. This is wasteful for sparse graphs but gives O(1) edge lookup.

Question 50Data Structures and Algorithms

Dijkstra's algorithm is run on a graph that contains an edge with negative weight. Why can the result be wrong?

  1. Negative weights force the graph to become disconnected
  2. The priority queue cannot store negative numbers
  3. Negative weights always create cycles
  4. The algorithm finalizes a vertex assuming no shorter path can appear later, which negative edges can violate Correct answer.

Explanation

Dijkstra settles a vertex once it is extracted with the smallest tentative distance. A later negative edge could reduce that distance, breaking the greedy assumption; Bellman-Ford is used instead.