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

  • 51Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Asymptotic Growth
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

How do n\sqrt{n}n​, nnn, and n+nn + \sqrt{n}n+n​ compare asymptotically?

Tap to flipClick to flipspace

n\sqrt{n}n​ grows slowest; nnn and n+nn + \sqrt{n}n+n​ are asymptotically equivalent, both growing as Θ(n)\Theta(n)Θ(n).

Or swipe the card

51 cards

  1. How do n\sqrt{n}n​, nnn, and n+nn + \sqrt{n}n+n​ compare asymptotically?

    n\sqrt{n}n​ grows slowest; nnn and n+nn + \sqrt{n}n+n​ are asymptotically equivalent, both growing as Θ(n)\Theta(n)Θ(n).

  2. How does a logarithmic power compare with a positive polynomial power?

    For positive constants aaa and bbb, (log⁡n)a=o(nb)(\log n)^a = o(n^b)(logn)a=o(nb); the logarithmic power grows strictly more slowly.

  3. How does an exponential function compare with a polynomial as nnn grows?

    For fixed c>1c > 1c>1 and fixed polynomial degree, cnc^ncn eventually grows faster than any polynomial in nnn.

  4. How does nnn^nnn compare with cnc^ncn for a fixed constant c>1c > 1c>1?

    nnn^nnn grows faster: nncn=(n/c)n\frac{n^n}{c^n} = (n/c)^ncnnn​=(n/c)n becomes arbitrarily large as nnn increases.

  5. What does f(n)=o(g(n))f(n) = o(g(n))f(n)=o(g(n)) mean?

    fff grows strictly more slowly than ggg: for every constant c>0c > 0c>0, f(n)<cg(n)f(n) < c g(n)f(n)<cg(n) for sufficiently large nnn.

  6. What does it mean to group functions together when ordering by asymptotic growth?

    Functions in the same group are asymptotically equivalent: they have the same growth rate up to constant factors.

  7. How can a limit of the ratio f(n)/g(n)f(n)/g(n)f(n)/g(n) reveal which function grows faster?

    If the ratio tends to infinity, fff grows faster; if it tends to zero, ggg grows faster; if it tends to a positive constant, they are asymptotically equivalent.

  8. Why might you take the logarithm of a ratio when comparing two functions?

    Taking the logarithm can make the limit easier to evaluate by turning products into sums and powers into factors.

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

    The number of ways to choose kkk objects from a set of nnn objects, without regard to order.

  10. What is the factorial formula for a binomial coefficient?

    (nk)=n!k!(n−k)!\displaystyle \binom{n}{k} = \frac{n!}{k!(n-k)!}(kn​)=k!(n−k)!n!​.

  11. Why does the binomial coefficient formula divide n!n!n! by k!(n−k)!k!(n-k)!k!(n−k)!?

    n!n!n! counts arrangements of all nnn objects. Dividing by the arrangements within the chosen kkk objects and the unchosen n−kn-kn−k objects removes orderings that represent the same selection.

  12. What is the asymptotic growth of (n3)\binom{n}{3}(3n​)?

    (n3)=n(n−1)(n−2)6=Θ(n3)\binom{n}{3} = \frac{n(n-1)(n-2)}{6} = \Theta(n^3)(3n​)=6n(n−1)(n−2)​=Θ(n3).

  13. What is Stirling’s approximation for n!n!n!?

    n!∼2πn(ne)n\displaystyle n! \sim \sqrt{2\pi n}\left(\frac{n}{e}\right)^nn!∼2πn​(en​)n as n→∞n \to \inftyn→∞.

  14. What is the asymptotic growth of log⁡(n!)\log(n!)log(n!)?

    log⁡(n!)=Θ(nlog⁡n)\log(n!) = \Theta(n\log n)log(n!)=Θ(nlogn), as follows by taking the logarithm of Stirling’s approximation.

  15. What is the asymptotic growth of the central binomial coefficient (nn/2)\binom{n}{n/2}(n/2n​)?

    For even nnn, (nn/2)=Θ(2nn)\displaystyle \binom{n}{n/2} = \Theta\left(\frac{2^n}{\sqrt{n}}\right)(n/2n​)=Θ(n​2n​).

  16. How does (nn/2)\binom{n}{n/2}(n/2n​) compare asymptotically with 2n2^n2n?

    It grows more slowly by a factor of n\sqrt{n}n​: (nn/2)=Θ(2n/n)\binom{n}{n/2} = \Theta(2^n/\sqrt{n})(n/2n​)=Θ(2n/n​).

  17. What is a sequence interface?

    An abstract way to store items in an extrinsic order, so items can be identified as the first, a particular position, or the last, regardless of their values.

  18. How does an interface differ from its implementation?

    An interface specifies what operations and behavior are available; an implementation specifies how they are achieved. For example, arrays and linked lists can both implement a sequence interface.

  19. What four end operations does the sequence structure in the problem support?

    Insert first, insert last, delete first, and delete last.

  20. What running time is assumed for each supported end operation on the abstract sequence?

    Each insert-first, insert-last, delete-first, and delete-last operation takes constant time.

  21. What does it mean to use a data structure as a black box?

    Use its specified public operations and guarantees without relying on or needing to know its internal implementation.

  22. How can you swap the first and last items using only constant-time end operations?

    Delete and save the first item, delete and save the last item, insert the former last item at the front, then insert the former first item at the back.

  23. What is the running time of swapping the ends using the four end operations?

    Θ(1)\Theta(1)Θ(1), because the algorithm performs a constant number of constant-time operations.

  24. What value does a delete operation return in the described sequence interface?

    It returns the item that was deleted.

  25. What does the operation shift_left(D,k)\text{shift\_left}(D,k)shift_left(D,k) do?

    It moves the first kkk items of sequence DDD to the back, preserving their order and the order of the remaining items.

  26. What is the recursive step for shifting the first kkk items to the back?

    Delete the first item, insert it at the back, then recursively shift the first k−1k-1k−1 items.

  27. What is a natural base case for the recursive shift operation?

    If k=0k = 0k=0, do nothing and return.

  28. What should a shift algorithm do when kkk is outside the permitted range?

    It can return without changing the sequence when k<1k < 1k<1 or k>∣D∣−1k > |D|-1k>∣D∣−1, as in the described algorithm.

  29. Why does the recursive shift algorithm terminate?

    Each recursive call reduces kkk by one, so the calls eventually reach the base case.

  30. What is the running time of shifting kkk items with the recursive algorithm?

    Θ(k)\Theta(k)Θ(k): each call does constant work, and there are kkk calls up to a constant difference.

  31. Why can recursion make an algorithm easier to reason about?

    It can reduce a problem to a smaller instance, allowing correctness to be argued using a base case and a simple step that preserves an invariant.

  32. What is amortized running time?

    It is a bound on the total cost of a sequence of operations. If an operation is amortized O(1)O(1)O(1), then mmm such operations take O(m)O(m)O(m) total time, even if some individual operations are expensive.

  33. How does amortized analysis differ from average-case analysis?

    Amortized analysis bounds the total cost across a sequence of operations on a data structure; average-case analysis averages over possible inputs, usually using an input distribution.

  34. What operations does a dynamic array support efficiently in the described model?

    Indexing takes worst-case constant time, while insertion and removal at the back take amortized constant time.

  35. Why is insertion or deletion at the front inefficient in a standard dynamic array?

    The other items generally have to be shifted to make room or close the gap, requiring linear time.

  36. How do linked lists compare with arrays for end operations and indexing?

    A linked list can support insertion and deletion at both ends in constant time, but finding an item by position can take linear time. An array supports constant-time indexing.

  37. Why can a linked list require linear time to find an item by position?

    Nodes may be stored in different memory locations, so the list must follow pointers one by one from a known node until it reaches the target.

  38. How does reserving extra capacity make dynamic-array insertions efficient?

    Insertions use the reserved space without reallocating. A resize is needed only after many insertions, allowing its cost to be spread across those operations.

  39. Why should a dynamic array shrink when it becomes sparsely occupied?

    Shrinking prevents the structure from retaining an amount of allocated space far larger than the number of stored items.

  40. Why should a dynamic array retain extra capacity after shrinking?

    If it shrank to exactly its current number of items, a nearby insertion could immediately force it to grow again. Retaining spare capacity helps avoid repeated resizing.

  41. How can a dynamic array be adapted to support efficient operations at both ends?

    Keep a linear amount of spare capacity at both the front and back, and resize or rebuild only after a linear number of end operations.

  42. How can two ordinary dynamic arrays simulate a sequence with efficient operations at both ends?

    Store roughly half the sequence in each array, with one array representing one side in reverse. Perform end operations at the appropriate ends of the two arrays.

  43. What must a two-array implementation do if one of its arrays becomes empty?

    Rebalance or rebuild by splitting the remaining items between two arrays, restoring the invariant that both sides can support end operations.

  44. What is the structure of a singly linked list node?

    Each node stores an item and a pointer to the next node. The list itself can store a head pointer and its size.

  45. What is the goal when reversing the last nnn nodes of a singly linked list containing 2n2n2n nodes?

    Keep the first nnn nodes in their original order and reverse the links among the last nnn nodes, modifying the existing list.

  46. How can you locate the nnnth node in a singly linked list when its head is known?

    Start at the head and follow the next pointer n−1n-1n−1 times.

  47. Why must a pointer-reversal algorithm save the current node’s next pointer before relinking it?

    Relinking overwrites the original next pointer. Saving it first preserves access to the rest of the list.

  48. What references are useful to maintain while reversing a singly linked list segment?

    Keep track of the current node, the previous node, and the current node’s original next node. These references allow the link to be reversed without losing access to the remaining nodes.

  49. After reversing the final nnn nodes, how should the two parts be connected?

    Set the nnnth node’s next pointer to the new head of the reversed segment, and set the old head of that segment’s next pointer to null.

  50. What time and extra-space bounds can be achieved when reversing the last half of a singly linked list in place?

    The reversal takes O(n)O(n)O(n) time and uses O(1)O(1)O(1) auxiliary space by changing pointers in the existing nodes.

  51. Why can temporarily disconnecting part of a linked list during reversal be safe?

    It is safe if the algorithm retains the necessary node references and reconnects the parts before finishing; otherwise, nodes could become inaccessible.

Card 1 of 51
Card 1 of 51

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent