3 Pages

Assignment 8

Course: COMPUTER S 116, Spring 2010
School: Waterloo
Rating:
 
 
 
 
 

Word Count: 844

Document Preview

116 CS Fall 2010 Assignment 8 Due 10:00 AM on Tuesday, November 16 For this and all subsequent assignments, you are expected to use the design recipe when writing functions from scratch. The solutions you submit must be entirely your own work. Do not look up either full or partial solutions on the Internet or in printed sources. Please read the course Web page for more information on assignment policies and how...

Register Now

Unformatted Document Excerpt

Coursehero >> Canada >> Waterloo >> COMPUTER S 116

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
116 CS Fall 2010 Assignment 8 Due 10:00 AM on Tuesday, November 16 For this and all subsequent assignments, you are expected to use the design recipe when writing functions from scratch. The solutions you submit must be entirely your own work. Do not look up either full or partial solutions on the Internet or in printed sources. Please read the course Web page for more information on assignment policies and how to organize and submit your work. Be sure to download the interface le from the course Web page and to follow all the instructions listed in the style guide (on the Web page). Specically, your solutions should be placed in les a8qY.rkt, where Y is a value from 1 to 4. This assignment mostly tests your understanding of the material in CS 116 Lecture Module 8, on loops, especially for loops. You may not use recursion or abstract list functions on this assignment. As well, a function may not mutate its arguments unless required to do so. A note on online submission: if there is a problem at the deadline for the assignment, please check www.cs.uwaterloo.ca/cs116, which should be available even if Odyssey is not working. Further information may be available there. Language level: Any Python version in the range 2.5.0 to 2.7. 1. Given a list of positive integers, we can compute the jump out number as the number of jumps required to jump out of a list, starting at the rst position. A jump means that if we are at a value x in the list, we can jump ahead x numbers. Here are some examples, with some explanation: jump_out([]) 0, since an empty list requires no jumps to get out of. jump_out([1]) 1, since we start at the rst position (the number 1), and jump out because our jump of distance one is enough to jump out. jump_out([3,1]) 1 because the number 3 indicates we can jump a distance of 3, and there are less than three elements after 3 in the list, and thus, we can jump out of the list. jump_out[(2, 5, 2, 8, 1, 1]) 4 because we start at 2, which means we can jump two positions to the second 2. After this, we can jump two positions to the rst 1. From there, we jump one position to the second 1. Finally, we jump one position out of the list, which was a total of four jumps. See the following picture: [2, 5, 2, 8, 1, 1] Write jump_out which should produce the integer number of jumps required to jump out of the list [clarication added November 10]. 1 2. (a) Write the function extract_elem which consumes two lists: elements, an arbitrary list and a non-empty list of natural numbers positions. The function should produce a list values of from elements as indicated by positions. Suppose that elements is [x0 , x1 , ..., xn1 ]. Then all values in positions are integers in the range 0 to n 1. In particular, a value 4 in the list positions refers to x4 . Note that the values in positions may be repeated, but they will not be outside the range 0 to n 1. For example, extract_elem([a, b, c, d, e], [2, 0, 3, 0, 4]) should produce [c , a, d, a, e]. (b) Write the function shift_produce which consumes a list and an integer. The function should produce the list obtained after shifting the elements of the given list to the left by the indicated amount. For example: shift_produce([1,2,3],0) [1,2,3] shift_produce([1,2,3,4], 1) [2,3,4,1] shift_produce([1,2,3,4], -1) [4,1,2,3] (c) Write the function shift_mutate which consumes a list and an integer. The function should mutate the list obtained after shifting the elements of the given list to the left by the indicated amount. For example, if S = [1,2,3], T = [1,2,3,4] and U = [1,2,3,4,5], then shift_mutate(S,0) shift_mutate(T, 1) shift_mutate(U, -1) will cause S [1,2,3], T [2,3,4,1] and U [5,1,2,3,4]. 3. Given a matrix (possibly non-square) as a non-empty list of non-empty lists, we can transpose a matrix by reecting the elements across the diagonal that runs from the top-left corner to the bottom-right corner. For example, transpose([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) [[1, 4, 7], [2, 5, 8], [3,6,9]] and transpose([[1,2,3],[4,5,6]]) [[1,4],[2,5],[3,6]]. Note that the algorithm outlined in Assignment 4 will not work here: you will need to think about solving this problem differently in Python. 4. Write the function kth_largest which returns the k th largest element from a non-empty list of distinct numbers, given k and a non-empty list of numbers. Use a variant of quick-sort to solve this problem. For example, kth_largest(1, [1, 10, 2]) 2]) 1. 2 10 and kth_largest(3, [1, 10, You may assume that k will be no larger than the length of the given list, and that k 1. You should solve the problem using the following logic: partition the list into three parts: a pivot, a list containing those elements less than the pivot, and a list containing those that are greater than the pivot (Note: you may use filter for this part of this question only). there are three possible positions for the k th largest element: in the greater than set; it is the pivot element; in the smaller than set. You will need to gure out how to recognize these three cases, and what to do in each case. Reminder: you may not use recursion. 3
Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

University of Toronto - MAT - MAt240
MAT 240, University of Toronto Fall term, 2010Exerzitien VIDue no later than 2:30 pm on Nov. 4, in your tutorial.1234Exercise 1. Let L : R5 R5 be the left-shift linear operator dened by L : (x1 , x2 , x3 , x4 , x5 ) (x2 , x3 , x4 , x5 , 0). i) What is
UPR Carolina - INGLES - INGL4016
HowtobealeaderA leader is someone whom others trust and consistently look to for guidance.Ageorstatuswithinagroupmaycreateassumptionsabout whowilllead,butatrueleaderinspiressteadfastloyalty,earningthe trustofothers.LeadershipisaresponsibilitybutalsoanHon
University of Phoenix - BEH - BEH 225
Final Project: Interview ProfileFinal Project: Interview Profile By: Jessie Roe BEH/225 Instructor: Michele Marvel September 26th, 2010The person I am interviewing is my wife, Danielle. She prefers Dani as a nick-name. Unfortunately she is 20 years youn
University of Phoenix - HCA - HCA 240
ObesityFinal: Obesity By: Jessie Roe HCA/240 Instructor: Dolton James September 25th, 2010~1~ObesityIntroduction Obesity is a growing epidemic in this country. Currently one in three Americans is overweight or obese (About Weight Loss Surgery, 2009).
Oklahoma Baptist - BIOL - 1001
Environmental Biology Test Gross primary productivity Rate at which an ecosystems producers capture and store a given amount of chemical energy as biomass in a given length of time Habitat Refers to a place or type of place where an organism or population
University of Minnesota - CSCI - 4061
CSci 4061: Intro to Operating SystemsAssignment 2: Multi-process Web Browser Due:November 1 by 2:00pm. You will be assigned in a group of 3.1. PurposeMost traditional web browsers (like Firefox) run as a multithreaded process, rendering web pages on u
Carleton University - ECON - 101
Econ 201 Final Exam1. In a competitive market, no single producer can influence the market price because a. many other sellers are offering a product that is essentially identical. b. consumers have more influence over the market price than producers do.
Columbia College - BIOLOGY - C2005
Prep101http:/www.prep101.com/mcat/DISORDERS AND DISEASES COMMONLY COVERED ON THE MCAT GENETIC DISORDERS . 1 NUTRITIONAL DISORDERS . 4 INFECTIOUS DISEASES. 5 OTHER COMMON DISEASES . 6 GENETIC DISORDERS Single-Gene Disorders This category encompasses a w
UC Davis - NPB 12 - 72121
LECTURE 13: Balance and Hearing (Note: Professor Gregg Recanzone will give the lecture) VOR (Vestibulo-Ocular Response) A different kind of eye movement is involuntary, or at least in the sense that you don't have to think about it, and that relates to ke
UC Davis - NPB 12 - 72121
LECTURE 14: Learning and Memory / Memory and Learning For the rest of the course we will go into what I consider the big picture, and that is the function and dysfunction of the "higher" brain regions: the limbic system and the cerebral cortex. The first
University of Texas - BIO - Bio 320
Chapter 15Mechanisms of Cell CommunicationA simple intracellular signaling pathway activated by an extracellular signal moleculeCells communicate with each other through signaling moleculesHello!signaling celltarget cellCells that produce the signa
Albany State University - BUSINESS - mgmt 4199
COMPANY: Whole Foods Market, Inc. I. Summary Whole Foods Markets, Inc. is the largest natural foods retailer in the US. The company sells natural and organic foods in over 100 stores and in the following categories: produce, grocery, meat and poultry, sea
Andhra University - PHYS - 57741
Version PREVIEW Rotation & Gravity Chap. 7 sizemore (13756) This print-out should have 28 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. Apollo 11 in Orbit 001 (part 1 of 2) 10.0 points When i
Clark Atlanta - ACCT - acc205
CHAPTER 17ANSWERS TO QUESTIONS 1. The performance of services by nonbusiness organizations is based on social need rather than on the profit motive and there is no conscious or deliberate effort by such organizations to derive a profit from their operati
University of the West Indies at St. Augustine - MGMT - 1
PART2Important Financial ConceptsCHAPTERS IN THIS PART4 5 6 7Time Value of Money Risk and Return Interest Rates and Bond Valuation Stock ValuationINTEGRATIVE CASE 2: ENCORE INTERNATIONALChapter 4 Time Value of MoneyCHAPTER 4Time Value of Money IN
University of Baltimore - INSS - 640
CH 10: E-Commerce: Digital Markets, Digital Goods Markets,E-commerceSource:http:/www.online-commerce.com/index.htmlIt allows people to exchange goods and services immediately and with no barriers of time or distance. Any time of the day or night, you c
UOIT - EE - 2200
Laboratory 1: Lab Equipment Familiarity, Measuring Voltage and Current, Verification of Ohms and Kirchoff's LawsThe electrical engineering fundamental laboratory consists of 12 identically equipped individual laboratory workstations. Each workstation inc
Phoenix - ECON - 212
ECN212 Microeconomic Principles Five-Week Online FormatSection 12076, Summer 2010 Dr. Steve ThorpeEconomics FacultyLiberal Arts DepartmentPhoenix CollegeOffice: A132Phone: (602) 285-7819Email: steve.thorpe@pcmail.maricopa.edu Course Content Her
Ill. Chicago - PHYS - 12231
reddy (ar38357) Angular Momentum clancy (SCI411-2) This print-out should have 7 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A basketball player wishes to balance a ball on h
Ill. Chicago - PHYS - 12231
reddy (ar38357) Kinematics B clancy (SCI411-2) This print-out should have 10 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points An automobile accelerates from rest at 0.2 m/s2 for
Ill. Chicago - PHYS - 12231
reddy (ar38357) Vectors clancy (SCI411-2) This print-out should have 8 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points Consider two vectors A and B and their resul
Ill. Chicago - PHYS - 12231
reddy (ar38357) Projectile Motion clancy (SCI411-2) This print-out should have 6 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points1Note: Dotted curves X and Z are arcs of circle
Ill. Chicago - PHYS - 12231
Ill. Chicago - PHYS - 12231
reddy (ar38357) Kinematics A clancy (SCI411-2) This print-out should have 11 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points A physics book is moved once around th
Ill. Chicago - PHYS - 12231
Ill. Chicago - PHYS - 12231
reddy (ar38357) Energy and Rocket problems clancy (SCI411-2) This print-out should have 6 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points Note: A bungee cord can s
Ill. Chicago - PHYS - 12231
reddy (ar38357) Tension and inclined planes clancy (SCI411-2) This print-out should have 9 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points Can an object be in mechanical equilib
Ill. Chicago - PHYS - 12231
reddy (ar38357) Friction clancy (SCI411-2) This print-out should have 15 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points A block of mass m is accelerated across a
Ill. Chicago - PHYS - 12231
reddy (ar38357) Newtons Laws and Circular Motion clancy (SCI411-2) This print-out should have 12 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A car rounds a curve while maint
Ill. Chicago - PHYS - 12231
reddy (ar38357) Collisions clancy (SCI411-2) This print-out should have 9 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A balloon of mass M is oating motionless in the air. A
Ill. Chicago - PHYS - 12231
reddy (ar38357) Torque clancy (SCI411-2) This print-out should have 11 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points1002 10.0 points A friend incorrectly says that a body ca
Ill. Chicago - PHYS - 12231
reddy (ar38357) Center of Mass clancy (SCI411-2) This print-out should have 8 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A uniform at plate of metal with a circular hole is
Ill. Chicago - PHYS - 12231
reddy (ar38357) Rotational kinematics clancy (SCI411-2) This print-out should have 12 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points A record has an angular speed
Ill. Chicago - PHYS - 12231
reddy (ar38357) 2D Equilibrium clancy (SCI411-2) This print-out should have 5 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 (part 1 of 2) 10.0 points A student gets her car stuck in a sno
Ill. Chicago - PHYS - 12231
reddy (ar38357) Rotational Inertia clancy (SCI411-2) This print-out should have 8 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A non-uniform disk of mass M and radius R has i
Ill. Chicago - PHYS - 12231
reddy (ar38357) Newtons Second Law applied to Rotational Motion clancy (SCI411-2) 1 This print-out should have 3 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A cable passes o
Ill. Chicago - PHYS - 12231
reddy (ar38357) Rotational Kinetic Energy clancy (SCI411-2) This print-out should have 6 questions. Multiple-choice questions may continue on the next column or page nd all choices before answering. 001 10.0 points A 0.25 m power sawblade has a mass of 0.
UNC - PHYS - 100
NAME: _Physics 100 Fa2010Homework 6 Answer Sheet: Due 10/15 in class: Show Your Work for All ProblemsChapter 7, Case 7. EXPLAIN all answers! a. Energy enters as: electrical energy in the current carried through the bulbEnergy leaves as: thermal energy
Anna University - EEE - ee2303
TRANSMISSIONANDDISTRIBUTIONENGINEERINGKINGSCOLLEGE OF ENGINEERINGDEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERINGQUESTION BANKSUBJECT NAME : TRANSMISSION & DISTRIBUTION ENGINEERING YEAR / SEM : III/V UNIT-I TRANSMISSION SYSTEM PART-A 1. What is m
University of the Punjab - MATH - 1
CSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCSS.COM.PKCS
Cornell - AEM - 3200
Uniform Commercial Codes, Acts, and Articles Assume: UCC- goods Contract review problems 1. 2-708(2)- Recovery of full contract price of profit under full performance in a binding contract (7) 2. 2-708(1)- Specially manufactured items. The difference betw
University of Florida - CS - 5725
SETNAMGROUPS CTUREEND_REQUEST FI RST_NAM EDRL_I D SET_I AUTHOR NSRECEIUPLOAD OFEND_NAM E PROFI LE_IEAI DIAGRAM CATEGORY DON PI DEEMCOMSETS LANGUAGE LOCATIUSER_NAM E M EME E-DATE P_I AGEVER_ USER_NAMP_I D LAST_NAM E ON DESCRI PTIARE_ M GROUPED_I NTOCOUNTRY
Carleton - MAAE - 2700
1.1.Solve:1.2.Solve:1.3.Solve:1.4. Solve: (a) The basic idea of the particle model is that we will treat an object as if all its mass is concentrated into a single point. The size and shape of the object will not be considered. This is a reasonable
University of Phoenix - BEH - 225
Axia College MaterialAppendix D TV Character EvaluationThe first TV character is Olivia Benson from Law and Orders SVU. She is a tough cop with a partner. She is strong and good at catching rapist. Her mother was raped and Olivia was the product of rape
Baylor - SOC - 1305
CHAPTER3 CHAPTER3CULTURE CULTURE Awayoflifeforpeopleinasociety. Cultureislearned;itisnotinnate.Weall haveculture,noonehasmoreculturethan someoneelse,justdifferenttaste. Cultureconsistsofallthematerialandnon materialgoodsandservicesthatare transmittedan
Baylor - SOC - 1305
CHAPTER 11 LECTURE: SEX AND GENDERMUELLER(TOYS) and (Riddle) I. Sex and Gender A. Sex refers to the biological and anatomical differences between Females and Males; Hermaphrodites-have combination of male and females genitalia Transsexuals-often feel th
Baylor - SOC - 1305
Chapters 5 and 6 Mueller Society, Social Structure, and Interaction (5) Groups and Organizations (6)I.Introduction A. The Nature of Social Structure 1. The stable pattern of social relationships that exist within a particular group or society (Kendall a
Baylor - SOC - 1305
Chapter 8 Class and Stratification in the U.S. Text and Lecture main points: What is Social Stratification Social Stratification and the American Dream Systems of Stratification Classical Perspectives on Social class Contemporary Sociological Models of
Baylor - SOC - 1305
Baylor - SOC - 1305
CHAPTER 4 SOCIALIZATIONAround the Globe? Socializationis the life long process of social interaction through which people acquire a self-identity and the social skills needed for survival in societyHuman Development: Biology and Society: Nature v Nurt
Baylor - SOC - 1305
Chapter 2 Sociological Research Methods Whyis Sociological Research Necessary? -to add to our knowledge base -To move beyond common sense to more accurate understanding of social phenomenon - To debunk fallacies in everyday interpretations - to provide
Baylor - SOC - 1305
Baylor - SOC - 1305
WELCOME TO THE WORLD OF SOCIOLOGY TODAY:SEATINGCHART for Next Week ANNOUNCEMENTS: MENTORS MEET WITH ME AFTER CLASS NEXT WEEK NEW STUDENTS IN CLASS: Get Syllabus off Blackboard or from me and see Prof. Mueller after class next Tuesday.MAJOR TOPICS TODAY
Baylor - PHI - 1308
Shirae Butler PHI 1308 April 8, 2010Describe any two strategies DeYoung commends to counter avarice. How does each practice work to correct this vice? DeYoung explains two strategies that counters avarice. The fi rst way is to face your p roblem and know
Baylor - PHI - 1308
Baylor - PHI - 1308
Shirae Butler PHI 1308. 3 What are general remedies of the capital vices?The capital vices all have one thing in common. They tu rn us from seeking God. To get helped, we must first realize the problem that we have. The first remedy requires that we exan
Baylor - PHI - 1308
W hat are the four types of sinful pride according to Gregory? Gregory describes pride as the most deadly sin. He explains that every sin deprives from t he sin of pride like the following: vain glory, envy, anger, melancholy, avarice, gluttony, and l ust
Baylor - PHI - 1308
Shirae Butler PHI 1308 In what sense is God the cause of our willing? Since human beings sometimes will to do something sinful, in what sense is God the cause of human sin?According to Aquinas, our will is related to our intellect. Will doesnt move itsel
Baylor - PHI - 1308
Shirae ButlerPHI 1308What does Goldie mean by dispositionism? What are some bad reasons that we tend to be d ispostionists?Goldie defines dispositionism to be what we do when we assume a persons motives i n the way they act at a given t ime, the way th
Baylor - PHI - 1308
Shirae Butler PHI 1308What are the minimal features of a narrative, according to Goldie? How does self-narrative r elate to our sense of identity?Goldie defines the minimal features of a narrative is that i t should show connections between events in ou
Baylor - PHI - 1308