100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada
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,80 €   Añadir al carrito

Examen

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

 11 vistas  0 veces vendidas
  • Grado
  • Institución

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

Vista previa 2 fuera de 9  páginas

  • 24 de junio de 2024
  • 9
  • 2023/2024
  • Examen
  • Preguntas y respuestas
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.

Los beneficios de comprar resúmenes en Stuvia estan en línea:

Garantiza la calidad de los comentarios

Garantiza la calidad de los comentarios

Compradores de Stuvia evaluaron más de 700.000 resúmenes. Así estas seguro que compras los mejores documentos!

Compra fácil y rápido

Compra fácil y rápido

Puedes pagar rápidamente y en una vez con iDeal, tarjeta de crédito o con tu crédito de Stuvia. Sin tener que hacerte miembro.

Enfócate en lo más importante

Enfócate en lo más importante

Tus compañeros escriben los resúmenes. Por eso tienes la seguridad que tienes un resumen actual y confiable. Así llegas a la conclusión rapidamente!

Preguntas frecuentes

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.

100% de satisfacción garantizada: ¿Cómo funciona?

Nuestra garantía de satisfacción le asegura que siempre encontrará un documento de estudio a tu medida. Tu rellenas un formulario y nuestro equipo de atención al cliente se encarga del resto.

Who am I buying this summary 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 this summary for 7,80 €. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

45,681 summaries were sold in the last 30 days

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

Empieza a vender
7,80 €
  • (0)
  Añadir