Computer Science: An Overview (13th Edition) (What's New in Computer Science)
13th Edition
ISBN: 9780134875460
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
Draw flow diagram of while and for loop. Explain a scenarios in which for loop is best suited and a scenario in which while loop is best suited?
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).
PEARHEAEGANEHNA
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
let x = "me";
let y = 3;
let z = myFun (x, y)
alert(z);
z=plusOne(plusOne (y));
alert(x);
function myFun (a,b){
alert (b);
moreFun();
return b* a. length;
}
fucntion moreFun () {
}
alert(y);
function plusOne (c)
return c + 1
Chapter 5 Solutions
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
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_forwardA={w ∈{0, 1}* | w starts with a symbol and ends with the other symbol} The state diagram for an NFA?arrow_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
- x = 1; y = 2; z = 1; n = 5; while (zarrow_forward4 Variable K-maps With casez Complete the Verilog implementation using only a casez statement that provides the implicates generated from the Kmap The sabmission will be mannally reviewed Exercise 2 uhmit successful, time is 1316 30 hos 207.1 Complete a verilog module with the following header: module testi( output logic y. input logic a,b,c,d ): that inplements the following K-map: C,d 00 01 11 10 00 01 11 1. 1 10 Editor module teati (output 1ogic y, inpus logie s,b,c.dlz alwaya comb begin -00010 tt ve EM00020 tat ve 1.5,6, ,10,11,13,141 y-1: defaulti y-0I endcase end E-O0040 Lt ve endnodule 1, 1. 1. 1.arrow_forwardSynchronization Problems: Select all of the following statements that are true. Regarding the bounded buffer version of the producer-consumer problem: If the buffer is full, the consumer must wait until new data is generated. Regarding the unbounded buffer version of the producer-consumer problem: the producer never has to wait and can produce new data elements without having to care for buffer sizes. With respect to the first readers-writers-problem discussed in class: If new reading processes are added again and again, a writing process could starve in the worst case. With respect to the solution to the second readers-writers-problem discussed in class: the queue semaphore provides a queuing of read and write processes. The naïve semaphore-based solution to the Dining-Philosophers problem discussed in class can lead to deadlocks. The semaphore-based solution to the Dining-Philosophers problem discussed in class is limited to at most 5 philosopher processes.arrow_forwardPLEASE HELP!!!! Write these rules in Python #name – a simple name for the rule (e.g., up, left, down, right) #• precondition function – a Boolean function that accepts a state and returns true if the rule is applicable to state #• action function – a function that accepts a state and returns the successor state obtained by applying the rulearrow_forwardLoop invariants Consider the following code, assuming that i, x, y, and n are integers, with n > 0. • State a non-trivial loop invariant for variable x. • Prove the loop invariant. Be sure that the proof includes the final conditions after the loop has ended. Note: a correct proof of an incorrect invariant will still receive partial credit. • Give the final value of a in terms of n. Hint: is the pattern close to (e.g. off by one) from some other pattern you might recognize? Hint: you might need to include a condition for y somewhere within your proof. i = 0; x = 1; while in do y = x + 2; x=x*y; i = 1 + 1; After the loop, x = (the invariant goes here)arrow_forwardA={w ∈{0, 1}* | w does not contain the substring 0011} The state diagram for a DFA?arrow_forwardBus timetables specify to the second the exact arrival and departure time of each bus on each stop. You need to pay for the full fare of every bus you ride and different bus lines charge different fees , but they are flat fees (independent of distance travelled on the line) A travel plan is a sequence of stop-time pairs where stop is a location of a bus stop and time is when we arrive at that stop. The plan is feasible if for any two consecutive pairs (a, t) and (b, t′) in the plan there exists a bus that departs after t and arrives at b at exactly t′. That is, a travel plan does not allow us to walk between stops. Assuming that no two buses arrive at the same time at the same stop, a feasible plan uniquely identifies the bus lines that we need to take to realize the plan. The cost of the plan is the sum of the fares we need to pay. Your task is to design an efficient algorithm that given a departure time t, an arrival time t′, an origin stop a and a destination stop b, finds the…arrow_forward8. X. Let f: RR defined by f(x) = x³ -arrow_forwardShow that the program construction schema of for loop can be constructed in any simple computer. The for loop is the schema ΚΕΝ h: A x B → A f = FOR(k, h): A x B → A where f(x, y) = ax is defined by the sequence do, a₁,..., āk € Em defined by do = x āi+1 = h(ai, y) andarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education