Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Solved Assignment - Programming I | CS 150, Assignments of Computer Science

Material Type: Assignment; Professor: Lusth; Class: Programming I; Subject: CS-Computer Science; University: University of Alabama; Term: Fall 2009;

Typology: Assignments

2009/2010

Uploaded on 02/25/2010

koofers-user-ig6
koofers-user-ig6 🇺🇸

10 documents

1 / 1

Toggle sidebar

Related documents


Partial preview of the text

Download Solved Assignment - Programming I | CS 150 and more Assignments Computer Science in PDF only on Docsity! Recursion Name: E-mail: Section: True or False: A recurrence always has two cases. False True or False: A recurrence always has two kinds of cases. True True or False: A recursive function and a recurrence are closely related. True Explain how you can you tell a recursive case from a base case in a recursive function: base case when to stop and recursive case to continue Recursion works by solving a (smaller) version of the same problem (both answers begin with ‘s’). If you add zero to a number, you get that number as a result. Also, the sum of two numbers is the same as incrementing the sum of the first number and the predecessor of the second number. For example, 5 +8 is equal to increment(5 +7). Use these two facts to write a recurrence for adding two numbers (subtract one from a number to get its predecessor): add(x,y-1) + 1 Using the above recurrence as a basis, define a recursive function named plus for adding two numbers. You may assume the increment function is already defined. def plus(x,y): if y == 0: return x else: return plus(x,y-1) + 1 [Use your head] If you can get all but the first letter of a string s with the expression s[1:], then the expression s[2:] gets all but the first two letters of s. Reading worksheet Fall 2009 CS 150
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved