Find the Big Theta, Big Omega, Big-O of the following code

I don't know anything about time complexity. I just looked for and still don't understand about it.

Find the Big Theta, Big Omega, Big-O of the following code:

public static int search(int arr[ ],int x) {`
1.int n = arr.length;                           // 1 
2.for(int i = 0; i < n; i++) {                  // {(1+(N+1)+N} = 2N+2
3.    if(arr[i] == x) {                         // N
4.        return i;                             // 1
    }
  }
5.return -1;                                    //1
}

I dunno that iam doing rigth, but my answer 5+3N



Read more here: https://stackoverflow.com/questions/64420048/find-the-big-theta-big-omega-big-o-of-the-following-code

Content Attribution

This content was originally published by Zakhel at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: