- Coding Videos/
- JavaScript /
- Big O Notation with Javascript Example

# Big O Notation with Javascript Example

### Download Video link >

Big O Notation with Javascript Example

A little bit about Big O Notation

source

### View Comments source >

### Transcript view all >

00:00 in this video I would like to talk about

00:02 the Big O notation so what is the Big O

00:06 notation the Big O notation is an

00:08 algorithm to calculate how long your

00:10 code takes to run or on or match your

00:13 codes efficients so what is the why the

00:18 Big O notation is important for our AIP

00:24 assignment 3 this kind of algorithm is

00:26 not important at all or it will not make

00:30 any difference but if you're going to

00:32 walk at a big companies like Google

00:35 Facebook and amazin you need to know

00:39 this basic Big O notation algorithm

00:42 because you will receive a lot of

00:44 millions of records and you have to

00:48 provide your function so it is really

00:50 matter how you solve your problems so

00:54 before I jump to the examples of Big O

00:58 notation I would like to talk about how

01:01 to think in Big O and pickle notation

01:06 expressions so in order to think in

01:10 pickle you have to do two steps you have

01:14 to always think about the worst case

01:16 scenario in pickle and another thing is

01:20 you can always ignore constants I'll

01:23 explain what these means in later in my

01:27 examples the pickle addition expressions

01:30 will be constants equations of when

01:34 linear equations or n quadratic

01:36 equations of n Square and all log n so

01:42 go to my example now I have a GES been

01:48 in the GSP I have functions two

01:53 functions which exactly just the same

01:56 thing adding the numbers and I time mine

02:00 code before and after ran in the

02:03 functions so that I can take like how

02:06 does it take to run that functions so

02:12 now let me provide the number of tenth

02:16 to both functions the number with Lou

02:19 and the number with the functions

02:22 without Luke so if I run this now I go

02:28 55 for both functions and the time

02:33 without Luke takes your point zero zero

02:36 two seconds but the time with functions

02:41 with Lu takes you point zero three

02:43 seconds so there is no much difference

02:47 with only ten numbers but what about if

02:51 we have like a hundred thousand ten

02:56 thousand hundred thousand so now if you

03:03 render we got the same results but the

03:06 time without Lu takes you seconds

03:11 because this is because it is very small

03:15 number so the light javascript cannot

03:18 describe in details so it just say zero

03:21 seconds but the function with Lu takes

03:26 you once you force against which is a

03:29 lot difference in timing imagine if you

03:34 have millions of records this will be a

03:37 lot a lot of gaps so in here this

03:44 function takes a lot more time because

03:46 the dysfunctions is heavily relies on

03:50 the data if you put 10 numbers it will

03:56 rent it will loop ten times and the

04:00 operations will be 11 but for this one

04:03 whatever the number you put it just only

04:06 do the one operation and it just

04:08 console.log the total result so that is

04:14 why this famish method becomes of n but

04:20 this is the constant one it doesn't rely

04:23 on the

04:24 input you provide so that is why this

04:27 functions become all of one so what

04:34 about in JavaScript objects an array so

04:39 JavaScript object operations are yeah

04:42 much faster because there is no order

04:44 and sorting in JavaScript objects so

04:49 generally a JavaScript object origins as

04:52 instruction SS removal and strategy but

04:55 it's a Genesis and removal are orphaned

04:58 constants or explain later for searching

05:03 this becomes Roth and so with an example

05:09 now I have a person object which has

05:12 three T's and three values so if you are

05:16 going to do object or keys of person

05:18 this method will loop your object and

05:23 get all the keys from the person object

05:26 that is why this has becomes off n for

05:31 the entries it is the same thing you

05:33 have to loop this object and you will

05:36 receive the keys and value pairs as an

05:39 array so in this case you are going to

05:41 get three values the first everywhere be

05:45 name and my name ID and my ID and H and

05:48 my age but for the has own property this

05:53 is all one because you are going to

05:56 assess the name of this person object so

06:01 which means this is the same as a person

06:04 dot name if there is a value you are you

06:07 ever see true if there is not you are

06:09 your C false that is why this has become

06:13 0 of 1 so let me turn back to the worst

06:18 case scenarios and ignore constants so

06:22 in J's bin I will write a few formulas

06:26 of the pickle if you have like o of n

06:29 square plus n plus 5 you need to think

06:35 about the worst case scenario the worst

06:37 case scenario

06:38 the O n square that is why you can

06:43 generalize this equation as o n square

06:46 so in this case you can ignore constant

06:51 this constants like 5 what are the other

06:55 thing will be pool and class 5 then you

07:00 you can say that this equation is an O

07:03 and or maybe both 3 and 32 n equal oh

07:08 end you can ignore the constants

07:11 completely so that is pretty much about

07:16 my video but before I conclude I would

07:20 like to provide a few references if you

07:25 want to know more about javascript

07:26 javascript object boards you you can go

07:29 and check this link but you need to know

07:31 hash maps in which is a kind of a data

07:35 structure and this block quote is for

07:39 overview of the Big O notation yeah

07:42 that's it guys I hope you enjoyed it if

07:46 you have more questions I would like to

07:49 discuss with you as well that's it

**Tags:**example, javascript, notation

## Leave a Reply