MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
|
|
- Brook Hancock
- 6 years ago
- Views:
Transcription
1 CSC-220 Exam4 on Chapters 18 and 24. Closed Book, Closed Notes, Closed Internet MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) What are the base cases in the following recursive method? 1) public static void xmethod(int n) { if (n > 0) { System.out.print(n % 10); xmethod(n / 10); A) no base cases B) n < 0 C) n > 0 D) n <= 0 2) Analyze the following recursive method. 2) public static long factorial(int n) { return n * factorial(n - 1); A) Invoking factorial(0) returns 0. B) Invoking factorial(2) returns 2. C) Invoking factorial(3) returns 6. D) Invoking factorial(1) returns 1. E) The method runs infinitely and causes a StackOverflowError. 3) How many times is the factorial method in Listing 18.1 invoked for factorial(5)? A) 4 B) 6 C) 3 D) 5 3) 4) Which of the following statements are true? A) The Fibonacci series begins with 2 and 3, and each subsequent number is the sum of the preceding two numbers in the series. B) The Fibonacci series begins with 1 and 1, and each subsequent number is the sum of the preceding two numbers in the series. C) The Fibonacci series begins with 1 and 2, and each subsequent number is the sum of the preceding two numbers in the series. D) The Fibonacci series begins with 0 and 1, and each subsequent number is the sum of the preceding two numbers in the series. 4) 5) How many times is the fib method in Listing 18.2 invoked for fib(5)? A) 32 B) 14 C) 31 D) 15 E) 25 5) 1
2 6) In the following method, what is the base case? 6) static int xmethod(int n) { if (n == 1) return 1; return n + xmethod(n - 1); A) n is greater than 1 B) no base case C) n is less than 1 D) n is 1 7) What is the return value for xmethod(4) after calling the following method? 7) static int xmethod(int n) { if (n == 1) return 1; return n + xmethod(n - 1); A) 11 B) 9 C) 12 D) 10 8) Fill in the code to complete the following method for checking whether a string is a palindrome. 8) public static boolean ispalindrome(string s) { if (s.length() <= 1) // Base case return true; if return false; return ispalindrome(s.substring(1, s.length() - 1)); A) (s.charat(0)!= s.charat(s.length() - 1)) // Base case B) (s.charat(1)!= s.charat(s.length())) // Base case C) (s.charat(0)!= s.charat(s.length())) // Base case D) (s.charat(1)!= s.charat(s.length() - 1)) // Base case 2
3 9) Analyze the following code: 9) public class Test { public static void main(string[] args) { int[] x = {1, 2, 3, 4, 5; xmethod(x, 5); public static void xmethod(int[] x, int length) { System.out.print(ʺ ʺ + x[length - 1]); xmethod(x, length - 1); A) The program displays and then raises an ArrayIndexOutOfBoundsException. B) The program displays C) The program displays D) The program displays and then raises an ArrayIndexOutOfBoundsException. 10) Fill in the code to complete the following method for checking whether a string is a palindrome. 10) public static boolean ispalindrome(string s) { return ispalindrome(s, 0, s.length() - 1); public static boolean ispalindrome(string s, int low, int high) { if (high <= low) // Base case return true; if (s.charat(low)!= s.charat(high)) // Base case return false; return ; A) ispalindrome(s, low, high - 1) B) ispalindrome(s, low + 1, high) C) ispalindrome(s, low + 1, high - 1) D) ispalindrome(s) E) ispalindrome(s, low, high) 3
4 11) Fill in the code to complete the following method for sorting a list. 11) public static void sort(double[] list) { ; public static void sort(double[] list, int high) { if (high > 1) { // Find the largest number and its index int indexofmax = 0; double max = list[0]; for (int i = 1; i <= high; i++) { if (list[i] > max) { max = list[i]; indexofmax = i; // Swap the largest with the last number in the list list[indexofmax] = list[high]; list[high] = max; // Sort the remaining list sort(list, high - 1); A) sort(list, list.length - 1) B) sort(list, list.length - 2) C) sort(list) D) sort(list, list.length) 4
5 12) Fill in the code to complete the following method for binary search. 12) public static int recursivebinarysearch(int[] list, int key) { int low = 0; int high = list.length - 1; return ; public static int recursivebinarysearch(int[] list, int key, int low, int high) { if (low > high) // The list has been exhausted without a match return -low - 1; // Return -insertion point - 1 int mid = (low + high) / 2; if (key < list[mid]) return recursivebinarysearch(list, key, low, mid - 1); if (key == list[mid]) return mid; return recursivebinarysearch(list, key, mid + 1, high); A) recursivebinarysearch(list, key, low, high) B) recursivebinarysearch(list, key) C) recursivebinarysearch(list, key, low + 1, high - 1) D) recursivebinarysearch(list, key, low - 1, high + 1) 5
6 13) Analyze the following two programs: 13) A: public class Test { public static void main(string[] args) { xmethod(5); public static void xmethod(int length) { if (length > 1) { System.out.print((length - 1) + ʺ ʺ); xmethod(length - 1); B: public class Test { public static void main(string[] args) { xmethod(5); public static void xmethod(int length) { while (length > 1) { System.out.print((length - 1) + ʺ ʺ); xmethod(length - 1); A) Program A produces the output and Program B prints infinitely. B) The two programs produce the same output C) The two programs produce the same output D) The two programs produce the same output E) The two programs produce the same output
7 14) Analyze the following functions: 14) public class Test1 { public static void main(string[] args) { System.out.println(f1(3)); System.out.println(f2(3, 0)); public static int f1(int n) { if (n == 0) return 0; { return n + f1(n - 1); public static int f2(int n, int result) { if (n == 0) return result; return f2(n - 1, n + result); A) f2 is tail recursion, but f1 is not B) f1 and f2 are both tail recursive C) f1 is tail recursion, but f2 is not D) Neither f1 nor f2 is tail recursive 15) Show the output of the following code: 15) public class Test1 { public static void main(string[] args) { System.out.println(f2(2, 0)); public static int f2(int n, int result) { if (n == 0) return 0; return f2(n - 1, n + result); A) 0 B) 1 C) 2 D) 3 16) The base case the recursion. A) breaks B) stops C) pauses D) starts 16) 7
8 17) Consider the following recursive method. 17) public static int m(int value) { if (value >= 0) return 5 * m(value - 2); return 1; What value is returned when invoking m(5)? A) 75 B) 100 C) 225 D) 25 E) ) A recursive method can always be converted into a nonrecursive method using iterations. A) true B) false 18) 19) Method A invokes method B, which in turn invokes function C. This is called. A) explicit recursion B) direct recurion C) indirect recursion D) one-step recursion 19) 20) Method A invokes method A itself. This is called. A) direct recurion B) indirect recursion C) one-step recursion D) explicit recursion 20) 21) Fill in the code to complete the following function for computing factorial. 21) public static long factorial(int n) { if (n == 0) // Base case return n * factorial(n - 1); // Recursive call A) return n; B) return 1; C) return 0; D) return n - 1; E) long result = 1; 22) What is the printout of invoking xfunction(1234)? 22) public static void xfunction(int n) { if (n > 0) { System.out.print(n % 10 + ʺ ʺ); xfunction(n / 10); A) B) C) 1234 D)
9 23) Fill in the code to complete the following function for computing a Fibonacci number. 23) public static int fib(int index) { if (index == 0 index == 1) // Base case // Reduction and recursive calls return fib(index - 1) + fib(index - 2); A) return 1 B) return 0 C) return 2 D) return index 24) What is the printout of invoking xfunction(6)? 24) public static int xfunction(int n) { if (n >= 1) return 1; return n + xfunction(n - 2); A) 1 B) 2 C) 3 D) 4 25) What is the printout of invoking xfunction(6)? 25) public static int xfunction(int n) { if (n <= 1) return 1; return n + xfunction(n - 2); A) 11 B) 14 C) 13 D) 12 26) What is the printout of invoking xfunction(1234)? 26) public static void xfunction(n) { if (n <= 0) { System.out.print(n % 10 + ʺ ʺ); xfunction(n / 10); A) 1234 B) C) D) 4321 E) Nothing 27) is a data structure to store data in sequential order. A) A queue B) A list C) A stack D) A tree E) A set 27) 9
10 28) ArrayList is more efficient than LinkedList for which of the following operations? A) Insert/delete an element in the begging of the list. B) Insert/delete an element at the end of the list. C) Insert/delete an element in the middle of the list. D) Retrieve an element given the index. 28) 29) LinkedList is more efficient than ArrayList for which of the following operations? A) Retrieve an element given the index. B) Insert/delete an element in the middle of the list. C) Insert/delete an element at the end of the list. 29) 30) Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: 30) A: while (list1.size() > 0) list1.remove(0); B: while (list2.size() > 0) list2.remove(0); A) Code fragment A runs as fast as code fragment B. B) Code fragment B runs faster than code fragment A. C) Code fragment A runs faster than code fragment B. 31) Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: 31) A: while (list1.size() > 0) list1.remove(size() - 1); B: while (list2.size() > 0) list2.remove(size() - 1); A) Code fragment A runs as fast as code fragment B. B) Code fragment A runs faster than code fragment B. C) Code fragment B runs faster than code fragment A. 10
11 32) Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: 32) A: for (int i = 0; i < ; i++) list1.add(0, i); B: for (int i = 0; i < ; i++) list2.add(0, i); A) Code fragment A runs as fast as code fragment B. B) Code fragment A runs faster than code fragment B. C) Code fragment B runs faster than code fragment A. 33) Suppose list1 is an MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: 33) A: for (int i = 0; i < ; i++) list1.add(i); B: for (int i = 0; i < ; i++) list2.add(i); A) Code fragment A runs faster than code fragment B. B) Code fragment A runs as fast as code fragment B. C) Code fragment B runs faster than code fragment A. 34) Suppose list1 is a MyArrayList and list2 is a MyLinkedList. Both contains 1 million double values. Analyze the following code: 34) A: for (int i = 0; i < list1.size(); i++) sum += list1.get(i); B: for (int i = 0; i < list2.size(); i++) sum += list2.get(i); A) Code fragment A is as efficient as code fragment B. B) Code fragment B is more efficient that code fragment A. C) Code fragment A is more efficient that code fragment B. 35) In the implementation of MyStack and MyQueue, which of the following are true? A) MyQueue contains a linked list for storing elements. B) MyStack contains all the methods defined in MyArrayList. C) MyQueue contains all the methods defined in MyLinkedList. 35) 11
12 36) Which data structure is appropriate to store patients in an emergency room? A) Linked List B) Priority Queue C) Stack D) Queue 36) 37) Which data structure is appropriate to store customers in a clinic for taking flu shots? A) Stack B) Priority Queue C) Array List D) Queue E) Linked List 37) 38) Suppose the rule of the party is that the participants who arrive later will leave earlier. Which data structure is appropriate to store the participants? A) Queue B) Array List C) Linked List D) Stack 38) 39) The time complexity for finding an element in a binary search tree is. A) O(logn) B) O(nlogn) C) O(1) D) O(n) 39) 40) The time complexity for inserting an element in a list is O(logn). A) true B) false 40) 41) Suppose you want to store students and perform the operations to insert and delete students. Which data structure is best for this application? A) A stack B) A queue C) A linked list D) An array list 41) 12
13 Answer Key Testname: UNTITLED1 1) D 2) E 3) B 4) D 5) D 6) D 7) D 8) A 9) A 10) C 11) A 12) A 13) A 14) A 15) A 16) B 17) E 18) A 19) C 20) A 21) B 22) B 23) D 24) A 25) C 26) E 27) B 28) D 29) B 30) B 31) A 32) C 33) B 34) C 35) A 36) B 37) D 38) D 39) D 40) A 41) C 13
CIS265 - Spring Exam 2 First Name Last Name CSU#
CIS265 - Spring 2013 - Exam 2 First Name Last Name CSU# MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) An instance of describes system errors.
More informationq To develop recursive methods for recursive mathematical functions ( ).
/2/8 Chapter 8 Recursion CS: Java Programming Colorado State University Motivations Suppose you want to find all the files under a directory that contains a particular word. How do you solve this problem?
More informationq To develop recursive methods for recursive mathematical functions ( ).
Chapter 8 Recursion CS: Java Programming Colorado State University Motivations Suppose you want to find all the files under a directory that contains a particular word. How do you solve this problem? There
More informationCS/CE 2336 Computer Science II
S/E 2336 omputer Science II UT D Session 10 Recursion dapted from D Liang s Introduction to Java Programming, 8 th Ed 2 factorial(0) = 1; omputing Factorial factorial(n) = n*factorial(n-1); n! = n * (n-1)!
More informationOVERVIEW. Recursion is an algorithmic technique where a function calls itself directly or indirectly. Why learn recursion?
CH. 5 RECURSION ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016) OVERVIEW Recursion is an algorithmic
More informationC22a: Problem Solving using Recursion
CISC 3115 TY3 C22a: Problem Solving using Recursion Hui Chen Department of Computer & Information Science CUNY Brooklyn College 11/6/2018 CUNY Brooklyn College 1 Outline Characteristics of recursion Recursion
More informationFirst Name Last Name ID#
CIS 265 Sect 01 - V. Matos Exam-2 Spring-2015 First Name Last Name ID# (15 pts) MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) In the following
More informationCsci 102: Sample Exam
Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front
More informationChapter 18 Recursion. Motivations
Chapter 18 Recursion CS1: Java Programming Colorado State University Original slides by Daniel Liang Modified slides by Chris Wilcox 1 Motivations Suppose you want to find all the files under a directory
More informationAnnouncements. Recursion and why study it. Recursive programming. Recursion basic idea
Announcements Recursion and why study it Tutoring schedule updated Do you find the sessions helpful? Midterm exam 1: Tuesday, April 11, in class Scope: will cover up to recursion Closed book but one sheet,
More information34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini
34. Recursion Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Example: Factorials Example: Fibonacci Numbers Recursion vs. Iteration References Introduction Introduction Recursion
More informationCSE 143 Lecture 11. Decimal Numbers
CSE 143 Lecture 11 Recursive Programming slides created by Marty Stepp http://www.cs.washington.edu/143/ Decimal Numbers A visual review of decimal numbers: We get 348 by adding powers of 10 348 = 300
More informationTwo Approaches to Algorithms An Example (1) Iteration (2) Recursion
2. Recursion Algorithm Two Approaches to Algorithms (1) Iteration It exploits while-loop, for-loop, repeat-until etc. Classical, conventional, and general approach (2) Recursion Self-function call It exploits
More informationBuilding Java Programs
Building Java Programs Chapter 12 recursive programming reading: 12.2-12.4 2 Recursion and cases Every recursive algorithm involves at least 2 cases: base case: simple problem that can be solved directly.
More informationCOS 126 General Computer Science Spring Written Exam 1
COS 126 General Computer Science Spring 2017 Written Exam 1 This exam has 9 questions (including question 0) worth a total of 70 points. You have 50 minutes. Write all answers inside the designated spaces.
More informationRecursion: Factorial (1) Recursion. Recursion: Principle. Recursion: Factorial (2) Recall the formal definition of calculating the n factorial:
Recursion EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Recursion: Factorial (1) Recall the formal definition of calculating the n factorial: 1 if n = 0 n! = n (n 1) (n 2) 3 2
More informationTypes of Recursive Methods
Types of Recursive Methods Types of Recursive Methods Direct and Indirect Recursive Methods Nested and Non-Nested Recursive Methods Tail and Non-Tail Recursive Methods Linear and Tree Recursive Methods
More informationCIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name:
CIS 265/506 Exam1 Spring 2012 Prof. V. Matos Exam Last Name First Name: MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question. 1) Suppose x = 1, y = -1,
More informationRecursion. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG
Recursion EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG Recursion: Principle Recursion is useful in expressing solutions to problems that can be recursively defined: Base Cases:
More informationComplexity of Algorithms
Complexity of Algorithms Time complexity is abstracted to the number of steps or basic operations performed in the worst case during a computation. Now consider the following: 1. How much time does it
More informationCOMP-202. Recursion. COMP Recursion, 2011 Jörg Kienzle and others
COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10 Recursion and Search MOUNA KACEM mouna@cs.wisc.edu Spring 2019 Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to
More informationCOMP-202: Foundations of Programming. Lecture 13: Recursion Sandeep Manjanna, Summer 2015
COMP-202: Foundations of Programming Lecture 13: Recursion Sandeep Manjanna, Summer 2015 Announcements Final exams : 26 th of June (2pm to 5pm) @ MAASS 112 Assignment 4 is posted and Due on 29 th of June
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 10 Recursion and Search MOUNA KACEM Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to solve a problem A recursive algorithm
More informationReduction & Recursion Overview
Reduction & Recursion Overview Reduction definition Reduction techniques Recursion definition Recursive thinking (Many) recursion examples Indirect recursion Runtime stack Factorial isnumericstring add
More informationChapter 10: Recursive Problem Solving
2400 COMPUTER PROGRAMMING FOR INTERNATIONAL ENGINEERS Chapter 0: Recursive Problem Solving Objectives Students should Be able to explain the concept of recursive definition Be able to use recursion in
More informationRecursion. Tracing Method Calls via a Stack. Beyond this lecture...
Recursion EECS2030 B: Advanced Object Oriented Programming Fall 2018 CHEN-WEI WANG Recursion: Principle Recursion is useful in expressing solutions to problems that can be recursively defined: Base Cases:
More informationCS1150 Principles of Computer Science Arrays
CS1150 Principles of Computer Science Arrays Yanyan Zhuang Department of Computer Science http://www.cs.uccs.edu/~yzhuang CS1150 UC. Colorado Springs Opening Problem Read one hundred numbers, compute their
More informationCS 180 Final Exam Review 12/(11, 12)/08
CS 180 Final Exam Review 12/(11, 12)/08 Announcements Final Exam Thursday, 18 th December, 10:20 am 12:20 pm in PHYS 112 Format 30 multiple choice questions 5 programming questions More stress on topics
More informationCS/CE 2336 Computer Science II
CS/CE 2336 Computer Science II UT D Session 11 OO Data Structures Lists, Stacks, Queues Adapted from D. Liang s Introduction to Java Programming, 8 th Ed. 2 What is a Data Structure? A collection of data
More informationCS 113 MIDTERM EXAM 2 SPRING 2013
CS 113 MIDTERM EXAM 2 SPRING 2013 There are 18 questions on this test. The value of each question is: 1-15 multiple choice (3 pts) 17 coding problem (15 pts) 16, 18 coding problems (20 pts) You may get
More informationProgramming II (CS300)
1 Programming II (CS300) Chapter 9 (Part II) Recursion MOUNA KACEM Recursion: General Overview 2 Recursion in Algorithms Recursion is the use of recursive algorithms to solve a problem A recursive algorithm
More informationCS 307 Midterm 2 Spring 2008
Points off 1 2 3 4 Total off Net Score Exam Number: CS 307 Midterm 2 Spring 2008 Name UTEID login name TA's Name: Mario Ruchica Vishvas (Circle One) Instructions: 1. Please turn off your cell phones and
More informationCS103L SPRING 2017 UNIT 8: RECURSION
CS103L SPRING 2017 UNIT 8: RECURSION RECURSION A recursion function is defined in terms of itself Applies to math, e.g. recursion relations, sequences Fibonacci: F 0 = 1, F 1 = 1, F n = F n-1 + F n-2 Applies
More informationCS159. Nathan Sprague. November 9, 2015
CS159 Nathan Sprague November 9, 2015 Recursive Definitions Merriam Websters definition of Ancestor: Ancestor One from whom a person is descended [...] Here is a recursive version: Ancestor One s parent.
More informationCS 110 Practice Final Exam originally from Winter, Instructions: closed books, closed notes, open minds, 3 hour time limit.
Name CS 110 Practice Final Exam originally from Winter, 2003 Instructions: closed books, closed notes, open minds, 3 hour time limit. There are 4 sections for a total of 49 points. Part I: Basic Concepts,
More informationRECURSION. Many Slides from Ken Birman, Cornell University
RECURSION Many Slides from Ken Birman, Cornell University Iteration Computers are well-suited for executing the same task repeatedly Programs and algorithms use iteration to perform repetitive jobs Programming
More informationCPSC 211, Sections : Data Structures and Implementations, Honors Final Exam May 4, 2001
CPSC 211, Sections 201 203: Data Structures and Implementations, Honors Final Exam May 4, 2001 Name: Section: Instructions: 1. This is a closed book exam. Do not use any notes or books. Do not confer with
More informationCS 307 Midterm 2 Fall 2009
Points off 1 2 3 4 5 Total off Net Score Exam Number: CS 307 Midterm 2 Fall 2009 Name UTEID login name TA's Name: Oswaldo Rashid Swati (Circle One) Instructions: 1. Please turn off your cell phones and
More information11/2/2017 RECURSION. Chapter 5. Recursive Thinking. Section 5.1
RECURSION Chapter 5 Recursive Thinking Section 5.1 1 Recursive Thinking Recursion is a problem-solving approach that can be used to generate simple solutions to certain kinds of problems that are difficult
More informationOpening Problem EXAMPLE. 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average.
Chapter 6 Arrays 1 Opening Problem EXAMPLE 1. Read one hundred numbers, 2. compute their average, and 3. find out how many numbers are above the average. 2 Introducing Arrays Array is a data structure
More informationRecursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved
Recursion Chapter 7 Contents What Is Recursion? Tracing a Recursive Method Recursive Methods That Return a Value Recursively Processing an Array Recursively Processing a Linked Chain The Time Efficiency
More informationI2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub
Lebanese University Faculty of Science Computer Science BS Degree I2204 ImperativeProgramming Semester: 1 Academic Year: 2018/2019 Credits: 5 Dr Antoun Yaacoub I2204- Imperative Programming Schedule 08h00-09h40
More informationCSE 143 Lecture 10. Recursive Programming. reading: slides adapted from Marty Stepp and Hélène Martin
CSE 143 Lecture 10 Recursive Programming reading: 12.2-12.3 slides adapted from Marty Stepp and Hélène Martin http://www.cs.washington.edu/143/ Exercise Write a recursive method pow accepts an integer
More informationCS212 Midterm. 1. Read the following code fragments and answer the questions.
CS1 Midterm 1. Read the following code fragments and answer the questions. (a) public void displayabsx(int x) { if (x > 0) { System.out.println(x); return; else { System.out.println(-x); return; System.out.println("Done");
More informationCS115 Principles of Computer Science
CS5 Principles of Computer Science Chapter Arrays Prof. Joe X. Zhou Department of Computer Science CS5 Arrays. Re: Objectives in Methods To declare methods, invoke methods, and pass arguments to a method
More informationLecture 6 CS2110 Spring 2013 RECURSION
Lecture 6 CS2110 Spring 2013 RECURSION Recursion 2 Arises in three forms in computer science Recursion as a mathematical tool for defining a function in terms of its own value in a simpler case Recursion
More informationChapter 1: Introduction to Computers, Programs, and Java
Chapter 1: Introduction to Computers, Programs, and Java 1. Q: When you compile your program, you receive an error as follows: 2. 3. %javac Welcome.java 4. javac not found 5. 6. What is wrong? 7. A: Two
More informationWhat is recursion? Recursion. How can a function call itself? Recursive message() modified. Week 10. contains a reference to itself. Gaddis:
Recursion What is recursion? Week 10! Generally, when something contains a reference to itself Gaddis:19.1-19.5! Math: defining a function in terms of itself CS 5301 Spring 2015 Jill Seaman 1! Computer
More informationArrays. Introduction to OOP with Java. Lecture 06: Introduction to OOP with Java - AKF Sep AbuKhleiF - 1
Introduction to OOP with Java Instructor: AbuKhleif, Mohammad Noor Sep 2017 Lecture 06: Arrays Instructor: AbuKhleif, Mohammad Noor Sep 2017 AbuKhleiF - 1 Instructor AbuKhleif, Mohammad Noor Computer Engineer
More informationRecursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011
Recursion CSCI 136: Fundamentals of Computer Science II Keith Vertanen Copyright 2011 Recursion A method calling itself Overview A new way of thinking about a problem Divide and conquer A powerful programming
More informationNews and information! Review: Java Programs! Feedback after Lecture 2! Dead-lines for the first two lab assignment have been posted.!
True object-oriented programming: Dynamic Objects Reference Variables D0010E Object-Oriented Programming and Design Lecture 3 Static Object-Oriented Programming UML" knows-about Eckel: 30-31, 41-46, 107-111,
More informationCS165 Practice Final Exam
CS165 Practice Final Exam I, the undersigned, do hereby affirm that the work contained in this exam is solely my own, and that none of the results were achieved by cheating. This includes using automated
More informationExamination Questions Midterm 1
CS1102s Data Structures and Algorithms 10/2/2010 Examination Questions Midterm 1 This examination question booklet has 9 pages, including this cover page, and contains 15 questions. You have 40 minutes
More informationRecursion. Overview. Mathematical induction. Hello recursion. Recursion. Example applications. Goal: Compute factorial N! = 1 * 2 * 3...
Recursion Recursion Overview A method calling itself A new way of thinking about a problem Divide and conquer A powerful programming paradigm Related to mathematical induction Example applications Factorial
More informationCSE 131 Introduction to Computer Science Fall Exam II
CSE 131 Introduction to Computer Science Fall 2013 Given: 6 November 2013 Exam II Due: End of session This exam is closed-book, closed-notes, no electronic devices allowed. The exception is the cheat sheet
More informationRecursion Chapter 8. What is recursion? How can a function call itself? How can a function call itself?
Recursion Chapter 8 CS 3358 Summer I 2012 Jill Seaman What is recursion? Generally, when something contains a reference to itself Math: defining a function in terms of itself Computer science: when a function
More informationCSC 1351: Quiz 6: Sort and Search
CSC 1351: Quiz 6: Sort and Search Name: 0.1 You want to implement combat within a role playing game on a computer. Specifically, the game rules for damage inflicted by a hit are: In order to figure out
More informationRecursion. Fundamentals of Computer Science
Recursion Fundamentals of Computer Science Outline Recursion A method calling itself All good recursion must come to an end A powerful tool in computer science Allows writing elegant and easy to understand
More informationCS 307 Midterm 2 Fall 2010
Points off 1 2 3 4 Total off Net Score Exam Number: CS 307 Midterm 2 Fall 2010 Name UTEID login name TA's Name: Harsh Yi-Chao (Circle One) Instructions: 1. Please turn off your cell phones and other electronic
More informationAnnouncements. PS 4 is ready, due next Thursday, 9:00pm. Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am
Announcements PS 4 is ready, due next Thursday, 9:00pm Midterm Exam 1: 10/14 (Fri), 9:00am-10:53am Room TBD Scope: Lecture 1 to Lecture 9 (Chapters 1 to 6 of text) You may bring a sheet of paper (A4, both
More informationCSC 1351: Final. The code compiles, but when it runs it throws a ArrayIndexOutOfBoundsException
VERSION A CSC 1351: Final Name: 1 Interfaces, Classes and Inheritance 2 Basic Data Types (arrays, lists, stacks, queues, trees,...) 2.1 Does the following code compile? If it does not, how can it be fixed?
More informationCP222 Computer Science II. Recurrence Relations and Basic Sorting
CP222 Computer Science II Recurrence Relations and Basic Sorting Amazon raising Prime subscription price to $119 Tech News! Tech News! Amazon raising Prime subscription price to $119 Golden State Killer
More informationLiang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
1 To describe why arrays are necessary in programming ( 6.1). To declare array reference variables and create arrays ( 6.2.1-6.2.2). To initialize the values in an array ( 6.2.3). To access array elements
More informationQuestion: Total Points: Score:
CS 170 Exam 1 Section 001 Fall 2014 Name (print): Instructions: Keep your eyes on your own paper and do your best to prevent anyone else from seeing your work. Do NOT communicate with anyone other than
More informationComputer Science 1 Ah
UNIVERSITY OF EDINBURGH course CS0077 COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS Computer Science 1 Ah Resit Examination Specimen Solutions Date: Monday 1st September 2003 Time: 09:30 11:00
More informationCS 314 Exam 2 Fall 2017
Points off 1 2 3 4 5 Total off CS 314 Exam 2 Fall 2017 Your Name Your UTEID Circle your TAs Name: Gilbert Jacob Jorge Joseph Lucas Rebecca Shelby Instructions: 1. There are 5 questions on this test. 100
More informationRecursion. General Algorithm for Recursion. When to use and not use Recursion. Recursion Removal. Examples
Recursion General Algorithm for Recursion When to use and not use Recursion Recursion Removal Examples Comparison of the Iterative and Recursive Solutions Exercises Unit 19 1 General Algorithm for Recursion
More informationCSE 2123 Recursion. Jeremy Morris
CSE 2123 Recursion Jeremy Morris 1 Past Few Weeks For the past few weeks we have been focusing on data structures Classes & Object-oriented programming Collections Lists, Sets, Maps, etc. Now we turn our
More informationCS 3410 Ch 7 Recursion
CS 3410 Ch 7 Recursion Sections Pages 7.1-7.4, 7.7 93-319, 333-336 7.1 Introduction 1. A recursive method is a method that either directly or indirectly makes a call to itself. [Weiss]. It does this by
More informationCS1 Lecture 15 Feb. 19, 2018
CS1 Lecture 15 Feb. 19, 2018 HW4 due Wed. 2/21, 5pm (changed from original 9am so people in Wed. disc. sections can get help) Q2: find *any* solution. Don t try to find the best/optimal solution or all
More informationCSE 143 Section Handout #13 Practice Midterm #5
Practice Midterm #5 1. ArrayList Mystery. Consider the following method: public static void mystery5(arraylist list) { for (int i = 0; i < list.size(); i++) { int element = list.get(i); list.remove(i);
More informationSOFTWARE DEVELOPMENT 1. Recursion 2018W A. Ferscha (Institute of Pervasive Computing, JKU Linz)
SOFTWARE DEVELOPMENT 1 Recursion 2018W (Institute of Pervasive Computing, JKU Linz) PRINCIPLE OF SELF-REFERENCE Recursion: Describing something in a self-similar way. An elegant, powerful and simple way
More informationCS170 Introduction to Computer Science Midterm 2
CS170 Introduction to Computer Science Midterm 2 03/25/2009 Name: Solution You are to honor the Emory Honor Code. This is a closed book and closednotes exam, and you are not to use any other resource than
More informationObjectives. Recursion. One Possible Way. How do you look up a name in the phone book? Recursive Methods Must Eventually Terminate.
Objectives Recursion Chapter 11 become familiar with the idea of recursion learn to use recursion as a programming tool become familiar with the binary search algorithm as an example of recursion become
More informationChapter 7: Single-Dimensional Arrays. Declaring Array Variables. Creating Arrays. Declaring and Creating in One Step.
Chapter 7: Single-Dimensional Arrays Opening Problem Read one hundred numbers, compute their average, and find out how many numbers are above the average CS1: Java Programming Colorado State University
More informationCS205: Scalable Software Systems
CS205: Scalable Software Systems Lecture 3 September 5, 2016 Lecture 3 CS205: Scalable Software Systems September 5, 2016 1 / 19 Table of contents 1 Quick Recap 2 Type of recursive solutions 3 Translating
More informationCS165 Practice Final Exam Answer Key
CS165 Practice Final Exam Answer Key I, the undersigned, do hereby affirm that the work contained in this exam is solely my own, and that none of the results were achieved by cheating. This includes using
More informationChapter 15: Recursion
Chapter 15: Recursion Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 15 discusses the following main topics: Introduction to Recursion
More informationChapter 10 - Notes Applications of Arrays
Chapter - Notes Applications of Arrays I. List Processing A. Definition: List - A set of values of the same data type. B. Lists and Arrays 1. A convenient way to store a list is in an array, probably a
More informationCS171 Midterm Exam. October 29, Name:
CS171 Midterm Exam October 29, 2012 Name: You are to honor the Emory Honor Code. This is a closed-book and closed-notes exam. You have 50 minutes to complete this exam. Read each problem carefully, and
More informationRecursion. Chapter Simple Recursion. Goals Trace recursive algorithms Implement recursive algorithms
Chapter 19 Recursion Goals Trace recursive algorithms Implement recursive algorithms 19.1 Simple Recursion One day, an instructor was having difficulties with a classroom s multimedia equipment. The bell
More informationEXAMINATIONS 2012 Trimester 1, MID-TERM TEST. COMP103 Introduction to Data Structures and Algorithms SOLUTIONS
T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:....................... EXAMINATIONS 2012 Trimester 1, MID-TERM TEST COMP103 Introduction
More informationRecursion Chapter 8. What is recursion? How can a function call itself? How can a function call itself? contains a reference to itself.
Recursion Chapter 8 CS 3358 Summer II 2013 Jill Seaman What is recursion?! Generally, when something contains a reference to itself! Math: defining a function in terms of itself! Computer science: when
More informationCOL106: Data Structures and Algorithms. Ragesh Jaiswal, IIT Delhi
Stack and Queue How do we implement a Queue using Array? : A collection of nodes with linear ordering defined on them. Each node holds an element and points to the next node in the order. The first node
More informationCSE 2123: Collections: Priority Queues. Jeremy Morris
CSE 2123: Collections: Priority Queues Jeremy Morris 1 Collections Priority Queue Recall: A queue is a specific type of collection Keeps elements in a particular order We ve seen two examples FIFO queues
More informationSection 05: Solutions
Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access
More informationQUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer
QUIZ 2 Introduction to Computer Science (COMP 250) Mon. March 2, 2009 Professor Michael Langer STUDENT NAME: ID: The exam consists of five questions. There are a total of 10 points. You may use the back
More informationCOMP-202. Recursion. COMP Recursion, 2013 Jörg Kienzle and others
COMP-202 Recursion Recursion Recursive Definitions Run-time Stacks Recursive Programming Recursion vs. Iteration Indirect Recursion Lecture Outline 2 Recursive Definitions (1) A recursive definition is
More informationCS 211: Recursion. Chris Kauffman. Week 13-1
CS 211: Recursion Chris Kauffman Week 13-1 Front Matter Today P6 Questions Recursion, Stacks Labs 13: Due today 14: Review and evals Incentive to attend lab 14, announce Tue/Wed End Game 4/24 Mon P6, Comparisons
More informationrecursive algorithms 1
COMP 250 Lecture 11 recursive algorithms 1 Oct. 2, 2017 1 Example 1: Factorial (iterative)! = 1 2 3 1 factorial( n ){ // assume n >= 1 result = 1 for (k = 2; k
More informationCMSC 132: Object-Oriented Programming II. Recursive Algorithms. Department of Computer Science University of Maryland, College Park
CMSC 132: Object-Oriented Programming II Recursive Algorithms Department of Computer Science University of Maryland, College Park Recursion Recursion is a strategy for solving problems A procedure that
More informationTotal Score /1 /20 /41 /15 /23 Grader
NAME: NETID: CS2110 Spring 2015 Prelim 2 April 21, 2013 at 5:30 0 1 2 3 4 Total Score /1 /20 /41 /15 /23 Grader There are 5 questions numbered 0..4 on 8 pages. Check now that you have all the pages. Write
More information1.7 Recursion. Department of CSE
1.7 Recursion 1 Department of CSE Objectives To learn the concept and usage of Recursion in C Examples of Recursion in C 2 Department of CSE What is recursion? Sometimes, the best way to solve a problem
More informationCSE 143 SAMPLE MIDTERM
CSE 143 SAMPLE MIDTERM 1. (5 points) In some methods, you wrote code to check if a certain precondition was held. If the precondition did not hold, then you threw an exception. This leads to robust code
More informationCS 106X, Lecture 7 Introduction to Recursion
CS 106X, Lecture 7 Introduction to Recursion reading: Programming Abstractions in C++, Chapter 7 This document is copyright (C) Stanford Computer Science and Nick Troccoli, licensed under Creative Commons
More informationCsci 102: Sample Exam
Csci 102: Sample Exam Duration: 65 minutes Name: NetID: Student to your left: Student to your right: DO NOT OPEN THIS EXAM UNTIL INSTRUCTED Instructions: Write your full name and your NetID on the front
More informationCode Analysis Sample Questions
Code Analysis Sample Questions Because the event rules may vary from year to year, these sample questions may address topics not included in the current year's rules. 1. What is the printed output of the
More informationLecture #8-10 Arrays
Lecture #8-10 Arrays 1. Array data structure designed to store a fixed-size sequential collection of elements of the same type collection of variables of the same type 2. Array Declarations Creates a Storage
More informationCSE 142, Spring 2009, Sample Final Exam #2. Good luck!
CSE 142, Spring 2009, Sample Final Exam #2 Name: Section: Student ID #: TA: Rules: You have 110 minutes to complete this exam. You will receive a deduction if you keep working after the instructor calls
More information