Big-O Exercises (Shane Vann-Shirley) #8

Closed
wants to merge 1 commit into
from
+16 −0

Conversation

Projects
None yet
2 participants

ashanevs commented May 13, 2019

 comfort: 3/5 completeness: 4/5 Not sure if I was meant to be able to complete all of those given some issues in the code, probably will need to discuss further in private
``` semi-completed big-o-exercises ```
``` 75acdfd ```

Zakk reviewed May 13, 2019

 @@ -17,6 +17,8 @@ function wordOccurrence(word, phrase) { } ``` This is a linear complexity algorithm, notated 0(N). It is linear because it the time it takes to complete scales linearly relative to the input size of the inputs you pass in (i.e. the loop has to run more times).

👍

Zakk reviewed May 13, 2019

 @@ -34,6 +36,8 @@ function bubble_sort(list) { } ``` This is a quadratic complexity algorithm, notated 0(N^2). The main indicator of this is the nested loops it contains. Nested loops cause time to scale very rapidly as input size increases and are often considered ineffecient.

👍

Zakk reviewed May 13, 2019

 @@ -46,6 +50,8 @@ function factorial(n) { } ``` This algorithm has constant complexity, notated 0(1). It takes the same amount of time regardless of what input you give it (which can only be a single number).

Zakk May 13, 2019

Close! The function is calling itself (which is something called recursion, and works kind of like a loop).

Zakk reviewed May 13, 2019

 @@ -54,6 +60,8 @@ function bobIsFirst(people) { } ``` This algorithm has constant complexity, notated 0(1). It takes the same amount of time regardless of the input you give it, as it does the same task every time it is called.

👍

Zakk reviewed May 13, 2019

 @@ -70,6 +78,8 @@ function isPalindrome(input) { } ``` This algorithm has linear complexity, notated 0(N). The time it takes to complete increases linearly as the input size increases, which adds more iterations to the for loop inside.

👍

Zakk reviewed May 13, 2019

 @@ -100,6 +112,8 @@ function printAllNumbersThenSumPairs(numArray) { } ``` This algorithm has linear complexity, notated 0(N). It will take longer to complete at a linear rate as the size of the input array increases.

👍