#Time Complexity for PseudoCode
1 messages ยท Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
Hey there! In order for code to have constant time complexity, it means that the runtime of the code does not depend on the size of the input.
In pseudo code, if you have a snippet like this:
function constantTimeExample(int[] array) {
return array[0];
}
This function is considered to have constant time complexity because it only performs a single operation (returning the first element of the array) regardless of how large the input array is. The runtime will always be the same because it only ever accesses one element.
So, in your case, if your pseudo code performs a simple operation or access that doesn't change based on input size, then it can be considered to have constant time complexity.
However, it's important to note that in real-world scenarios, achieving true constant time complexity can be rare and often depends on factors such as hardware limitations. It's more common to see algorithms with logarithmic, linear, or quadratic time complexities in practice.
Hope this helps with your exam preparation! Let me know if you have any other questions.
prof says its O(n) but i think it is O(n^2) because its a nested loop. In the while loop, i goes from 0 to n-1, which makes n iterations. Inside the for loop, j goes from 0 to n-1, which makes n iterations as well. $$f(n) = c_1 + c_2 \cdot n \cdot c_3 \cdot n$$
aye no latex bot?
Click the link to see full results.
i typed the latex wrong
look at the inner loop
"i" is incremented in the inner loop
so the inner loop complexity isn't independent from the outer loop
so it's not a multiplication of complexity
no
the highlighted part
ohhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
it's also a bit confusing that you using i<-i+1 at one place and i++ at another
please use one syntax
๐
thank u btw