100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CSE 2050 Exam 2 - Recursion, Sorting, and Hashing with Correct Verified Answers| Latest 2024

Rating
-
Sold
-
Pages
14
Grade
A+
Uploaded on
01-07-2024
Written in
2023/2024

emoization - ANSWER 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 - ANSWER 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)

Show more Read less
Institution
CSE 2050
Course
CSE 2050









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CSE 2050
Course
CSE 2050

Document information

Uploaded on
July 1, 2024
Number of pages
14
Written in
2023/2024
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CSE 2050 Exam 2 - Recursion, Sorting, and Hashing with Correct Verified Answers | Latest 2024 Memoization - ANSWER 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 - ANSWER def fib(n, f ib_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 - ANSWER Can be more intuitive to code / understand. Can be memory saving if you don't need answers to all subproblems. Memoization Cons - ANSWER Depending on implementation, larger overhead due to recursion. Tabulation - ANSWER Bottom -Up. Solve smaller problems first. Then bigger problems. ... Then finally solve the real problem. Fib - Tab - ANSWER def fib(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] Linear Search - ANSWER Look for an item x in a sorted list. Approach: Step through a n array of items one at a time. Look for the item x. Search stops when... Item x is found. Or when search has examined all items and x is not found. Running Time: O(n) Binary Search - ANSWER Classic, recursive algorithm. If you are looking for an item in a sorted list, you break the list in half and repeat the search on whichever side you could contain the missing element, which can be found by comparing the median element. Then, repeating on the smaller list is just a single recursive call. Binary Se arch Poor Implementation - ANSWER def bs(L, item): if len(L) == 0: return False
CA$17.64
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
QUINTER New York College Of Dentistry
Follow You need to be logged in order to follow users or courses
Sold
342
Member since
2 year
Number of followers
104
Documents
38404
Last sold
2 days ago

3.4

57 reviews

5
25
4
8
3
7
2
1
1
16

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions