1
00:00:01,470 --> 00:00:02,070
Welcome back.

2
00:00:02,640 --> 00:00:06,870
We just learned our first notation of an.

3
00:00:08,110 --> 00:00:13,360
Or linear time, and we see here that we have a few others remaining.

4
00:00:14,200 --> 00:00:15,950
So let's talk about the next one.

5
00:00:16,600 --> 00:00:22,960
Another very common big notation that you're going to see what happens if we have a function like this.

6
00:00:24,580 --> 00:00:30,730
A function that says compressed 1st box that receives an array of boxes.

7
00:00:32,130 --> 00:00:43,860
And this function simply has console dialog boxes zero, so that is its logging out just the first item

8
00:00:43,860 --> 00:00:44,560
in the box.

9
00:00:45,480 --> 00:00:49,020
What would you say the big O of this function is?

10
00:00:50,350 --> 00:00:59,530
How many steps or operations does this function take if the boxes increase from zero to maybe 10 to

11
00:00:59,530 --> 00:01:01,660
maybe one hundred to one hundred thousand?

12
00:01:03,050 --> 00:01:05,590
What would happen here, ready for the answer?

13
00:01:06,580 --> 00:01:07,570
Well, this.

14
00:01:09,160 --> 00:01:13,720
Is what we call constant time, it's an O of one.

15
00:01:14,760 --> 00:01:21,120
That is, no matter how many times the boxes increase year or however many boxes we have, we're always

16
00:01:21,120 --> 00:01:24,260
just grabbing the first item in the array.

17
00:01:25,380 --> 00:01:33,120
If we look at this with an example, if we had an array of boxes here and we run it through the function,

18
00:01:33,120 --> 00:01:36,630
that just takes the first item in the array.

19
00:01:37,680 --> 00:01:43,390
Well, the number of operations is one, no matter how big this the number of boxes are.

20
00:01:43,440 --> 00:01:45,360
We're only doing one thing.

21
00:01:46,420 --> 00:01:48,310
So it's a constant time.

22
00:01:49,850 --> 00:01:52,940
If we look at this on a graph, if we have.

23
00:01:55,840 --> 00:02:03,040
Element or one box, we do one operation, if we have three again, we still do just one because we're

24
00:02:03,040 --> 00:02:04,900
just grabbing the first item in the array.

25
00:02:05,260 --> 00:02:07,850
If we have, let's say, five.

26
00:02:08,180 --> 00:02:08,860
Same thing.

27
00:02:09,520 --> 00:02:11,010
Seven, same thing.

28
00:02:11,470 --> 00:02:13,180
And what about nine?

29
00:02:13,360 --> 00:02:15,880
Again, same number of operation.

30
00:02:16,390 --> 00:02:20,500
And this is I don't know if you can see the line, but this is just constant time.

31
00:02:20,920 --> 00:02:26,740
It's not linear time like it was where it increases and increases with the number of operations, the

32
00:02:26,740 --> 00:02:29,620
number of operations just stays flat.

33
00:02:32,780 --> 00:02:34,320
But I have a question here.

34
00:02:34,370 --> 00:02:36,140
What if we do something different?

35
00:02:36,260 --> 00:02:37,730
What if we do something like this?

36
00:02:39,370 --> 00:02:42,160
What if we have a function that says function?

37
00:02:45,440 --> 00:02:47,720
Or log first.

38
00:02:51,080 --> 00:02:52,250
Two boxes.

39
00:02:53,300 --> 00:02:59,930
And this takes an array of boxes and is going to console the log.

40
00:03:01,300 --> 00:03:02,650
The first.

41
00:03:03,780 --> 00:03:04,710
Item in the array.

42
00:03:06,010 --> 00:03:11,890
And it's going to console dialogue, also the second item in the array.

43
00:03:15,290 --> 00:03:17,570
How do we measure the bigo of this function?

44
00:03:18,790 --> 00:03:25,810
Well, let me just comment this out for a second, because we don't need this right now and just create

45
00:03:25,810 --> 00:03:36,040
an array called boxes and this boxes has to say zero one, two, three, four and five.

46
00:03:36,050 --> 00:03:39,610
So five items or six in this case because we include zero.

47
00:03:41,720 --> 00:03:43,340
And if we run this function.

48
00:03:45,150 --> 00:03:48,870
Log first, two boxes and we give it the boxes of Ray.

49
00:03:49,920 --> 00:03:57,690
And we click run here, we have zero and one, so we've logged this one and then this one.

50
00:03:58,630 --> 00:04:00,280
What's the number of operations here?

51
00:04:01,430 --> 00:04:02,900
Well, we have.

52
00:04:04,770 --> 00:04:10,830
Oh, of one that is one operation here and then we have over here.

53
00:04:11,980 --> 00:04:14,110
Oh, of one again.

54
00:04:15,500 --> 00:04:19,250
Each time this function runs to operations.

55
00:04:20,860 --> 00:04:32,860
So this function in total is actually running O of two operations every time, so no matter how big

56
00:04:32,860 --> 00:04:40,120
the boxes get, the number of operations here is going to be, too, if we look at this on a graph.

57
00:04:41,460 --> 00:04:50,100
Instead of having all of one like we have before, we have O of two, and then if we had three operations,

58
00:04:50,100 --> 00:04:51,740
I'll just be out of three.

59
00:04:52,260 --> 00:04:55,410
But overall, it's still a flat line.

60
00:04:56,430 --> 00:04:58,800
And this is something we're going to get into later on.

61
00:04:59,590 --> 00:05:08,620
But when it comes to cost and time, we don't care about the nitty gritty of one or two or three of

62
00:05:08,620 --> 00:05:14,200
even a hundred, we round this down to just simply saying, oh, of one.

63
00:05:16,150 --> 00:05:23,440
That is, we have constant time, it's a flat line in terms of scalability, it doesn't matter how big

64
00:05:23,440 --> 00:05:28,540
our inputs are, we're always going to do the constant amount of time on a function.

65
00:05:30,790 --> 00:05:37,680
And if we look at this on a graph, we see that of one over here is the dark green area.

66
00:05:37,690 --> 00:05:38,940
It's excellent.

67
00:05:38,980 --> 00:05:42,250
We love of one because it's very scalable, right.

68
00:05:42,430 --> 00:05:45,670
It doesn't matter how many elements we have, it's always going to run.

69
00:05:45,670 --> 00:05:50,200
The same predictability when it comes to computing is very, very nice.

70
00:05:50,320 --> 00:05:54,190
And all of one is definitely excellent.

71
00:05:55,590 --> 00:06:03,420
OK, so we've learned about linear time, oh, of N and then Konstantine O of one.

72
00:06:04,920 --> 00:06:08,760
Let's do a bit of a fun exercise to really solidify our knowledge here.
