1

00:00:01,140  -->  00:00:07,620
Not look at the data structure called it is software it gets lot of its power through data structures

2

00:00:07,620  -->  00:00:14,080
that it uses and the data structure is an organized collection of related data.

3

00:00:14,100  -->  00:00:19,980
For example if you want to print all the CT status that a student has registered for then watch this

4

00:00:19,980  -->  00:00:24,960
course titles in some kind of a data structure before printing them later.

5

00:00:24,970  -->  00:00:28,550
You look at several of these powerful built in data structures.

6

00:00:29,070  -->  00:00:34,290
However there is one very basic data structure that is built into every programming language and it's

7

00:00:34,290  -->  00:00:35,690
an art.

8

00:00:35,780  -->  00:00:41,160
In fact it is so basic that even some of the data structures that we study later are built on top of

9

00:00:41,250  -->  00:00:47,090
arrays pre-knowledge just look at arrays and we will study other data structures later.

10

00:00:48,270  -->  00:00:54,880
And that is basically a container object that holds a fixed number of values of a single type.

11

00:00:54,960  -->  00:00:57,650
Some of the terms in this definition are emphasized in bold.

12

00:00:57,800  -->  00:01:00,100
And let's understand what they mean.

13

00:01:00,300  -->  00:01:05,570
The term object in this definition implies a Java object that is in Java.

14

00:01:05,610  -->  00:01:11,400
An array is basically an object and hence will be stored on the heap like any other object.

15

00:01:11,520  -->  00:01:18,250
Since R is an object the variable referencing it is an object reference next to a fixed number which

16

00:01:18,250  -->  00:01:23,970
means that the number of items they can store is decided at the array creation time itself and cannot

17

00:01:23,970  -->  00:01:30,570
be changed thereafter finally by a single type we mean that the items in an RV should be of a single

18

00:01:30,570  -->  00:01:37,660
data type like N and R double or even some class that is an array can store primitives or object or

19

00:01:37,660  -->  00:01:44,120
Francis but only condition is that they have to be of the same type.

20

00:01:44,140  -->  00:01:48,490
Here is an illustration of an array which contains seven integer values.

21

00:01:48,780  -->  00:01:55,290
Each item in the array is called an element and this axis by its next number an index number is nothing

22

00:01:55,320  -->  00:02:02,620
but the numerical position of the element in the ID and index numbering begins with zero.

23

00:02:03,550  -->  00:02:09,450
Now if this array is named as my array then the fourth element which is a value 5 is accessed in this

24

00:02:09,450  -->  00:02:10,140
way.

25

00:02:10,520  -->  00:02:15,360
That is you will have the Aryanism followed by square brackets with the index number in between the

26

00:02:15,360  -->  00:02:17,020
square brackets.

27

00:02:17,370  -->  00:02:18,140
Multiple axis.

28

00:02:18,140  -->  00:02:24,000
Fourth element the next number will be three as index numbering starts with zero.

29

00:02:25,050  -->  00:02:28,380
No coming to creating an array there are three ways to do it.

30

00:02:28,800  -->  00:02:33,160
Let's look at how we can create our example or a call to my at it.

31

00:02:33,240  -->  00:02:38,520
Let's just look at the case where an arrest or primitives later we will see an example where underresourced

32

00:02:38,610  -->  00:02:43,560
object references and hit is a fast way to do it.

33

00:02:43,560  -->  00:02:49,020
We use the word new knew the number of elements that are it would store is indicated in square brackets

34

00:02:49,020  -->  00:02:50,130
.

35

00:02:50,130  -->  00:02:54,970
This declaration is quite similar to the declaration we saw for creating objects.

36

00:02:55,020  -->  00:02:59,840
The difference is that in this index we how additional square brackets on the left hand side of that

37

00:02:59,840  -->  00:03:02,180
assignment are on the right hand side.

38

00:03:02,200  -->  00:03:09,990
MP balances is replaced by square brackets since the arrays of pipe and each element will by default

39

00:03:09,990  -->  00:03:11,690
be zero that is.

40

00:03:11,700  -->  00:03:17,270
Each element is basically an end variable and is initialized with a default value an inquiry.

41

00:03:17,270  -->  00:03:18,140
But you can get.

42

00:03:18,210  -->  00:03:19,580
Which is zero.

43

00:03:20,100  -->  00:03:25,320
So do the R.H. then if it's an object it's elements here are primitives.

44

00:03:25,320  -->  00:03:32,220
Next step would be to initialize each element all the seven elements are initialized in this way using

45

00:03:32,220  -->  00:03:34,140
their next numbers.

46

00:03:34,140  -->  00:03:41,110
The Szilard element is initialized with the value 9 first element with the value 11 and so on.

47

00:03:41,110  -->  00:03:43,160
Not since an array is an object.

48

00:03:43,290  -->  00:03:48,840
If the other declaration contains only that type under array name then that variable gets the default

49

00:03:48,840  -->  00:03:49,460
value.

50

00:03:49,470  -->  00:03:53,510
Any object reference gets which is null.

