Question

What is the loop INVARIANT for this program? The loop variant has to pass the premises:

loop {P) [U] while (b) (Sj1 S fQ)

(0 S len)) i=0; r false; while (i < len) { if (a ] r) { r = true; i = len; else r true)

loop {P) [U] while (b) (Sj1 S fQ)
(0 S len)) i=0; r false; while (i
0 0
Add a comment Improve this question Transcribed image text
Answer #1

In simple word loop variant is some predict or condition that holds the every iteration of the loop.

here, In while loop condition is (i < len)

so, (i < len ) is loop varient

Add a comment
Know the answer?
Add Answer to:
What is the loop INVARIANT for this program? The loop variant has to pass the premises:
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the loop invariant (I) to show that the code below correctly computes the product of...

    Use the loop invariant (I) to show that the code below correctly computes the product of all elements in an array A of n integers for any n ≥ 1. First use induction to show that (I) is indeed a loop invariant, and then draw conclusions for the termination of the while loop. p = a[0] i = 0 while i <= n − 1 do //(I) p = a[0] · a[1] · · · a[i] (Loop Invariant) i +...

  • For this pseudocode present a loop invariant and prove it, n >= 0. i <= 0;...

    For this pseudocode present a loop invariant and prove it, n >= 0. i <= 0; s <=2; while i < n do i <= i + 1 s <= s * s

  • Create a program via Java that has atleast 8 characters long, one upper case, and one...

    Create a program via Java that has atleast 8 characters long, one upper case, and one lower case, and one digit. here is my code:     public static void main(String[] args)     {         //variables defined         String passwords;         char password =0;                 //settings up password condition to false         boolean passwordcondition= false;         boolean size=false;         boolean digit=false;         boolean upper=false;         boolean lower=false;         //inputting a scanner into the system         Scanner keyboard = new Scanner(System.in);...

  • Create a program named Lab14B. You will create a nested loop in this program by putting...

    Create a program named Lab14B. You will create a nested loop in this program by putting Lab14A’s for loop inside a while loop. In the new while loop, you will read integers from the file, Lab14B.txt, and determine if the number is prime (using the copied loop from Lab14A). Stop the while loop when you reach the end of file. Copy your code from Lab14A into your new program Add a while not eof loop around that code, and also...

  • Write a PYTHON program that allows the user to navigate the lines of text in a...

    Write a PYTHON program that allows the user to navigate the lines of text in a file. The program should prompt the user for a filename and input the lines of text into a list. The program then enters a loop in which it prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the...

  • def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or...

    def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...

  • no other details are given, its asking for the invariant programming language: Java Question 3. [15...

    no other details are given, its asking for the invariant programming language: Java Question 3. [15 marks in total Consider the following code fragment with missing statements at ????. Assume that A is a nonempty array of integers and has length N. Assume that it has already been initialised. Refer to this code in parts (a-e) below. A [0] int count 1; int i- 1 while (i< NI1 count> N/2 ) if (xAi]) count++ int x else ???? i+ if...

  • program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int...

    program. 13. What's the output of the following program? #include< iostream> #include&math> using namespace std; int p 7; void main) extern double var int p abs(-90); system( "pause"); double var = 55; 14. How many times does "#" print? forlint i 0;j< 10; +ti) if(i-2141 6) continue; cout<< "#"; 15. Write the function declaration/prototype for a, pow function b floor function 16. State True or False a. b. c. d. e. isupper function returns a double value for loop is...

  • answer. A4 Consider a formal argument which has two premises: “p implies not q”, and “p...

    answer. A4 Consider a formal argument which has two premises: “p implies not q”, and “p or not q”, with the conclusion that “q is false”. a. Is this a valid argument? Give a truth table that verifies your b. Convert the statement “any integer less than C is also less than Cz" into “r implies s” form: i.e. what are the statements r and s? (Remember to substitute your integer values of C and C3.) c. Fix any integer...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT