Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Notes/Exercise/Questions/Exercise-01.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ function isLeapYear(year){
return (year % 100 === 0) ? (year % 400 === 0) : (year % 4 === 0);
}

````
````

The time complexity for `isLeapYear` is: `O(1)`. Regardless of the input the algorithm will still go through the same number of operations during operation.
4 changes: 3 additions & 1 deletion Notes/Exercise/Questions/Exercise-02.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ const sumOfArray = (array) => {
return sum;
}

```
```

The time complexity for `sumOfArray` is: `O(n)`. The number of operations that will be used in the for loop will increase as the input increases.
9 changes: 8 additions & 1 deletion Notes/Exercise/Questions/Exercise-04.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
**Write a function that accepts an array of strings and return a new array that only contains the strings that start with the character 'd'. Use Big O Notation to describe the time complexity of the function.**
**Write a function that accepts an array of strings and return a new array that only contains the strings that start with the character 'd'. Use Big O Notation to describe the time complexity of the function.**

```js
const returnString = (arr) => {
return arr.filter(string => string.toLowerCase().startsWith('d'));
}
```
The above function will have a time complexity of `O(n)`. This is because the filteration operations will increase as the input increases.
4 changes: 3 additions & 1 deletion Notes/Exercise/Questions/Exercise-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ const median (array) => {
return array[middle];
}

```
```

The time complexity for `median` is: `O(1)`. Regardless of the length of the input array accessing the middle elements will take constant time.