loop-invariant Questions

3

double var = 0.; for(int i = 0; i < 1000000 ; i++) { var += sqrt(2.0); } std::cout << var << std::endl; Under MSVC2012, is it possible that under release with optimization turn on,...
Hintze asked 24/12, 2012 at 19:27

16

Solved

I'm reading "Introduction to Algorithm" by CLRS. In chapter 2, the authors mention "loop invariants". What is a loop invariant?
Bisset asked 11/7, 2010 at 2:7

7

Solved

As seen on Introduction to Algorithms (http://mitpress.mit.edu/algorithms), the exercise states the following: Input: Array A[1..n] and a value v Output: Index i, where A[i] = v or NIL if v does ...
Burra asked 7/4, 2011 at 17:20

1

Solved

Consider the standard strategy to solve the 100 prisoners and a lightbulb problem. Here's my attempt to model it in Dafny: method strategy<T>(P: set<T>, Special: T) returns (count: int...
Ulna asked 26/6, 2017 at 2:33

6

Solved

For example, assuming a string s is this: for(int x = 0; x < s.length(); x++) better than this?: int length = s.length(); for(int x = 0; x < length; x++)
Amplexicaul asked 27/2, 2011 at 19:16

7

Solved

I have do an extensive calculation on a big vector of integers. The vector size is not changed during the calculation. The size of the vector is frequently accessed by the code. What is faster in g...

6

Solved

I have the following looking code in VC++: for (int i = (a - 1) * b; i < a * b && i < someObject->someFunction(); i++) { // ... } As far as I know compilers optimize all these ...
Nonobservance asked 25/2, 2011 at 10:37

5

Solved

When using formal aspects to create some code is there a generic method of determining a loop invariant or will it be completely different depending on the problem?
Shontashoo asked 29/5, 2010 at 13:46

3

Solved

I'm looking at Hoare Logic and I'm having problems understanding the method of finding the loop invariant. Can someone explain the method used to calculate the loop invariant? And what should a l...

10

Solved

In the following code: std::vector<int> var; for (int i = 0; i < var.size(); i++); Is the size() member function called for each loop iteration, or only once?

3

Solved

I have a loop that looks like this: for (int i = 0; i < dim * dim; i++) Is the condition in a for loop re-evaluated on every loop? If so, would it be more efficient to do something like t...
1

© 2022 - 2025 — McMap. All rights reserved.