Data Abstraction & Problem Solving with C++: Walls and Mirrors 6th Edition Carrano, Henry Test Bank

Similar documents
Test Bank Ver. 5.0: Data Abstraction and Problem Solving with C++: Walls and Mirrors, 5 th edition, Frank M. Carrano

Recursion Solution. Counting Things. Searching an Array. Organizing Data. Backtracking. Defining Languages

Chapter 2. Question 2 Write a box trace of the function given in Checkpoint Question 1. We trace the function with 4 as its argument (see next page).

11/2/2017 RECURSION. Chapter 5. Recursive Thinking. Section 5.1

Recursion. Chapter 7

What is Recursion? ! Each problem is a smaller instance of itself. ! Implemented via functions. ! Very powerful solving technique.

Solutions for Selected Exercises

Programming with Recursion. What Is Recursion?

1 Recursion. 2 Recursive Algorithms. 2.1 Example: The Dictionary Search Problem. CSci 235 Software Design and Analysis II Introduction to Recursion

Identify recursive algorithms Write simple recursive algorithms Understand recursive function calling

Recursion. Chapter 7. Copyright 2012 by Pearson Education, Inc. All rights reserved

Solving problems by recursion

8/5/10 TODAY'S OUTLINE. Recursion COMP 10 EXPLORING COMPUTER SCIENCE. Revisit search and sorting using recursion. Recursion WHAT DOES THIS CODE DO?

Algorithm Efficiency & Sorting. Algorithm efficiency Big-O notation Searching algorithms Sorting algorithms

1) What is the primary purpose of template functions? 2) Suppose bag is a template class, what is the syntax for declaring a bag b of integers?

Recursive Definitions

CMSC 132: Object-Oriented Programming II. Recursive Algorithms. Department of Computer Science University of Maryland, College Park


Two Approaches to Algorithms An Example (1) Iteration (2) Recursion

Recursion Chapter 3.5

q To develop recursive methods for recursive mathematical functions ( ).

q To develop recursive methods for recursive mathematical functions ( ).

Announcements. Recursion and why study it. Recursive programming. Recursion basic idea

Announcement. Submit assignment 3 on CourSys Do not hand in hard copy Due Friday, 15:20:00. Caution: Assignment 4 will be due next Wednesday

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Chapter 15: Recursion

Recursive Thinking. Chapter 8: Recursion. Recursive Definitions. Recursion. Java Software Solutions for AP* Computer Science A 2nd Edition

Recursion. Dr. Jürgen Eckerle FS Recursive Functions

Recursion. Chapter 17 CMPE13. Cyrus Bazeghi

Lesson 12: Recursion, Complexity, Searching and Sorting. Modifications By Mr. Dave Clausen Updated for Java 1_5

def F a c t o r i a l ( n ) : i f n == 1 : return 1 else : return n F a c t o r i a l ( n 1) def main ( ) : print ( F a c t o r i a l ( 4 ) )

We cover recursion in 150. Why do it again in 151?

Recursion: Factorial (1) Recursion. Recursion: Principle. Recursion: Factorial (2) Recall the formal definition of calculating the n factorial:

CSC 1052 Algorithms & Data Structures II: Recursion

Fundamental mathematical techniques reviewed: Mathematical induction Recursion. Typically taught in courses such as Calculus and Discrete Mathematics.

Analyzing Complexity of Lists

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

Objectives. Recursion. One Possible Way. How do you look up a name in the phone book? Recursive Methods Must Eventually Terminate.

8 Algorithms 8.1. Foundations of Computer Science Cengage Learning

Unit-2 Divide and conquer 2016

Recursion. Example R1

Recursion: The Mirrors. (Walls & Mirrors - Chapter 2)

Chapter 17 Recursion

C22a: Problem Solving using Recursion

Recursive Methods and Problem Solving. Chris Kiekintveld CS 2401 (Fall 2010) Elementary Data Structures and Algorithms

Programming II (CS300)

Recursion. EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG

Divide & Conquer. 2. Conquer the sub-problems by solving them recursively. 1. Divide the problem into number of sub-problems

Recursion. Chapter 5

Software Development. Modular Design and Algorithm Analysis

Recursion(int day){return Recursion(day += 1);} Comp Sci 1575 Data Structures. Recursive design. Convert loops to recursion