51

00:03:53,550  -->  00:03:55,730
Here is the second way to create an array.

52

00:03:55,870  -->  00:04:02,040
Syntax is similar to the first approach but with two differences is Element initialization is done in

53

00:04:02,040  -->  00:04:05,340
the declaration itself and between the two braces.

54

00:04:05,460  -->  00:04:09,280
Second difference is we have empty square brackets on the right hand side.

55

00:04:09,480  -->  00:04:12,210
That is we don't explicitly specify the array size.

56

00:04:12,360  -->  00:04:17,190
I is automatically inferred from the number of elements used to initialize the.

57

00:04:17,430  -->  00:04:23,320
In this case it is 7 specifying that RSS will result in a compile time error.

58

00:04:24,620  -->  00:04:27,380
Finally to create an array has a simpler syntax.

59

00:04:27,840  -->  00:04:30,780
Right answer in quotes only element initialization.

60

00:04:30,920  -->  00:04:36,930
There is no Nuki word order type information with the square brackets.

61

00:04:36,930  -->  00:04:42,720
Finally we saw that in all three array creation examples the declaration began with the element type

62

00:04:42,720  -->  00:04:45,500
followed by empty square brackets.

63

00:04:45,560  -->  00:04:51,170
However it is perfectly legal to also have the empty square brackets after the are in him instead of

64

00:04:51,180  -->  00:04:53,690
the element type like we see here.

65

00:04:54,330  -->  00:04:59,580
Personally I prefer to have it after the element type and that's because on the right side also the

66

00:04:59,580  -->  00:05:02,430
square brackets follow the element type.

67

00:05:02,430  -->  00:05:08,270
So it's just for the sake of consistency but it is entirely up to you.

68

00:05:08,280  -->  00:05:11,010
Often we need to know the length or size of the army.

69

00:05:11,100  -->  00:05:14,110
That is the number of elements or array contents.

70

00:05:14,110  -->  00:05:20,490
And for this we can use the length of the ID that is left is a feat within the array object as an array

71

00:05:20,490  -->  00:05:23,480
is an object as we already discussed.

72

00:05:24,480  -->  00:05:33,040
So for our miring example accessing lanthanum my very variable returns the value 7 we know that aria

73

00:05:33,050  -->  00:05:38,730
has a fixed number of elements and so accessing an element outside of the boundary will result in an

74

00:05:38,850  -->  00:05:41,500
added runtime.

75

00:05:41,760  -->  00:05:47,610
For example my idea has only seven elements and so trying to access elements beyond the seventh element

76

00:05:47,810  -->  00:05:50,670
really do are on parameter in this example.

77

00:05:50,670  -->  00:05:56,370
We are trying to access the eighth element which is stored in next number 7 and it will result in a

78

00:05:56,370  -->  00:05:58,970
runtime error.

79

00:05:59,100  -->  00:06:05,180
So we looked at arrays containing primitives but arrays can also store object references.

80

00:06:05,280  -->  00:06:08,550
And here is an example similar to an array of ends.

81

00:06:08,640  -->  00:06:15,360
We can create an array of object references here and article students is created which can store boost

82

00:06:15,360  -->  00:06:23,760
with an object or Francis as you can see the type of the R is simply changed from end to student.

83

00:06:23,760  -->  00:06:29,880
Since each element is an object reference but default each element gets initialized with no.

84

00:06:31,170  -->  00:06:36,000
Since each element is an object reference we can initialize each element by assigning a new student

85

00:06:36,000  -->  00:06:37,220
object.

86

00:06:37,290  -->  00:06:43,920
So each element no references that student object on so we can also initialize each element state in

87

00:06:43,920  -->  00:06:47,270
this bit using the dot operator.

88

00:06:47,310  -->  00:06:52,620
So basically arrays can store either primitives or object references on be no understand how it can

89

00:06:52,620  -->  00:06:55,080
be done.

90

00:06:55,090  -->  00:07:01,980
Now let's discuss a bit about how arrays are represented within memory Gibeon specification doesn't

91

00:07:01,980  -->  00:07:05,540
say anything about how an object is stored inside memory.

92

00:07:05,920  -->  00:07:06,430
Hello.

93

00:07:06,450  -->  00:07:12,420
It is generally believed that most GBM implementations use a mediately out when it comes to.

94

00:07:12,810  -->  00:07:16,080
That is that our elements are stored contiguously.

95

00:07:16,080  -->  00:07:19,400
In other words they are stored next to each other in the memory.

96

00:07:19,740  -->  00:07:22,140
And this and also fast random access.

97

00:07:22,440  -->  00:07:26,820
There is any element can be accessed in in constant time.

98

00:07:26,820  -->  00:07:33,780
So accessing Tozan element would take the same amount of time as accessing the fifth element the element

99

00:07:33,780  -->  00:07:38,180
access is extremely fast if you want to search for a particular item in the array.

100

00:07:38,250  -->  00:07:44,170
Then that would be linear time as we have to scan the directory starting from the first element.

