Your last example is broken. Your loops have 0 iterations. You initialize i to n, but then repeat if i is less than n. That condition is never true since you are beginning i equal to n. Same problem with inner loop and j. There are other problems with it too. You're dividing i and j by 2 without actually assigning results back to i and j. Your loop conditions are also written assuming i and j increase, but dividing will decrease them. Also, if your intention in inner loop is to half j repeatedly until it reaches 0 then the runtime of that loop is O(log n) but your comment indicates O(n).
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Top comments (1)
Your last example is broken. Your loops have 0 iterations. You initialize i to n, but then repeat if i is less than n. That condition is never true since you are beginning i equal to n. Same problem with inner loop and j. There are other problems with it too. You're dividing i and j by 2 without actually assigning results back to i and j. Your loop conditions are also written assuming i and j increase, but dividing will decrease them. Also, if your intention in inner loop is to half j repeatedly until it reaches 0 then the runtime of that loop is O(log n) but your comment indicates O(n).