Lecture Notes 4 More C++ and recursion CSS 501 Data Structures and Object-Oriented Programming Professor Clark F. Olson

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to:

Chapter 13 Recursion. Chapter Objectives

Fundamentals of Programming Session 13

Chapter 8 Algorithms 1

Programming II (CS300)

CSC 273 Data Structures

Plan of the lecture. Quick-Sort. Partition of lists (or using extra workspace) Quick-Sort ( 10.2) Quick-Sort Tree. Partitioning arrays

Programming II (CS300)

Data structure and algorithm in Python

Lecture Notes 14 More sorting CSS Data Structures and Object-Oriented Programming Professor Clark F. Olson

Chapter 12 Supplement: Recursion with Java 1.5. Mr. Dave Clausen La Cañada High School

Recursive Algorithms. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

= otherwise W-4 W-1. Overview. CSE 142 Computer Programming I. Overview. Factorial Function

Recursion. Chapter 11

12/30/2013 S. NALINI,AP/CSE

Induction and Recursion. CMPS/MATH 2170: Discrete Mathematics

CS205: Scalable Software Systems

Sorting Algorithms. + Analysis of the Sorting Algorithms

Recursion. Tracing Method Calls via a Stack. Beyond this lecture...

Lecture 6 Sorting and Searching

Component 02. Algorithms and programming. Sorting Algorithms and Searching Algorithms. Matthew Robinson

Why use recursion? Some problems are more easily expressed in a recursive definition

Recursion (Rosen, 6 th edition, Section 4.3, 4.4)

17CS33:Data Structures Using C QUESTION BANK

QuickSort

Recursion. Genome 559: Introduction to Statistical and Computational Genomics Elhanan Borenstein

Lecture P6: Recursion

Introduction to Algorithms

Pseudo code of algorithms are to be read by.

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

Lecture Notes on Linear Search

Sorting is a problem for which we can prove a non-trivial lower bound.

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Recursion. Thinking Recursively. Tracing the Recursive Definition of List. CMPT 126: Lecture 10. Recursion

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

Admin. How's the project coming? After these slides, read chapter 13 in your book. Quizzes will return

What is Recursion? Chapter 17 Recursion. Executing RunningSum. High-Level Example: Binary Search

Divide-and-Conquer. Divide-and conquer is a general algorithm design paradigm:

Chapter 13. Recursion. Copyright 2016 Pearson, Inc. All rights reserved.

More Complicated Recursion CMPSC 122

recursive algorithms 1

3/20/2015. Chapter 19 Sorting and Searching SELECTION SORT INSERTION SORT MERGE SORT THE QUICKSORT ALGORITHM MERGE SORT VS SELECTION SORT

C/C++ Programming Lecture 18 Name:

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

Copyright The McGraw-Hill Companies, Inc. Persion required for reproduction or display. What is Recursion?

34. Recursion. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

CMSC 150 LECTURE 7 RECURSION

Recursion. Overview. Mathematical induction. Hello recursion. Recursion. Example applications. Goal: Compute factorial N! = 1 * 2 * 3...

Transcription:

Data Abstraction & Problem Solving with C++: Walls and Mirrors 6th Edition Carrano, Henry Test Bank Download link: https://solutionsmanualbank.com/download/test-bank-for-data-abstractionproblem-solving-with-c-walls-and-mirrors-6-e-carrano-henry/ Data Abstraction & Problem Solving with C++: Walls and Mirrors 6th Edition by Carrano, Henry Solutions Manual Completed download: https://solutionsmanualbank.com/download/data-abstraction-problemsolving-with-c-walls-and-mirrors-6th-edition-by-carrano-henry-solutionsmanual/ Chapter 2 Recursion: The Mirrors Multiple Choice Questions 1. In a recursive solution, the terminates the recursive processing. a) local environment b) pivot item c) base case d) recurrence relation 2. A binary search uses a strategy. a) divide-and-conquer b) sequential c) determine-the-pivot d) smallest-to-largest 3. A is a mathematical formula that generates the terms in a sequence from previous terms. a) local environment b) pivot item c) base case d) recurrence relation Answer: d. 4. The factorial of n is equal to. a) n 1 b) n factorial (n 1) c) factorial (n 1) Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 1

d) n * factorial (n 1) Answer: d. 5. The base case for a recursive definition of the factorial of n is. a) factorial ( 1) b) factorial (0) c) factorial (n) d) factorial (n 1) 6. What is fundamentally wrong with computing the Fibonacci sequence recursively? a) it has two base cases b) each call to the function results in two recursive calls c) it computes the same values over and over d) nothing 7. In the box trace, each box roughly corresponds to a(n). a) recursive relation b) activation record c) base case d) pivot item 8. In the box trace, each box contains all of the following EXCEPT. a) the values the function s arguments b) the function s local variables c) the function s execution time d) a placeholder for the value returned by each recursive call from the current box e) the value returned by the function itself 9. In the box trace for a recursive function, a new box is created each time. a) the function is called b) the function returns a value c) an object is created d) an object is initialized 10. What happens if a recursive function never reaches a base case? a) the function returns the correct value b) the function returns an incorrect value c) the function terminates immediately Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 2

d) an infinite sequence of recursive calls occurs Answer: d. 11. In a recursive method that writes a string of characters in reverse order, the base case is. a) a string with a length of 0 b) a string whose length is a negative number c) a string with a length of 3 d) a string that is a palindrome 12. Which of the following is a precondition for a method that accepts a number n and computes the n th Fibonacci number? a) n is a negative integer b) n is a positive integer c) n is greater than 1 d) n is an even integer 13. How many bases cases does a recursive binary search of a sorted array have? a) 0 b) 1 c) 2 d) 3 14. The number of ways to choose k out of n things is. a) the number of ways to choose k 1 out of n 1 things b) the number of ways to choose k out of n 1 things c) the sum of the number of ways to choose k 1 out of n 1 things and the number of ways to choose k out of n 1 things d) the product of the number of ways to choose k 1 out of n 1 things and the number of ways to choose k out of n 1 things 15. When you solve a problem by solving two or more smaller problems, each of the smaller problems must be the base case than the original problem. a) closer to b) farther to c) either closer to or the same distance from d) either farther to or the same distance from Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 3

16. A recursive method that computes the number of groups of k out of n things has the precondition that. a) n is a positive number and k is a nonnegative number b) n is a nonnegative number and k is a positive number c) n and k are nonnegative numbers d) n and k are positive numbers 17. The midpoint of a sorted array has the index, where first is the index of the first item in the array, and last is the index of the last item in the array. a) first / 2 + last / 2 b) first / 2 last / 2 c) (first + last) / 2 d) (first last) / 2 18. If the value sought by a recursive binary search algorithm is in the array, which of the following is true? a) the algorithm makes the same comparisons as a sequential search b) the algorithm is successful without reaching a base case c) the algorithm searches the entire array d) the algorithm searches only the array half containing the value Answer: d. 19. Which of the following is NOT a precondition for an array that is to be searched by a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and SIZE is size of the array) a) SIZE <= first b) 0 <= first c) last <= SIZE 1 d) anarray[first] <= anarray[first + 1] <= <= anarray[last] 20. What does the following recursive algorithm display? writeback(in s:string) if (s is empty) return else { Write the first character of s writeback(the string beginning at the second character of s) } a) nothing b) the first character of s a number of times equal to the length of s Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 4

c) the string s d) the string s backward 21. For an array containing 2, 3, 5, 6, 9, 13, 16, and 19, what value does a recursive binary search algorithm return when it searches for 6? a) 1 b) 3 c) 4 d) none of the above 22. For an array containing 2, 3, 5, 6, 9, 13, 16, and 19, what value does a recursive binary search algorithm return when it searches for 10? a) 1 b) 0 c) 1 d) 10 23. In a sorted array having SIZE locations, the k th smallest item is given by. a) anarray[k-1] b) anarray[k] c) anarray[size-k] d) anarray[size+k] 24. A recursive binary search algorithm always reduces the problem size by at each recursive call. a) 1 b) 2 c) half d) one-third 25. A recursive solution that finds the factorial of n always reduces the problem size by at each recursive call. a) 1 b) 2 c) half d) one-third Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 5

26. In the recursive solution to finding the k th smallest item in an array, the problem size decreases by at each recursive call. a) 1 b) at least 1 c) half d) at least half 27. In the recursive solution to the Towers of Hanoi problem, the number of disks to move at each recursive call. a) decreases by 1 b) increases by 1 c) decreases by half d) increases by half 28. A recursive solution that finds the factorial of n generates recursive calls. a) n - 1 b) n c) n + 1 d) n * 2 29. In the Fibonacci sequence, which of the following integers comes after the sequence 1, 1, 2, 3? a) 3 b) 4 c) 5 d) 6 30. Which of the following is a base case for a recursive binary search algorithm? (first is the index of the first item in the array, last is the index of the last item in the array, and mid is the midpoint of the array). a) last > first b) first > last c) 0 <= first d) last <= SIZE-1 Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 6

True/False Questions 1. A recursive solution solves a problem by solving a smaller instance of the same problem. 2. An iterative solution involves loops. 3. A binary search starts at the beginning of the collection of items. Answer: False. 4. An iterative method always calls itself. Answer: False. 5. In practice, recursion should be used even when a problem has a simple iterative solution. Answer: False. 6. When constructing a recursive solution, you should assume that a recursive call s postcondition is true if its precondition is true. 7. Every recursive method must have a base case. 8. A recursive solution can have more than one base case. 9. The binary search algorithm can be applied to an unsorted array. Answer: False. 10. The base case for a recursive solution to finding the k th smallest item in an array cannot be predicted in advance. Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 7

Short Answer Questions 1. What items does a sequential search examine when it is successful? Answer: A sequential search starts at the beginning of the collection and looks at every item in the collection in order until the desired item is found. 2. What is a base case? Answer: A base case is a special case of a recursive function whose solution you know. A base case enables the recursive processing to terminate. 3. What are the four questions that must be considered when constructing a recursive solution? Answer: The four questions that must be considered when constructing a recursive solution are: How can you define the problem in terms of a smaller problem of the same type? How does each recursive call diminish the size of the problem? What instance of the problem can serve as the base case? As the problem size diminishes, will you reach this base case? 4. What is a recurrence relation? Answer: A recurrence relation is a mathematical formula that generates the terms in a sequence from previous terms. 5. What is the box trace? Answer: The box trace is a systematic way to trace the actions of a recursive method. 6. What is an activation record? Answer: An activation record is a record that contains a method s local environment at the time of and as a result of the call to the method. 7. What elements are included in a method s local environment? Answer: The local environment of a method includes the method s local variables, a copy of the actual value arguments, a return address in the calling routine, and the value of the method itself. 8. What are the two base cases for a recursive binary search algorithm? Answer: The two base cases are: first > last value == anarray[mid] where first is the index of the first item in the array anarray, last is the index of the last item in anarray, and mid is the midpoint of anarray. 9. When is the base case first > last (where first is the index of the first item in the array and last is the index of the last item in the array) reached in a recursive binary search algorithm? Answer: This base case is reached when the value sought is not in the original array. 10. When is the base case value == anarray[mid] (where mid is the midpoint of the array) reached in a recursive binary search algorithm? Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 8

Answer: This base case is reached when the value sought is in the original array. 11. What is a pivot item? Answer: A pivot item is an element of a data collection that an algorithm uses to arrange the rest of the collection. 12. What is the base case for the recursive solution to the Towers of Hanoi problem? Answer: The base case for the recursive solution to the Towers of Hanoi problem is a tower containing only one disk. 13. What are the two factors that contribute to the inefficiency of some recursive solutions? Answer: The two factors are the overhead associated with method calls, and the inherent inefficiency of some recursive algorithms. 14. What is a tail-recursive function? Answer: A tail-recursive function is a function whose last action is a recursive call. 15. Why do some compilers automatically replace tail recursion with iteration? Answer: Some compilers automatically replace tail recursion with iteration because tail-recursive methods are often less efficient than their iterative counterparts, and the conversion of a tailrecursive method to an equivalent iterative method is rather mechanical. More download links: data abstraction and problem solving with c++ test bank pdf data abstraction and problem solving with c++ solution manual pdf data abstraction & problem solving with c++: walls and mirrors (6th edition) pdf data abstraction and problem solving with c++ pdf 6th data abstraction and problem solving with c++ answers Data Abstraction & Problem Solving with C++: Walls and Mirrors, Sixth Edition, by Frank Carrano and D.J. Henry Test Bank 9