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
Question
Chapter 5, Problem 57CRP
Program Plan Intro
Loop invariant:
A loop invariant is a condition that is automatically “true” instantly previous and instantly next each iteration of a loop.
- It states an approach for achieving a goal; it is exactly the “pre-condition” for implementing the loop’s body, and it is exactly the “post-condition” of what is outputted by executing the loop’s body.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
solve with Matlab
Assignment vs. Equals is important in loops. An assignment is a = b and means assign value
b to variable a. The equals operator is ab results in 1 or yes if they are equal, 0 or no if
they are not.
The final type of loop is a WHILE loop. It requires that a series of operations occur while the
condition applied to a specified variable is correct.
The example syntax is:
i=10;
while i>5
i-i-1
end
Practice Problem: Given the matrix: M-[1 1; 1 3;]; Use loops to determine how many
of the entries are greater than 1 and the location of all qualifying entries (the
corresponding row and column).
Design a PDA for L = {a' bi ck /j> = i + k and
ijk > 0}. Process the string aaabbbbbcc using
instantaneous description.
%3D
Determine the loop invariant of the code written then prove that the loop invariant holds on Initialization, Maintainance and Termination.
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
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
- Argue the correctness of the following loop invariant for Do-Math(): result = x-z Be sure to argue both the initial condition and the maintenance condition.arrow_forwardWrite the steps number 1-8 like thisarrow_forwardcourse (discrete structures) Recall question 2 from Tutorial 3 (Pigeon-Hole Principle), where we have a round-robin chess tournament for 150 players, each of whom play 7 games. We showed that since there are 20 possible first moves for White and 20 possible first moves for Black in response, that there must be two different games in the tournament that begin with the same first two moves. For which of the following changes would this result still be true? Question 1 options: a) each player played 6 games instead of 7 b) each player played 8 games instead of 7 c) there were 200 players instead of 150 (and each played 7 games) d) there were 100 players instead of 150 (and each played 7 games)arrow_forward
- Computer Science Engineering:arrow_forwardPython codes for this programarrow_forward1 Question 1 A Deep Neural Network is shown in Figure 1. The aim of this network is to classify human and dog. 1. Calculate the initial error of the Deep Neural Network by feeding the following input: X₁ = 5, X₂ = 2. The X₁ indicates the length of the tail and X₂ indicates the number of eyes. 2. Update the layer 2 weights (ws,we, w7,ws) of the Deep Neural Network shown in Figure 1 for a single iteration. The learning rate is set to a = 1 and there are no biases in the neurons. 3. Recalculate the error with the updated weights of layer 2 and report its improvement with respect to the initial error (percentage wise). 4. (Bonus Question) Update and report the layer 1 weights (w₁,w₂,3,W4) of the network and estimate the improvement to the error. Input X₁=5 W₁-0 w₂ = 0 W₁-0 Layer 1 3₁ ₂0 Layer 2 ys y Predicted Output Real Output 1 0 BE Figure 1: A Deep Neural Network designed for dog or human detectionarrow_forward
- Assume the following scoring matrix. A T C G - A 1 -1 -1 -2 -1 T 1 -1 -1 -1 C 2 -1 -1 G 1 -1 Fill out the dynamic programming table for the global alignment between sequences v = TAGCTCCG and w = GCATCCA using the scoring matrix above. Use the following recursive scoring formula. w= G C A T C C A 0 1 2 3 4 5 6 7 v= 0 T 1 A 2 G 3 C 4 T 5 C 6 C 7 G 8 What is the score and global alignment between v and w?arrow_forward8. X. Let f: RR defined by f(x) = x³ -arrow_forwardplease make sure the answer is correct and the diagram is understandable. please explain how to get the NAND-AND structure from the AND-OR-NOT. Thanks in advance for your helparrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage