Computer Science  >  SOLUTIONS MANUAL  >  CS 61A Final Review solutions - Santa Clara University COMPUTER MISC (All)

CS 61A Final Review solutions - Santa Clara University COMPUTER MISC

Document Content and Description Below

CS 61A Final Review Fall 2019 Discussion 14: December 4, 2019 Solutions 1 Recursion 1.1 (Adapted from Fall 2013) Fill in the blanks in the implementation of paths, which takes as input two positiv ... e integers x and y. It returns a list of paths, where each path is a list containing steps to reach y from x by repeated incrementing or doubling For instance, we can reach 9 from 3 by incrementing to 4, doubling to 8, then incrementing again to 9, so one path is [3, 4, 8, 9] def paths(x, y): Return a list of ways to reach y from x by repeated incrementing or doubling. >>> paths(3, 5) [[3, 4, 5]] >>> sorted(paths(3, 6)) [[3, 4, 5, 6], [3, 6]] >>> sorted(paths(3, 9)) [[3, 4, 5, 6, 7, 8, 9], [3, 4, 8, 9], [3, 6, 7, 8, 9]] >>> paths(3, 3) # No calls is a valid path [[3]] if _________________________: return ______________________________________________ elif _______________________: return ______________________________________________ else: a = _________________________________________________ b = _________________________________________________ return ______________________________________________ def paths(x, y): if x > y: return [] elif x == y: return [[x]] else: 2 Final Review a = paths(x + 1, y) b = paths(x * 2, y) return [[x] + subpath for subpath in a + b] Final Review 3 1.2 We will now write one of the faster sorting algorithms commonly used, known as merge sort. Merge sort works like this: 1. If there is only one (or zero) item(s) in the sequence, it is already sorted! 2. If there are more than one item, then we can split the sequence in half, sort each half recursively, then merge the results, using the merge procedure from earlier in the notes. The result will be a sorted sequence. Using the algorithm described, write a function mergesort(seq) that takes an unsorted sequence and sorts it. def mergesort(seq): [Show More]

Last updated: 2 years ago

Preview 1 out of 13 pages

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)
Preview image of CS 61A Final Review solutions - Santa Clara University COMPUTER MISC document

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Reviews( 0 )

$7.00

Buy Now

We Accept:

Payment methods accepted on Scholarfriends (We Accept)

Instant download

Can't find what you want? Try our AI powered Search

120
0

Document information


Connected school, study & course


About the document


Uploaded On

Nov 17, 2022

Number of pages

13

Written in

All

Seller


Profile illustration for Browsegrades
Browsegrades

Member since 3 years

0 Documents Sold

Additional information

This document has been written for:

Uploaded

Nov 17, 2022

Downloads

 0

Views

 120

Document Keyword Tags


$7.00
What is Scholarfriends

Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·