Computer Science: An Overview (12th Edition)
12th Edition
ISBN: 9780133760064
Author: Glenn Brookshear, Dennis Brylow
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 5, Problem 56CRP
- a. Identity the preconditions for the sequential search as represented in Figure 5.6. Establish a loop invariant for the while structure in that program that, when combined with the termination condition, implies that upon termination of the loop, the
algorithm will report success or failure correctly. - b. Give an argument showing that the while loop in Figure 5.6 does in fact terminate.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(a) The Fibonacci sequence can also be seen in hurricanes prediction. The shape takes in the
form of a spiral, it can be in a nesting process and repeated into infinity. It is called the
logarithmic spiral, and it abounds in nature. The Fibonacci sequence of numbers, “Fn”, is
defined using the recursive relation. Fibonacci sequence of numbers can be computed as
follows:
Fn = Fn-1+Fn-2
If the 12th and 13th terms in the hurricane prediction sequence are 89 km/hour and 144
km/hour, analyze the value of the 15th, 16th, and 17th hurricane speed by using the Fibonacci
formula as stated above.
Choose the correc answer in the question below.
a. Correctness of dynamic programming algorithm:
Usually, a dynamic programming algorithm can be seen as a recursion and proof by induction is one of the easiest way to show its correctness. The structure of a proof by strong induction for one variable, say n, contains three parts. First, we define the Proposition P(n) that we want to prove for the variable n. Next, we show that the proposition holds for Base case(s), such as n = 0, 1, . . . etc. Finally, in the Inductive step, we assume that P(n) holds for any value of n strictly smaller than n' , then we prove that P(n') also holds.
Use the proof by strong induction properly to show that the algorithm of the Knapsack problem above is correct.
b. Bounded Knapsack Problem:
Let us consider a similar problem, in which each item i has ci > 0 copies (ci is an integer). Thus, xi is no longer a binary value, but a non-negative integer at most equal to ci , 0 ≤ xi ≤ ci . Modify the dynamic programming algorithm seen at class for this…
Chapter 5 Solutions
Computer Science: An Overview (12th Edition)
Ch. 5.1 - Prob. 1QECh. 5.1 - Prob. 2QECh. 5.1 - Prob. 3QECh. 5.1 - Suppose the insertion sort as presented in Figure...Ch. 5.2 - A primitive in one context might turn out to be a...Ch. 5.2 - Prob. 2QECh. 5.2 - The Euclidean algorithm finds the greatest common...Ch. 5.2 - Describe a collection of primitives that are used...Ch. 5.3 - Prob. 2QECh. 5.3 - Prob. 3QE
Ch. 5.3 - Prob. 4QECh. 5.4 - Modify the sequential search function in Figure...Ch. 5.4 - Prob. 2QECh. 5.4 - Some of the popular programming languages today...Ch. 5.4 - Suppose the insertion sort as presented in Figure...Ch. 5.4 - Prob. 5QECh. 5.4 - Prob. 6QECh. 5.4 - Prob. 7QECh. 5.5 - What names are interrogated by the binary search...Ch. 5.5 - Prob. 2QECh. 5.5 - What sequence of numbers would be printed by the...Ch. 5.5 - What is the termination condition in the recursive...Ch. 5.6 - Prob. 1QECh. 5.6 - Give an example of an algorithm in each of the...Ch. 5.6 - List the classes (n2), (log2n), (n), and (n3) in...Ch. 5.6 - Prob. 4QECh. 5.6 - Prob. 5QECh. 5.6 - Prob. 6QECh. 5.6 - Prob. 7QECh. 5.6 - Suppose that both a program and the hardware that...Ch. 5 - Prob. 1CRPCh. 5 - Prob. 2CRPCh. 5 - Prob. 3CRPCh. 5 - Select a subject with which you are familiar and...Ch. 5 - Does the following program represent an algorithm...Ch. 5 - Prob. 6CRPCh. 5 - Prob. 7CRPCh. 5 - Prob. 8CRPCh. 5 - What must be done to translate a posttest loop...Ch. 5 - Design an algorithm that when given an arrangement...Ch. 5 - Prob. 11CRPCh. 5 - Design an algorithm for determining the day of the...Ch. 5 - What is the difference between a formal...Ch. 5 - Prob. 14CRPCh. 5 - Prob. 15CRPCh. 5 - The following is a multiplication problem in...Ch. 5 - Prob. 17CRPCh. 5 - Four prospectors with only one lantern must walk...Ch. 5 - Starting with a large wine glass and a small wine...Ch. 5 - Two bees, named Romeo and Juliet, live in...Ch. 5 - What letters are interrogated by the binary search...Ch. 5 - The following algorithm is designed to print the...Ch. 5 - What sequence of numbers is printed by the...Ch. 5 - Prob. 24CRPCh. 5 - What letters are interrogated by the binary search...Ch. 5 - Prob. 26CRPCh. 5 - Identity the termination condition in each of the...Ch. 5 - Identity the body of the following loop structure...Ch. 5 - Prob. 29CRPCh. 5 - Design a recursive version of the Euclidean...Ch. 5 - Prob. 31CRPCh. 5 - Identify the important constituents of the control...Ch. 5 - Identify the termination condition in the...Ch. 5 - Call the function MysteryPrint (defined below)...Ch. 5 - Prob. 35CRPCh. 5 - Prob. 36CRPCh. 5 - Prob. 37CRPCh. 5 - The factorial of 0 is defined to be 1. The...Ch. 5 - a. Suppose you must sort a list of five names, and...Ch. 5 - The puzzle called the Towers of Hanoi consists of...Ch. 5 - Prob. 41CRPCh. 5 - Develop two algorithms, one based on a loop...Ch. 5 - Design an algorithm to find the square root of a...Ch. 5 - Prob. 44CRPCh. 5 - Prob. 45CRPCh. 5 - Design an algorithm that, given a list of five or...Ch. 5 - Prob. 47CRPCh. 5 - Prob. 48CRPCh. 5 - Prob. 49CRPCh. 5 - Prob. 50CRPCh. 5 - Prob. 51CRPCh. 5 - Does the loop in the following routine terminate?...Ch. 5 - Prob. 53CRPCh. 5 - Prob. 54CRPCh. 5 - The following program segment is designed to find...Ch. 5 - a. Identity the preconditions for the sequential...Ch. 5 - Prob. 57CRPCh. 5 - Prob. 1SICh. 5 - Prob. 2SICh. 5 - Prob. 3SICh. 5 - Prob. 4SICh. 5 - Prob. 5SICh. 5 - Is it ethical to design an algorithm for...Ch. 5 - Prob. 7SICh. 5 - Prob. 8SI
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the following two relations for Millennium College: STUDENT(StudentID, StudentName, CampusAddress, GPA...
Modern Database Management
Suppose the class F is defined in (a). Let f be an instance of F. Which of the statements in (b) are correct?
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
What error message do you see in the Code Pad if you type the following?
The error message is not actually v...
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Write a program that acts as a simple printing calculator. The program should allow the user to type in express...
Programming in C
Suppose that nl is of type int and n2 is of type long. What is the type of the value returned by Math.min (n1, ...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Write an SQL statement to display the breed, type, and DOB of all pets having the type Dog.
Database Concepts (7th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- F. Task(s) Divide and Conquer Algorithm - Mergesort Assume that you have recently joined SortPro Inc. as an intem. SortPro engages in software solutions for clients in the food and beverage industry and in the hospitality industry. As an intern, your Team Lead assigns you the task of developing a sorting algorithm for a client in the food and beverage industry. The client takes food orders and wishes to have the option of sorting his food orders by the order id. To check the soundness of your solution, your Team Lead asks you to write a program that will sort the food orders using Mergesort and to report the efficiency of the algorithm. Your Team Lead has set the following requirements: • Auto-generate the order ids randomly. You may use a random function to generate the order ids. The order id takes the form of FD9999 (the number of digits might change according to the maximum number of orders, n, that is input by the user). • For each order id, the total cost of the order should also…arrow_forwardExercise 1.A set W of strings of symbols is defined recursively by a, b, and d belong to W. If x belongs to W, so does a(x)d. Provide 3 strings made of 3 letters each belonging to W and show the procedure used to obtain them. Provide 3 strings made of at least 5 letters each belonging to W and show the procedure used to obtain them.arrow_forward2. R(N) is the running time of strange_sum when called on a List of length N. Since this is recursive code, your answer to iii should include a diagram of the recursion tree. a. Answer for li being an ArrayList b. Answer for li being a LinkedList static int strange_sum(List li) { return strange_sum_helper(li, 0, li.size() - 1); static int strange_sum_helper (List arr, int left, int right) { if (right - left < 0) return 0; else if (right else { int mid = (left + right) / 2; return strange_sum_helper(arr, left, mid) left 0) return arr.get(left); == + strange_sum_helper(arr, mid + 1, right); } }arrow_forward
- Using a repetition construct, display the following on the screen (warm-up problem). L P P Larrow_forward2. Let E be the alphabet E = {0, 1, 2, 3, 4}. Then using Definition 1 of section 5.3, (a) Give a recursive definition of the set of strings E". (b) Prior to the first iteration of the recursion, list all the elements then in E*. (c) After the first iteration of the recursion, list all the elements then in E*. (d) After the second iteration of the recursion, list all the elements then in E*. Definition 1 The set E* of strings over the alphabet E is defined recursively by BASIS STEP: À e E* (where à is the empty string containing no symbols). RECURSIVE STEP: fw ε amd x Σ, then wx E Σ'.arrow_forwardWhich of the following statements about recursion are TRUE? at least one parameter of a recursive function is equivalent to the loop variable in a while loop recursive functions stop once the base case is reached U any problem that can be solved with a loop can be written recursively as long as the input size is not too large a recursive function calls itself at least oncearrow_forward
- Exercise 1-Printing Characters of Odd ASCII Codes Recursively Exercise Objectives ✓ Calling functions recursively ✓ Comparing the iterative approach vs. the recursive approach Problem Description A cell type might split into two or three every hour, or might die. The likelihood for splitting into two is 30% and into three is 55% and dying is 15% for every lifespan. Assume that we start with a sample of one cell, write a recursive function to calculate and return the total number of cell after a number of hours. The function receives the umber of hours as a parameter. Hint: use rand() function to simulate the percentage. Use this function signature: int cell(int total_hours). The function should stop when the total_hours left is 0 or less. Write the main function that prompts the user to enter the number of hours and pass the number of hours to the recursive function cell. Then print the result returned by the recursive functionarrow_forwardGiven three sequences of length m, n, and p each, you are to design and analyze an algorithm to find the longest common subsequence (LCSS) for the three sequence. Is it possible to use dynamic programming to find the LCSS between the three sequences? If yes, provide recursive solution to the above problem. (Hint: We already designed dynamic programming algorithm for two sequences of length m and n in our class.)arrow_forwardExercise 1-Printing Characters of Odd ASCII Codes Recursively Exercise Objectives Calling functions recursively Comparing the iterative approach vs. the recursive approach Problem Description A cell type might split into two or three every hour, or might die. The likelihood for splitting into two is 30% and into three is 55% and dying is 15% for every lifespan. Assume that we start with a sample of one cell, write a recursive function to calculate and return the total number of cell after a number of hours. The function receives the umber of hours as a parameter. Hint: use rand() function to simulate the percentage. Use this function signature: int cell(int total hours). The function should stop when the total hours left is 0 or less. Write the main function that prompts the user to enter the number of hours and pass the number of hours to the recursive function cell. Then print the result returned by the recursive functionarrow_forward
- Nonearrow_forwardalgoritm if possible or codearrow_forwardwrite algorithm or theory of the following problem. Dont write code, Narrative 2: We need to have a generic module which reads in file and gives the output in the format which would facilitate other programs to do comparison like the one we saw above to carry out analysis and comparison. Response Required: Write a program that reads a given text, outputs the text as is, and also prints the number of lines and the number of times each letter appears in the text. An uppercase letter and a lowercase letter are treated as being the same; that is, they are tallied together. Since there are 26 letters, we use an array of 26 components to perform the letter count. We also need a variable to store the line count. The text is stored in a file, which we will call textin.txt. The output will be stored in a file, which we will call textout.txt Input: A file containing the text to be processed. Output: A file containing the text, number of lines, and the number of times a letter appears in the…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Computational Software for Intelligent System Design; Author: Cadence Design Systems;https://www.youtube.com/watch?v=dLXZ6bM--j0;License: Standard Youtube License