Free Practice Quiz Question List

10 Data Structure and Algorithm Trade-offs Online Quiz Questions

Use this free practice quiz with 20 questions to review 10 Data Structure and Algorithm Trade-offs, test your knowledge, and prepare for your next test or exam.

20 questions
01
Choose one
1 point

Why is inserting an element near the beginning or middle of a dynamic array typically O(n)O(n)?

  1. A

    The elements after the insertion point must be shifted, so it is typically O(n)O(n).

  2. B

    The insertion is always O(1)O(1) because arrays support constant-time indexing.

  3. C

    The array must be sorted first, so the operation is typically O(log⁡n)O(\log n).

  4. D

    The insertion requires hashing every existing element, so it is typically O(nlog⁡n)O(n\log n).

02
True or false
1 point

True or false: In a linked list, inserting at a known node can be O(1)O(1), even though finding that node may take O(n)O(n).

  1. A

    True

  2. B

    False

03
Written response
1 point

What structure should be used when a program needs efficient insertion and removal at both the front and the rear?

04
Fill in the blank
1 point

Binary search requires data and takes comparisons in the usual analysis.

05
Choose one
1 point

A program must repeatedly perform range queries and produce keys in sorted order. Which structure is the best general choice?

  1. A

    A hash table, because it naturally maintains sorted order and supports range queries.

  2. B

    A linked list, because range queries require scanning nodes in insertion order.

  3. C

    A balanced tree, because it maintains sorted order, supports range queries, and has typical O(log⁡n)O(\log n) search, insertion, and deletion.

  4. D

    A stack, because its LIFO ordering provides efficient predecessor and successor queries.

06
True or false
1 point

True or false: A stable sorting algorithm preserves the relative order of records that have equal sort keys.

  1. A

    True

  2. B

    False

07
Written response
1 point

A task-processing system must add and remove tasks efficiently at either end of a sequence. What structure is most appropriate?

08
Fill in the blank
1 point

An LRU cache commonly combines a for key lookup with a for recency ordering.

09
Choose one
1 point

A collection of nn items is sorted once, followed by mm binary searches. What is the total asymptotic time complexity?

  1. A

    O(mn)O(mn)

  2. B

    O(n+m)O(n+m) in every implementation

  3. C

    O(nlog⁡m+mlog⁡n)O(n\log m + m\log n)

  4. D

    O(nlog⁡n+mlog⁡n)O(n\log n + m\log n)

10
Open ended
1 point

A service stores records by unique identifier. Most requests look up one exact identifier, but some requests require sorted iteration and range queries. Explain when a hash table is preferable, when a balanced tree is preferable, and what trade-offs should guide the final choice.

11
Choose one
1 point

A scheduler repeatedly needs to retrieve the task with the highest priority. Which structure is the most appropriate primary choice?

  1. A

    A linked list, because it provides constant-time access to every priority value.

  2. B

    A heap or priority queue, because it is designed to retrieve the next highest- or lowest-priority item efficiently.

  3. C

    A hash table, because hashing automatically returns the numerically smallest key.

  4. D

    A stack, because LIFO order is equivalent to priority order.

12
Choose one
1 point

A program sorts an array of nn items once and then performs mm binary searches on it. What is the total asymptotic time complexity?

  1. A

    O(mn)O(mn)

  2. B

    O(nlog⁡n+mlog⁡n)O(n\log n + m\log n)

  3. C

    O(n+m)O(n + m) in the worst case

  4. D

    O(nlog⁡m)O(n\log m)

13
Choose one
1 point

A program needs fast exact lookup by record ID and efficient sequential processing of all records. Which combined design best fits these requirements, assuming records may move within the main storage?

  1. A

    A stack and a queue

  2. B

    A balanced tree and a heap

  3. C

    A dynamic array and a hash table mapping IDs to indices

  4. D

    A linked list and a binary search tree

14
Choose one
1 point

A system must repeatedly retrieve all keys within specified ranges and iterate through the keys in sorted order. Which structure is the best primary choice?

  1. A

    A balanced tree

  2. B

    A hash table

  3. C

    A stack

  4. D

    A basic array

15
Choose one
1 point

A singly linked list must insert an item after a node that is identified only by its value. Which complexity statement is most accurate for the complete insertion task?

  1. A

    The entire operation is always O(1)O(1) because linked lists never move elements.

  2. B

    The entire operation is always O(log⁡n)O(\log n) because links provide direct access.

  3. C

    The operation is always O(n2)O(n^2) because each node has a link.

  4. D

    The link update is O(1)O(1) after locating the node, but locating it may make the total O(n)O(n).

16
True or false
1 point

True or false: A recursive binary search on a sorted array has recurrence T(n)=T(n/2)+O(1)T(n)=T(n/2)+O(1), so its running time is O(log⁡n)O(\log n).

  1. A

    True

  2. B

    False

17
Written response
1 point

What is the worst-case time complexity of a linear search through an unsorted collection of nn items?

18
Written response
1 point

What is the usual complexity description for appending to a dynamic array over a long sequence of append operations?

19
Choose all
1 point

Select all statements that accurately describe hash-table trade-offs.

  1. A

    Lookup is guaranteed O(1)O(1) even when all keys collide.

  2. B

    A hash table always maintains keys in sorted order.

  3. C

    Expected lookup, insertion, and deletion can be O(1)O(1) with a good hash function and controlled load factor.

  4. D

    The worst case can be O(n)O(n), and sorted-order operations are not naturally supported.

20
Choose all
1 point

Which properties are required for a correct recursive function? Select all that apply.

  1. A

    A base case that can return without another recursive call

  2. B

    Progress toward the base case on each recursive call

  3. C

    A rule for combining recursive results into the final result

  4. D

    A hash table for storing every previously visited input