101

00:07:44,670  -->  00:07:51,000
Later we would look at data structures that are designed specifically for fast searching not just look

102

00:07:51,000  -->  00:07:54,870
at a very simple and quick them off our list.

103

00:07:56,230  -->  00:08:01,110
OK in this demo we're going to fill up this new method called arrays and it's in walk from the main

104

00:08:01,110  -->  00:08:05,370
method and all the previous method invocations have been commented out.

105

00:08:05,880  -->  00:08:07,840
So we'll be just testing fewer things here.

106

00:08:07,860  -->  00:08:12,620
One is we'll create an array using the second approach that we solve for creating arrays.

107

00:08:12,930  -->  00:08:17,990
Then we will use the lenth function lengthy and really does that.

108

00:08:17,990  -->  00:08:21,840
And then we would also look at how we can access the elements right.

109

00:08:21,840  -->  00:08:22,470
We can use it.

110

00:08:22,470  -->  00:08:25,570
We can access the elements using and mixed numbers and we would also apply order.

111

00:08:25,590  -->  00:08:27,480
So it's going to be a really simple demo.

112

00:08:27,810  -->  00:08:34,320
So just go ahead and create the array and we will create the exact same idea that we have seen earlier

113

00:08:34,320  -->  00:08:36,180
.

114

00:08:36,360  -->  00:08:40,450
So let's just call it and followed by Grad rockets.

115

00:08:40,590  -->  00:08:44,850
Let's just call it my theory as we have seen in this light.

116

00:08:45,120  -->  00:08:48,460
It's in you and in the second approach.

117

00:08:48,580  -->  00:08:55,440
We'll have this kind of an operation followed by basis and we are going to initialize the elements right

118

00:08:55,440  -->  00:08:56,500
here in the declaration.

119

00:08:56,550  -->  00:08:59,810
So I have just copied that.

120

00:09:00,150  -->  00:09:08,850
So those are those are the same elements not just put in some of the things system not all or brindled

121

00:09:08,850  -->  00:09:14,960
and to just turn the Leonti just so let's see my re.

122

00:09:15,090  -->  00:09:19,800
Them niggas copy this.

123

00:09:20,010  -->  00:09:25,510
So this is going to print the size of the ID next leps access of all of the elements.

124

00:09:25,530  -->  00:09:28,700
So let me just copy this whole thing.

125

00:09:29,190  -->  00:09:38,240
It's axis the second element which is Axis using the element and next number one.

126

00:09:39,210  -->  00:09:46,680
So let's just go ahead and compile and does this by it's fine.

127

00:09:46,710  -->  00:09:47,390
So there you go.

128

00:09:47,400  -->  00:09:48,650
So we are inside our base.

129

00:09:48,690  -->  00:09:54,110
The ideal to 7 and the first the second element is basically 11.

130

00:09:54,150  -->  00:09:54,690
OK.

131

00:09:54,720  -->  00:10:01,740
This is what it is not it's just trying to access an element which is outside the boundary of I.

132

00:10:02,190  -->  00:10:08,820
So the idea has seven elements so let's just try to access the 8 element which is accessed using the

133

00:10:08,940  -->  00:10:11,490
next number 7.

134

00:10:12,560  -->  00:10:19,400
It's really compiled and this should give a runtime error and that's what we get here.

135

00:10:19,410  -->  00:10:22,950
It's this array index out of bounds exception.

136

00:10:23,100  -->  00:10:24,820
So we are getting a runtime error.

137

00:10:24,910  -->  00:10:29,370
And that's because we are trying to access something outside the boundary of the ID.

138

00:10:29,820  -->  00:10:32,090
OK so those are three simple things here.

139

00:10:32,240  -->  00:10:35,890
And so we now have an understanding of this.

140

00:10:36,120  -->  00:10:42,020
So the main thing that we need to remember about arrays is an arm is basically an object in yellow.

141

00:10:42,180  -->  00:10:45,780
OK I it will have a fixed number of elements.

142

00:10:45,810  -->  00:10:49,740
That's one thing I and all the elements should be of single type.

143

00:10:49,740  -->  00:10:53,640
In this case it is and but it can also be object references.

144

00:10:53,640  -->  00:11:00,660
So later in the project Beeville in the first version rule extensively use arrays undir we will we will

145

00:11:00,660  -->  00:11:04,260
try we'll create lot of ways that store object references.

146

00:11:04,410  -->  00:11:11,130
OK unjaded We will also look at other data structures sophisticated radar structures and that's about

147

00:11:11,130  -->  00:11:11,430
it.

148

00:11:11,430  -->  00:11:18,050
So just go ahead and you can find the updated basics democracy in the resources section and you can

149

00:11:18,060  -->  00:11:22,810
now download and exit this file it's a good program and you can play around with that.

150

00:11:22,950  -->  00:11:23,450
OK then.

151

00:11:23,460  -->  00:11:23,930
Thank you.

152

00:11:23,940  -->  00:11:25,110
And happy coding.
