Questions tagged [iteration]

40 questions
46
votes
5 answers

Iteration can replace Recursion?

I've been seeing all over stack Overflow, e.g here, here, here, here, here and some others I don't care to mention, that "any program that uses recursion can be converted to a program using only iteration". There was even a highly upvoted thread…
Tobi Alafin
  • 1,647
  • 4
  • 17
  • 22
20
votes
3 answers

Time complexity $O(m+n)$ Vs $O(n)$

Consider this algorithm iterating over $2$ arrays $(A$ and $B)$ size of $ A = n$ size of $ B = m$ Please note that $m \leq n$ The algorithm is as follows for every value in A: // code for every value in B: // code The time complexity of…
7
votes
0 answers

Understanding the Polyhedral Model

I am wondering at a high level the mathematics of the Polyhedral Model. The polyhedral model (also called the polytope method) is a mathematical framework for programs that perform large numbers of operations -- too large to be explicitly…
Lance Pollard
  • 2,323
  • 1
  • 19
  • 34
5
votes
1 answer

Finding the largest linear combination that is not possible

Regarding the problem: What is the largest bet that cannot be made with chips worth $\$7.00 $ and $\$9.00$? Verify that your answer is correct with both forms of induction. I need to find an algorithmic approach, but till now my approach is to try…
jiten
  • 199
  • 6
4
votes
1 answer

Prove correctness of the iterative algorithm

Description: Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra…
3
votes
0 answers

What is the name of visiting an array starting at first element, then last element, then second, then last but one, then third, etc

For example if I have an array [0, 1, 2, 3, 4, ..., n] and I want to iterate over it in an order like [0, n, 1, n - 1, 2, n - 2, ..., n // 2] how it can be called? Is there a general name for this?
Azat Ibrakov
  • 161
  • 9
2
votes
1 answer

Generating all words of length $n$ avoiding $A^2$ and $B^3$

I need to find a way to iterate over all sequences of words in two letters $A,B$ avoiding the sequence $A^2 = AA$ and $B^3 = BBB$. First of all, what is the regular expression for such a thing? I need a way of iterating over all such possible…
john mangual
  • 1,951
  • 1
  • 21
  • 27
2
votes
1 answer

Calculating $\sum_{i=1}^a \lfloor a/i \rfloor i^2$

I have a sum: $$S = \sum_{i=1}^n{\lfloor a/i \rfloor i^2},$$ where $a$ is a constant. Is there a way to speed this up? That is, can we avoid iterating overl all $i$s, possibly calculating it in logarithmic or better time, something manageable when…
2
votes
0 answers

Basic Determine exact amount of iterations

How exactly do you track the exact amount of iterations? I know its probably basic but can't figure out how so was hoping someone could explain to a complete beginner how you arrive at an answer. def f(n): i = 4 while i < n: print(i) i = i +…
yige
  • 21
  • 1
2
votes
0 answers

SCoP, Iteration Domain in Polyhedral Optimization and use of Presburger arithmetic

Context: While exploring the fundamentals of polyhedral optimization and attempting to explore a connection from the input Static Control Part (SCoP) to the iteration domain from birds eye view, I am confused about whether I am making the correct…
F.C. Akhi
  • 123
  • 1
  • 7
2
votes
1 answer

Iterate over a range randomly without any duplicate or storing the full range in memory

I'm trying to create (or find) an algorithm to iterate over a range (e.g.: 1-100, etc) but randomly, without any duplicate values (similar result to random sort, etc) but without actually storing the full range in memory (such as using list(range(1,…
2
votes
1 answer

Iteration Vs Induction Method

I am working on different methods to solve Recurrence Relations. I am using Iteration method and substitution method, which involves Induction, but I feel that sometimes Induction method creates a bit confusion, so I want to know that which of these…
2
votes
2 answers

How to iterate the Hardy-Ramanujan integers quickly

The Hardy-Ramanujan integers, A025487 - OEIS, are integers which when factorized, have their exponents for all the primes starting from 2, in decreasing (not strictly) order. The first few terms are: $$ \begin{array}{lll} 1 & = & 1\\ 2^1 & = &…
simonzack
  • 313
  • 3
  • 12
2
votes
2 answers

Is there a formal definition for iteration?

I wanted know if there is a formal definition of iteration. In the sense that, this definition will say that after the 4th iteration is termination or the 5th iteration and not the 2nd iteration. Basically a rigorous definition of iteration.
rert588
  • 261
  • 2
  • 7
1
vote
0 answers

Nested Function stuck on iteration update

I want to solve the Sparse Extended Information Filter Slam described by Dr. Sebestian Thrun in Probabilistic Robotics.I stuck in some nested function. The algorithm is described in page 309 in this book at Table 12.1 Algorithm is like…
Encipher
  • 165
  • 9
1
2 3