# #100Devs

"Then when I asked, "Do ya have a man?", she tried to pretend
She said: "No, I don't, I only have a friend""

# Daily Standup

(Mon-Fri 6pm EST)

Class Coming!

# Brute Force

## ITS ALL YOU NEED

"Just had a coffee chat was told they see so many applicants with empty githubs, no portfolio sites and no projects under their belt

We’re on the right track yall, Leon has definitely given us the cheat codes"

@Telescope_Thieves

### There was no technical assessment, I just told them about the projects I had worked on and made sure I was friendly and connected with them as people. I know there's lots of people here that are better coders than me, so it's absolutely possible you can do this! Don't stop believing, stay consistent, and it will happen!

Sean, SOFTWARE FUCKING ENGINEER!

# Was going to cancel the interview, but friend convinced them last minute

Works part time, gets paid full time!

Erica

# When worrying about real data, it is also cost, but in space and time

Less Memory, but Less Efficient

More Memory, but More Efficient

# O(1)

For all inputs to our algorithm there is and will always be only one operation required

• Order 1
• Constant Time

# O(1) Example

No matter how many inputs are located in num there will only ever be one operation needed!

``````const nums = [1,2,3,4,5]
const firstNumber = nums[0]``````

# O(N)

For all inputs to our algorithm there will be one

operation per input

• Order n
• Linear
• Linear Scailing

# O(N) Example

Here we sum the numbers in the array. We have to add each number to a running sum, so we have to operate on each one. This means one operation per input.

``````const nums = [1,2,3,4,5]
let sum = 0
for(let num of nums){
sum += num
}``````

# O(1) VS O(N)

### Summing function for a sorted, contiguous array of integers that starts with the number 1? Could easily be O(n) but...

``````const sumContiguousArray = function(ary){
//get the last item
const lastItem = ary[ary.length - 1]
//Gauss's trick
return lastItem * (lastItem + 1) / 2
}
const nums = [1,2,3,4,5]
const sumOfArray = sumContiguousArray(nums)``````

# Order N Squared

Text

``````const hasDuplicates = function(num){
for(let i = 0; i < nums.length; i++){
const thisNum = nums[i]
for(let j = 0; j < nums.length; j++){
if(j !== i){
const otherNum = nums[j]
if(otherNum === thisNum) return true
}
}
}
return false
}

const nums = [1,2,3,4,5,5]
hasDuplicates(nums) //true``````

# O(N^2)

Here we’re iterating over our array, which we already know is O(n), and another iteration inside it, which is another O(n). For every item in our list, we have to loop our list again to calculate what we need.

By Leon Noel

# #100devs - Intro DS & Algorithms

Class 62 of our Free Web Dev Bootcamp for folx affected by the pandemic. Join live T/Th 6:30pm ET leonnoel.com/twitch and ask questions here: leonnoel.com/discord

• 1,452