BigO Notation Lab (Ismail) #2

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@ismailshak

ismailshak commented May 13, 2019

No description provided.

@ismailshak

This comment has been minimized.

ismailshak commented May 13, 2019

comfort 5
completeness 5

@@ -17,6 +17,8 @@ function wordOccurrence(word, phrase) {
}
```

O(n), it goes through the whole array and checks every single element regardless of result.

This comment has been minimized.

@Zakk
@@ -34,6 +36,8 @@ function bubble_sort(list) {
}
```

O(n^2), there is a nested loop that goes through the array and swaps neighboring values to put them in order.

This comment has been minimized.

@Zakk
@@ -46,6 +50,8 @@ function factorial(n) {
}
```

O(n), it goes through the top of a given sequence of numbers and subtracts 1 all the way down to reach 0. Always going to be dependant on n.

This comment has been minimized.

@Zakk
@@ -54,6 +60,9 @@ function bobIsFirst(people) {
}
```

O(1), it only performs one check and returns a result. Regardless of where bob is, it just returns a true or false.

This comment has been minimized.

@Zakk
@@ -70,6 +79,8 @@ function isPalindrome(input) {
}
```

O(n), it still has to go through the input and push into the stack regardless of if its a palindrome or not. It loops through it again to check if its equal. At the worst case it is not a palindrome and loops through the input twice (2n, but no coefficients).

This comment has been minimized.

@Zakk
}
return result;
}
```

O(n), it always goes through all the values from 1 to n.

This comment has been minimized.

@Zakk
@@ -100,6 +114,8 @@ function printAllNumbersThenSumPairs(numArray) {
}
```

O(n), it always loops through the array twice so O(n) + O(n) = O(2n). But the coefficient is dropped.

This comment has been minimized.

@Zakk
@@ -115,3 +131,5 @@ function isPrime(num) {
return true;
}
```

O(n), it should takes the same amount of time to run each time its called. It checks whether the given input is a prime. However, the for loops forces the algorithm to check every value from 2 to n-1. So it would depend on the value of n.

This comment has been minimized.

@Zakk
@Zakk

This comment has been minimized.

Zakk commented May 13, 2019

@ismailshak You got 8 out of 8! Great work!

@Zakk Zakk closed this May 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment