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

Closed
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
2 participants
@ashanevs

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

@@ -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).

This comment has been minimized.

@Zakk
@@ -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.

This comment has been minimized.

@Zakk
@@ -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).

This comment has been minimized.

@Zakk

Zakk May 13, 2019

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

@@ -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.

This comment has been minimized.

@Zakk
@@ -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.

This comment has been minimized.

@Zakk
@@ -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.

This comment has been minimized.

@Zakk

@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