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 5  pages

  • June 24, 2024
  • 5
  • 2023/2024
  • Exam (elaborations)
  • Questions & answers
avatar-seller
CSE 2050 Exam 2
Write a O(n) contains function with one line of code - ANS-return any(obj == item for i in
L)

What is the run time of binary search with slicing? - ANS-O(nlogn)

What is the run time of binary search with reference? - ANS-O(logn)

Why is iteration better than recursion? - ANS-Iteration is generally faster and takes less
memory space

Dynamic Programming - ANS-Sub-problems are solved from the bottom up. Each
problem is trivially solved as the combination of previously-solved subproblems.

Greedy Algorithm - ANS-an algorithm that always tries the solution path that appears to
be the best.

Memoization - ANS-Before attempting to solve a new sub-problem, a collection is
referenced to see if this sub-problem has already been solved.

Drawbacks of Recursion - ANS-Can be slow, take a lot of memory space, can solve the
same subproblems repeatedly

Recursion can help (?) - ANS-Explore branching paths

Recursion - ANS-the process of calling the function by itself until it reaches a base case

Binary Search - ANS-An ordered list is divided in 2 with each comparison.

Prune and Search - ANS-method for finding an optimal value by iteratively dividing a
search space into two parts

Invariant - ANS-something that holds true throughout the execution of a code

Invariant for Bubble Sort - ANS-The biggest items of the list are in their sorted, final
position after each loop

, Invariant for Selection Sort - ANS-Same thing with Bubble Sort, where the biggest items
of the list are in their sorted, final position after each loop

Invariant for Insertion Sort - ANS-After each loop, a small portion of the list, or sub list,
are sorted, but does not mean that each element are in their final position

Best and Worst Case for Bubble Sort - ANS-Best Case: if only one item (particularly the
rabbit) is unsorted, O(n)
Worst Case: O(n^2), has to go through every item (reversed sorted list, turtle,
randomized)

Best and Worse Case for Selection Sort - ANS-Best Case: reverse sorted, though
O(n^2), randomized sometimes
Worst Case: if just one object are out of places

Benefit of Using Selection Sort - ANS-It only makes one swap per element (O(n)), which
can reduce memory cost

Best and Worst Case for Insertion Sort - ANS-Best Case: only one object out of place
O(n) swap
Worst Case: reversed sorted (O(n^2))

Compare Insertion Sort vs Selection Sort (3) - ANS-1) Number of comparisons is less
than number of swaps in insertion
2) Insertion is generally more efficient
3) O(n) swaps in selection vs O(n^2) swaps in insertion

Why is Binary Search O(logn) - ANS-Every iteration is n/2^k, and after k divisions, the
length of the list will equal to 1. As a result, 1 = n/2^k, 2^k = n, which log2n = k.

Best Case for Binary Search - ANS-O(1), if median happens to be the item

Rank the O(n^2) (from best to worst) in a randomly distributed list - ANS-Insertion sort,
Selection Sort, Bubble Sort

Rank the O(n^2) if one item is out of place (also explain why Bubble performs bad when
it handles turtle) - ANS-Insertion, Bubble, Selection

Rank the O(n^2) if list is reversed sorted - ANS-Selection, Insertion, Bubble

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