100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
cse 2050 exam 2 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 Questions with 100% Actual correct answers | verified | latest update | Graded A+ | Already Passed | Complete Solution

 5 views  0 purchase
  • Course
  • Institution

cse 2050 exam 2 Questions with 100% Actual correct answers | verified | latest update | Graded A+ | Already Passed | Complete Solution

Preview 2 out of 7  pages

  • June 24, 2024
  • 7
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
cse 2050 exam 2
[9, 7, 4, 2, 1]
[1, 7, 4, 2, 9]
[1, 2, 4, 7, 9] - ANS-selection sort -

[9, 7, 4, 2, 1]
[1, 9, 7, 4, 2]
[1, 7, 4, 2, 9]
[1, 2, 7, 4, 9]
[1, 2, 4, 7, 9] - ANS-cocktail sort (bubble with alternating directions)

[9, 7, 4, 2, 1]
[7, 4, 2, 1, 9]
[4, 2, 1, 7, 9]
[2, 1, 4, 7, 9]
[1, 2, 4, 7, 9] - ANS-bubble sort - after x calls, the last x items are sorted

[9, 7, 4, 2, 1]
[7, 9, 4, 2, 1]
[4, 7, 6, 2, 1]
[2, 4, 7, 9, 1]
[1, 2, 4, 7, 9] - ANS-insertion sort - with each inner loop, select the next highest item and
move it to the end

binary search - ANS-a search algorithm that starts at the middle of a sorted set of
numbers and removes half of the data; this process repeats until the desired value is
found or all elements have been eliminated.

binary search - running time - ANS-asymptotic running time is o(log n)

binary search running time - ANS-linear time if we used slicing; asymptotic running time
is O(logn) because the tree of function calls a single chain of length at most O(log n) -
number of times you can cut n in half before it gets down to 1

bubble sort - algorithm - ANS-def --sort(L):
has_swapped = True
while(has_swapped):
has_swapped = False

, for i in range(len(L)-1):
if L[i] > L[i+1]:
L[i], L[i+1] = L[i+1], L[i]
swaps += 1
has_swapped = True

if no elements swapped during the pass, can safely exit

bubble sort - best, worst, average - ANS-O(n), O(n^2), O(n^2)

dynamic programming - ANS-storing previously calculated values to prevent repetitive
calculations and allow for quick retrievals as well as using smaller values to solve for
even larger ones

example binary search algorithm - ANS-def bs(array, element, start, end):
if start > end:
return -1
mid = (start + end) // 2
if element == array[mid]:
return mid
if element < array[mid]:
return bs(array, element, start, mid-1)
else:
return bs(array, element, mid+1, end)

example recursive program using memoization - 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]

fib_cache = {0:1, 1:1}

example recursive program using tabulation - ANS-def Fibonacci(n):
f=[]
f.append(1)
f.append(1)
for i in range(2, n+1):
f.append(f[i-1] + f[i-2])
return f[n]

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)

79271 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