1. Home
  2. Explore
  3. Computer Science
  4. Algorithms Problem-Solving

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Algorithms Problem-Solving

  • 39Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Asymptotic Reasoning

When several functions have the same asymptotic growth rate, how should they be represented in an ordered list of growth rates?

39 questions

  1. 1

    When several functions have the same asymptotic growth rate, how should they be represented in an ordered list of growth rates?

    1. A

      As a group at the same position in the ordering

    2. B

      As entries ordered by their values for small inputs

    3. C

      As separate entries in an arbitrary order

    4. D

      Only the function with the largest constant should be listed

    Correct answer
    A

    As a group at the same position in the ordering

    Explanation

    Asymptotically equivalent functions belong together at the same position in the growth ordering; their relative order is not meaningful asymptotically.

  2. 2

    For positive constants aaa and bbb, how does (log⁡n)a(\log n)^a(logn)a compare asymptotically with nbn^bnb?

    1. A

      Their relative growth depends on the values of aaa and bbb

    2. B

      (log⁡n)a(\log n)^a(logn)a grows strictly more slowly than nbn^bnb

    3. C

      The two functions are asymptotically equivalent

    4. D

      (log⁡n)a(\log n)^a(logn)a grows strictly faster than nbn^bnb

    Correct answer
    B

    (log⁡n)a(\log n)^a(logn)a grows strictly more slowly than nbn^bnb

    Explanation

    Any fixed positive power of a logarithm grows more slowly than any fixed positive power of nnn.

  3. 3

    Suppose the ratio of two positive functions approaches 000 as nnn grows. What does this imply about their relative growth?

    1. A

      Neither function can be compared asymptotically

    2. B

      The numerator grows more slowly than the denominator

    3. C

      The numerator grows more quickly than the denominator

    4. D

      The two functions have the same asymptotic growth

    Correct answer
    B

    The numerator grows more slowly than the denominator

    Explanation

    If the ratio of the numerator to the denominator approaches 000, the numerator is asymptotically smaller and grows more slowly.

  4. 4

    What does it indicate if the ratio of two positive functions approaches a positive finite constant?

    1. A

      The denominator grows strictly faster

    2. B

      Both functions must be exponential

    3. C

      The numerator grows strictly faster

    4. D

      The functions are asymptotically equivalent

    Correct answer
    D

    The functions are asymptotically equivalent

    Explanation

    A ratio that approaches a positive finite constant indicates that the two functions differ by an asymptotically constant factor, so they are asymptotically equivalent.

  5. 5

    Which statement best distinguishes little-ooo from big-OOO when comparing two functions?

    1. A

      Little-ooo expresses strictly slower growth, while big-OOO allows growth of the same order

    2. B

      Little-ooo permits equal growth, while big-OOO requires strictly slower growth

    3. C

      Little-ooo applies only to exponential functions, while big-OOO applies to all functions

    4. D

      Little-ooo compares only constant factors, while big-OOO compares exponents

    Correct answer
    A

    Little-ooo expresses strictly slower growth, while big-OOO allows growth of the same order

    Explanation

    Big-OOO allows the functions to have the same asymptotic order. Little-ooo describes a stricter relationship in which one function grows strictly more slowly.

  6. 6

    Why does multiplying an exponential function by a fixed polynomial factor not make it grow more slowly than every exponential function?

    1. A

      Exponential growth dominates polynomial growth asymptotically

    2. B

      Polynomial factors eventually cancel exponential growth

    3. C

      Exponential and polynomial factors always have the same growth

    4. D

      A polynomial factor changes an exponential into a logarithm

    Correct answer
    A

    Exponential growth dominates polynomial growth asymptotically

    Explanation

    An exponential factor eventually dominates any fixed polynomial factor. Polynomial multipliers or divisors can affect comparisons between functions, but do not erase exponential growth.

  7. 7

    Compared with 2n2^n2n, how does 2nn\frac{2^n}{\sqrt{n}}n​2n​ grow asymptotically?

    1. A

      More quickly, because the denominator increases with nnn

    2. B

      At the same rate, because both functions contain 2n2^n2n

    3. C

      More slowly, because division by n\sqrt{n}n​ reduces the function by an unbounded factor

    4. D

      At the same rate, because n\sqrt{n}n​ is a constant factor

    Correct answer
    C

    More slowly, because division by n\sqrt{n}n​ reduces the function by an unbounded factor

    Explanation

    The factor n\sqrt{n}n​ grows without bound, so dividing by it makes the function asymptotically smaller than 2n2^n2n, even though both retain exponential growth.

  8. 8

    What does the binomial coefficient (nk)\binom{n}{k}(kn​) count?

    1. A

      The number of ways to choose nnn objects from a set of kkk objects

    2. B

      The number of ways to arrange all nnn objects in a line

    3. C

      The number of ways to arrange kkk selected objects in order

    4. D

      The number of ways to choose kkk objects from nnn objects without regard to order

    Correct answer
    D

    The number of ways to choose kkk objects from nnn objects without regard to order

    Explanation

    A binomial coefficient counts selections of kkk objects from nnn when the order of the selected objects does not matter.

  9. 9

    Which expression gives the factorial formula for (nk)\binom{n}{k}(kn​)?

    1. A

      (n−k)!n!k!\frac{(n-k)!}{n!k!}n!k!(n−k)!​

    2. B

      k!(n−k)!n!\frac{k!(n-k)!}{n!}n!k!(n−k)!​

    3. C

      n!(n−k)!\frac{n!}{(n-k)!}(n−k)!n!​

    4. D

      n!k!(n−k)!\frac{n!}{k!(n-k)!}k!(n−k)!n!​

    Correct answer
    D

    n!k!(n−k)!\frac{n!}{k!(n-k)!}k!(n−k)!n!​

    Explanation

    The number of ordered selections of kkk objects is n!(n−k)!\frac{n!}{(n-k)!}(n−k)!n!​. Dividing by k!k!k! removes the different orders of the same selection, giving (nk)=n!k!(n−k)!\binom{n}{k}=\frac{n!}{k!(n-k)!}(kn​)=k!(n−k)!n!​.

  10. 10

    What is the main use of Stirling's approximation when analyzing factorials?

    1. A

      It converts a factorial exactly into a polynomial

    2. B

      It shows that factorials grow more slowly than exponentials

    3. C

      It determines the number of divisors of a factorial

    4. D

      It replaces a factorial with an expression whose asymptotic growth is easier to compare

    Correct answer
    D

    It replaces a factorial with an expression whose asymptotic growth is easier to compare

    Explanation

    Stirling's approximation estimates factorials using an expression involving powers and a square-root factor, making their asymptotic growth easier to analyze.

  11. 11

    What is the asymptotic order of log⁡(n!)\log(n!)log(n!)?

    1. A

      Θ(nlog⁡n)\Theta(n\log n)Θ(nlogn)

    2. B

      Θ(n2)\Theta(n^2)Θ(n2)

    3. C

      Θ(n)\Theta(n)Θ(n)

    4. D

      Θ((log⁡n)2)\Theta((\log n)^2)Θ((logn)2)

    Correct answer
    A

    Θ(nlog⁡n)\Theta(n\log n)Θ(nlogn)

    Explanation

    Taking the logarithm of Stirling's approximation for n!n!n! gives a leading term of nlog⁡nn\log nnlogn; the remaining terms grow more slowly. Thus log⁡(n!)=Θ(nlog⁡n)\log(n!)=\Theta(n\log n)log(n!)=Θ(nlogn).

  12. 12

    For fixed k=3k=3k=3, what is the asymptotic order of (n3)\binom{n}{3}(3n​)?

    1. A

      Θ(n3)\Theta(n^3)Θ(n3)

    2. B

      Θ(log⁡n)\Theta(\log n)Θ(logn)

    3. C

      Θ(2n)\Theta(2^n)Θ(2n)

    4. D

      Θ(nlog⁡n)\Theta(n\log n)Θ(nlogn)

    Correct answer
    A

    Θ(n3)\Theta(n^3)Θ(n3)

    Explanation

    Using (n3)=n(n−1)(n−2)6\binom{n}{3}=\frac{n(n-1)(n-2)}{6}(3n​)=6n(n−1)(n−2)​, the leading term is a constant multiple of n3n^3n3.

  13. 13

    What is the asymptotic order of the central binomial coefficient (nn/2)\binom{n}{n/2}(n/2n​) for even nnn?

    1. A

      Θ ⁣(2nn)\Theta\!\left(\frac{2^n}{\sqrt{n}}\right)Θ(n​2n​)

    2. B

      Θ(n3)\Theta(n^3)Θ(n3)

    3. C

      Θ ⁣(nnen)\Theta\!\left(\frac{n^n}{e^n}\right)Θ(ennn​)

    4. D

      Θ(log⁡n)\Theta(\log n)Θ(logn)

    Correct answer
    A

    Θ ⁣(2nn)\Theta\!\left(\frac{2^n}{\sqrt{n}}\right)Θ(n​2n​)

    Explanation

    Applying Stirling's approximation to (nn/2)=n!((n/2)!)2\binom{n}{n/2}=\frac{n!}{((n/2)!)^2}(n/2n​)=((n/2)!)2n!​ and simplifying gives asymptotic growth proportional to 2nn\frac{2^n}{\sqrt{n}}n​2n​.

  14. 14

    What makes a sequence interface distinct from a particular array or linked-list implementation?

    1. A

      It specifies the exact memory addresses of the first and last items

    2. B

      It requires all items to occupy consecutive memory locations

    3. C

      It specifies the operations and ordering behavior without prescribing how items are stored

    4. D

      It requires each item to point to the next item

    Correct answer
    C

    It specifies the operations and ordering behavior without prescribing how items are stored

    Explanation

    An interface describes the supported behavior abstractly. Arrays and linked lists are different possible implementations of a sequence interface.

  15. 15

    What does it mean to say that a sequence has an extrinsic order?

    1. A

      Each item determines the position of the item that follows it

    2. B

      Items are ordered according to their numerical values

    3. C

      Items have positions such as first or tenth based on their arrangement, independent of their values

    4. D

      Items are stored in memory in the order they were allocated

    Correct answer
    C

    Items have positions such as first or tenth based on their arrangement, independent of their values

    Explanation

    A sequence maintains positions such as first, tenth, and last. Those positions are determined by the sequence's arrangement, not by properties of the items themselves.

  16. 16

    A sequence data structure is given as a black box that supports insert-first, insert-last, delete-first, and delete-last in constant time. What is the key restriction of treating it as a black box?

    1. A

      An algorithm must assume the sequence is stored in an array

    2. B

      An algorithm may use only one of its supported operations

    3. C

      An algorithm may inspect its internal memory but may not modify it

    4. D

      An algorithm may rely on the supported operations but not on the hidden implementation

    Correct answer
    D

    An algorithm may rely on the supported operations but not on the hidden implementation

    Explanation

    A black-box abstraction exposes a public interface while hiding the implementation. Algorithms using it should rely on its specified operations and guarantees.

  17. 17

    When a sequence's delete operation is specified to return the removed item, how can that guarantee help implement an endpoint swap?

    1. A

      Replace both endpoints without retrieving their values

    2. B

      Delete one endpoint and assume the other endpoint changes automatically

    3. C

      Store both deleted endpoint items, then insert each at the opposite end

    4. D

      Copy every item into a new sequence before swapping

    Correct answer
    C

    Store both deleted endpoint items, then insert each at the opposite end

    Explanation

    Deleting the first and last items returns their values. The algorithm can store those two values temporarily and insert each at the opposite end.

  18. 18

    If each sequence operation takes constant time, what is the running time of swapping the first and last items using two deletions and two insertions?

    1. A

      Θ(n)\Theta(n)Θ(n)

    2. B

      Θ(1)\Theta(1)Θ(1)

    3. C

      Θ(n2)\Theta(n^2)Θ(n2)

    4. D

      Θ(log⁡n)\Theta(\log n)Θ(logn)

    Correct answer
    B

    Θ(1)\Theta(1)Θ(1)

    Explanation

    The swap uses a fixed number of operations, and each operation takes constant time, so the total time is constant.

  19. 19

    What does a left shift by KKK positions do to a sequence?

    1. A

      It deletes the first KKK items from the sequence

    2. B

      It moves the last KKK items to the front in reverse order

    3. C

      It moves the first KKK items, in their original order, to the back

    4. D

      It reverses the first KKK items and leaves the rest in place

    Correct answer
    C

    It moves the first KKK items, in their original order, to the back

    Explanation

    A left shift takes the first KKK items and appends them to the back in the same relative order. The former (K+1)(K+1)(K+1)st item becomes first.

  20. 20

    In a recursive left-shift algorithm that moves one item and then shifts K−1K-1K−1 items, what is a suitable base case?

    1. A

      When K<0K<0K<0, move one item from the back to the front

    2. B

      When KKK equals the sequence length, delete every item

    3. C

      When K=0K=0K=0, return without changing the sequence

    4. D

      When K=1K=1K=1, reverse the whole sequence

    Correct answer
    C

    When K=0K=0K=0, return without changing the sequence

    Explanation

    With K=0K=0K=0, no items need to be moved, so the recursion can stop without modifying the sequence.

  21. 21

    If each recursive call for a left shift performs a constant number of sequence operations and reduces KKK by one, what is the running time?

    1. A

      Θ(2K)\Theta(2^K)Θ(2K)

    2. B

      Θ(1)\Theta(1)Θ(1)

    3. C

      Θ(K)\Theta(K)Θ(K)

    4. D

      Θ(K2)\Theta(K^2)Θ(K2)

    Correct answer
    C

    Θ(K)\Theta(K)Θ(K)

    Explanation

    The recursion makes a number of calls proportional to KKK, with constant work in each call, giving total time Θ(K)\Theta(K)Θ(K).

  22. 22

    Which performance guarantee is associated with indexing into a dynamic array?

    1. A

      Amortized linear time

    2. B

      Worst-case logarithmic time

    3. C

      Amortized quadratic time

    4. D

      Worst-case constant time

    Correct answer
    D

    Worst-case constant time

    Explanation

    A dynamic array supports indexing in worst-case constant time, since an indexed element can be accessed directly.

  23. 23

    Why are insertions and deletions at the front of a conventional dynamic array inefficient?

    1. A

      The array must search every item to find the front

    2. B

      Existing items may need to be shifted to make room or close a gap

    3. C

      Every front operation requires converting the array to a linked list

    4. D

      The array cannot store items at index zero

    Correct answer
    B

    Existing items may need to be shifted to make room or close a gap

    Explanation

    Inserting at or removing from the front changes the positions of the other items, so many of them may need to be shifted.

  24. 24

    What does it mean for an operation to take amortized O(1)O(1)O(1) time?

    1. A

      The operation's cost is independent of how many prior operations occurred

    2. B

      Across a sequence of mmm operations, their total cost is bounded by a constant times mmm

    3. C

      Every individual operation is guaranteed to take constant time

    4. D

      The operation takes constant time only for average-sized inputs

    Correct answer
    B

    Across a sequence of mmm operations, their total cost is bounded by a constant times mmm

    Explanation

    An amortized constant-time guarantee bounds the total cost of a sequence of operations by a constant times the number of operations. Some individual operations may still be expensive.

  25. 25

    How does amortized analysis differ from averaging an algorithm's running time over possible inputs?

    1. A

      It analyzes the total cost of a sequence of operations on a data structure, rather than averaging across an input distribution

    2. B

      It applies only when every operation has the same worst-case cost

    3. C

      It requires assigning probabilities to each operation

    4. D

      It averages the cost across all possible input sizes, while input analysis does not

    Correct answer
    A

    It analyzes the total cost of a sequence of operations on a data structure, rather than averaging across an input distribution

    Explanation

    Amortized analysis bounds the total cost across multiple operations, often on the same evolving data structure. It does not require a probability distribution over inputs.

  26. 26

    Why can a dynamic array append be amortized constant time even if some appends are expensive?

    1. A

      Resizing never copies existing items

    2. B

      Each append is individually guaranteed to avoid allocation

    3. C

      The array's capacity always equals its number of items

    4. D

      Occasional resizing costs can be spread across many inexpensive appends

    Correct answer
    D

    Occasional resizing costs can be spread across many inexpensive appends

    Explanation

    Most appends are inexpensive, while a resize may require copying many elements. If resizing occurs only after many appends, the expensive costs can be charged across those operations.

  27. 27

    Why does keeping extra capacity at an array's end support amortized constant-time appends?

    1. A

      It ensures the array never has unused memory

    2. B

      It turns an array into a linked list during insertion

    3. C

      It allows many appends before another costly resize is needed

    4. D

      It makes every append avoid changing the array's contents

    Correct answer
    C

    It allows many appends before another costly resize is needed

    Explanation

    Spare capacity lets the array accept multiple new items without resizing. If the capacity is expanded geometrically or otherwise with linear slack, a resize is separated from the next one by many appends.

  28. 28

    Why might a dynamic array shrink when it becomes much less full?

    1. A

      To make indexing take less than constant time

    2. B

      To guarantee that every deletion uses constant time in the worst case

    3. C

      To preserve the original capacity permanently

    4. D

      To avoid retaining space far larger than the amount needed for its current items

    Correct answer
    D

    To avoid retaining space far larger than the amount needed for its current items

    Explanation

    If many items are removed but the array keeps its large allocation, it may use far more memory than the remaining sequence requires. Shrinking helps keep space proportional to the number of stored items.

  29. 29

    Why should a shrinking policy leave spare capacity instead of resizing to exactly the current number of items after every deletion?

    1. A

      Exact-size arrays require linked-list nodes for each item

    2. B

      Exact-size arrays cannot support indexing

    3. C

      Spare capacity makes deletion at the front constant time

    4. D

      Spare capacity helps prevent repeated expensive resizing after alternating deletions and insertions

    Correct answer
    D

    Spare capacity helps prevent repeated expensive resizing after alternating deletions and insertions

    Explanation

    If an array is resized to exactly its current size, the next insertion may immediately force growth again. Leaving slack creates room for more operations before another costly resize.

  30. 30

    How can two dynamic arrays be used to support efficient operations at both ends of a sequence?

    1. A

      Alternate individual items between the arrays and scan both for each access

    2. B

      Store one portion in each array, treating one array in reverse order and using index arithmetic

    3. C

      Store every item in both arrays and compare copies after each operation

    4. D

      Use one array only for indexing and the other only for resizing

    Correct answer
    B

    Store one portion in each array, treating one array in reverse order and using index arithmetic

    Explanation

    The sequence can be split into two portions held in separate dynamic arrays. One portion is viewed in reverse, allowing each array's efficient end operations to serve opposite ends of the overall sequence.

  31. 31

    What should a two-array deque-style structure do when one of its arrays becomes empty?

    1. A

      Continue using the empty array for deletions until it contains an item

    2. B

      Copy every item into a permanent fixed-size array

    3. C

      Discard the other array and lose its stored items

    4. D

      Rebalance the remaining items between newly arranged arrays to restore a useful split

    Correct answer
    D

    Rebalance the remaining items between newly arranged arrays to restore a useful split

    Explanation

    When one side empties, the structure can redistribute the remaining items between the arrays. Since this rebuild follows many preceding operations, its cost can be amortized across them.

  32. 32

    Which property distinguishes linked-list lookup from dynamic-array indexing?

    1. A

      Both methods require scanning the entire structure

    2. B

      Linked-list lookup may require traversing nodes and take linear time

    3. C

      Dynamic-array indexing requires following every preceding item

    4. D

      Linked-list lookup is always worst-case constant time

    Correct answer
    B

    Linked-list lookup may require traversing nodes and take linear time

    Explanation

    A linked list may store nodes in different memory locations and provides access by following pointers, so finding a distant item can require traversing a linear number of nodes. An array can index directly.

  33. 33

    What information does each node in the singly linked list described in the content contain?

    1. A

      An item and pointers to both the previous and next nodes

    2. B

      A head pointer and the list's total size

    3. C

      An array index and the total capacity of the list

    4. D

      An item and a pointer to the next node

    Correct answer
    D

    An item and a pointer to the next node

    Explanation

    Each singly linked-list node contains its item and a next pointer. The list itself maintains information such as its head and size.

  34. 34

    Given a singly linked list of 2n2n2n nodes, how many next-pointer traversals are needed to reach node nnn from the head?

    1. A

      nnn

    2. B

      2n−12n-12n−1

    3. C

      2n2n2n

    4. D

      n−1n-1n−1

    Correct answer
    D

    n−1n-1n−1

    Explanation

    The head is node 111. Reaching node nnn therefore requires following n−1n-1n−1 next pointers.

  35. 35

    When reversing the next pointers of a singly linked list in place, why must the algorithm save the current node's next pointer before changing it?

    1. A

      So it can continue traversing the unreversed portion after relinking the current node

    2. B

      So it can avoid storing the previous node

    3. C

      So it can determine the current node's item without reading it

    4. D

      So it can calculate the size of the linked list

    Correct answer
    A

    So it can continue traversing the unreversed portion after relinking the current node

    Explanation

    Changing the current node's next pointer would otherwise lose the link to the unreversed remainder. Saving that pointer first preserves the path for continued traversal.

  36. 36

    Which set of references is sufficient for an iterative in-place reversal of a singly linked-list segment?

    1. A

      The current node, its item, and the list's capacity

    2. B

      The head node, the list size, and an array of all node addresses

    3. C

      The current node and a pointer to the list's tail only

    4. D

      The current node, the previous node, and the saved next node

    Correct answer
    D

    The current node, the previous node, and the saved next node

    Explanation

    The algorithm needs the current node to modify, the previous node to point back to, and the saved next node to continue traversing.

  37. 37

    After reversing the last nnn nodes of a list containing 2n2n2n nodes, what must happen at the boundary between the unchanged and reversed portions?

    1. A

      The head must point directly to the last node of the original list

    2. B

      The node at position nnn must be deleted

    3. C

      The node at position nnn must point to the new first node of the reversed portion

    4. D

      The new last node of the reversed portion must point back to the head

    Correct answer
    C

    The node at position nnn must point to the new first node of the reversed portion

    Explanation

    The first nnn nodes remain in their original order. The node at position nnn must be linked to the original last node, which becomes the first node of the reversed portion.

  38. 38

    After reversing the final nnn nodes of a singly linked list in place, what should the next pointer of the new final node be?

    1. A

      It should point to the node before the reversed segment

    2. B

      It should be null

    3. C

      It should point to the list head

    4. D

      It should point to the original final node

    Correct answer
    B

    It should be null

    Explanation

    The original first node of the reversed segment becomes its final node. Its next pointer must be null so the resulting list terminates correctly.

  39. 39

    If an algorithm is required to reverse part of a linked list in place using only constant extra space, which approach satisfies the restriction?

    1. A

      Copy all node items into a new array and rewrite them in reverse order

    2. B

      Create a second linked list containing the reversed nodes

    3. C

      Store every node address in a temporary list before changing pointers

    4. D

      Relink the existing nodes using a constant number of temporary references

    Correct answer
    D

    Relink the existing nodes using a constant number of temporary references

    Explanation

    In-place reversal modifies the existing nodes' pointers and needs only a constant number of temporary references. The other approaches use a non-constant amount of auxiliary storage or create new nodes.

Question 1 of 39
Question 1 of 39

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent