Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How would I write a function that contains a nested for-loop but is only order(n)? Im not sure if i need to use recursion or not.
If the inner for loop is a constant number of loops rather than a variable number of loops, while the outer loop is a variable number of loops (or vice versa) the time complexity is O(n*C) where C is a constant, which just means O(n) (since big O notation is only concerned with growing factors).
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Hello I am starting to learn programming and I would like to know this if someone could help me out.
If we know how many times will loop be done whats the easiest one to use?
You should use as a rule of thumb.
If know iterations --> for
If unknown iterations --> while
If at least one iteration (but not known) --> repeat
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
Which of the following is not equivalent to the other two? Please tell me when it isn't output different from the other two.
while (i<10) {...}
for (;i<10:) {...}
do {...} while (i<10);
I'll appreciate it for your answer.
The last one is different from the first two! If i==15, then the first two are not executed at all, while the do {} block gets executed once.
The do-while loop is unlike the others in that it will execute at least one time because the condition check happens after the loop body. The other two structures first check whether i<10, then execute the loop body if true.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I want to implement the Viterbi algorithm for decoding convolutional codes.
Would it be better to implement it using 2D arrays or using linked lists in C programming language.
I am a newbie in C and would appreciate any help regarding which method would be better with the specific reasons.
It's be better to implement it using 2D array since you have to access random index with a constant time complexity of O(1).
You can't access random index in linked lists with a constant time complexity of O(1).
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Time Complexity of Juggling algorithm for array rotation(Suppose 'd' times) is computed as O(n), where n is the size of the array. But for any number of rotation(i.e. for any value of 'd'), the algorithm runs exactly for n times. So, shouldn't the time complexity of the algorithm be "Theta(n)" ? It always loops for n times in any case.If not, can anyone provide a test case where it doesn't run for n times?
It is unclear what you ask, but if we look at https://www.geeksforgeeks.org/array-rotation/ we see that it is described as O(n) time but if we want to rotate zero steps it could be done in O(1) time, so it doesn't always take n times - i.e. Theta(n) would be wrong; but O(n) is correct.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How would I do this in 1 loop since I need to loop again and close every second door? Do they want me to loop through the program 100 times? Should I be using pointers ?
Yes, you should loop through the program 100 times if you want to simulate this behavior.
But if you want to know the final condition(Open/Close) then you can have better algorithm:
As every perfect square number only have odd number of factor, if number is perfect square then final condition of door is open otherwise door is close.
If you are interested see perfect square number and Why perfect squares only have odd numbers of factor .