100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSE 2050 Exam 2 - Recursion, Sorting, and Hashing Questions with 100% Actual correct answers | verified | latest update | Graded A+ | Already Passed | Complete Solution $7.99   Add to cart

Exam (elaborations)

CSE 2050 Exam 2 - Recursion, Sorting, and Hashing Questions with 100% Actual correct answers | verified | latest update | Graded A+ | Already Passed | Complete Solution

 11 views  0 purchase
  • Course
  • Institution

CSE 2050 Exam 2 - Recursion, Sorting, and Hashing Questions with 100% Actual correct answers | verified | latest update | Graded A+ | Already Passed | Complete Solution

Preview 2 out of 9  pages

  • June 24, 2024
  • 9
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
CSE 2050 Exam 2 - Recursion, Sorting,
and Hashing
Recursion - ANS-Problem-solving strategy that involves breaking a problem into smaller
instances of the same problem (also called subproblems) until we get a small enough
subproblem with a trivial solution.

First X Numbers - ANS-def f(x):
if x > 0:
return f(x-1) + x
return 0

Proofs by Induction - ANS-Base Step: prove the predicate is true when n = 1.
Hypothesis Step: assume it is true for n = K.
Inductive Step: show it is true for n = K + 1.

Rules of Recursion - ANS-Base Case: there must be at least one base case at which,
when such condition is met, the function stops calling itself.
Recursive Step: must move towards the base case.

The Function Call Stack - ANS-Calling a function pushes onto the stack.
Returning pops off the stack.

Factorial - ANS-def fact(x):
if x == 1:
return 1
else:
return x * fact(x-1)

Euclid's Algorithm - ANS-def GCD(a, b):
if a > b:
a, b = b, a
if a == 0:
return b
return GCD(a, b % a)

Fibonacci Numbers - ANS-def fib(n):
if n in [0, 1]:

, return 1
return fib(n-1) + fib(n-2)

Golden Ratio - ANS-Ratio of adjacent Fibonacci numbers.
Often called the most beautiful number in the universe.
Applications from geometry to the proportions of the human body itself.

Problems - ANS-Some recursive algorithms are inefficient because they repeatedly call
to a function with the same parameters, wasting time.

Greedy Algorithms - ANS-Strategy that makes the most optimal choice at each small
stage with the goal of eventually leading to a globally optimal solution.
Picks the best solution at the moment without regard for consequences (hence, it is
greedy).
In many problems, a greedy strategy does not produce an optimal solution.

Dynamic Programming - ANS-Stores previously calculated values to prevent repetitive
calculations and allow for quicker retrievals as well as using smaller values to solve for
even larger ones.
Created subproblems are overlapping, that is, we see the same subproblems repeated.
Two Approaches: Memoization and Tabulation.

Memoization - ANS-Write the recursive function top-down.
Alter the function to check if we've already calculated the value.
If so, use the pre-calculated value,
If not, do the recursive call.

Fib - Memo - ANS-def fib(n, fib_cache):
if n in fib_cache:
return fib_cache[n]
fib_cache[n] = fib(n-1, fib_cache) + fib(n-2, fib_cache)
return fib_cache[n]

Memoization Pros - ANS-Can be more intuitive to code / understand.
Can be memory saving if you don't need answers to all subproblems.

Memoization Cons - ANS-Depending on implementation, larger overhead due to
recursion.

Tabulation - ANS-Bottom-Up.

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller Hkane. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $7.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79223 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling

Recently viewed by you


$7.99
  • (0)
  Add to cart