Skip to content

Commit d2f84dc

Browse files
authored
Update Arrays_Introduction.md
1 parent 44e2270 commit d2f84dc

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/com/deepak/data/structures/Arrays/Arrays_Introduction.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
## Arrays
22

3-
- Arrays is the most basic type of data structure that stores similar kind of values.
4-
- Each item in a array is a element and can be accessed using a index.
5-
- Normally arrays have 0 based index which means indexing starts from 0 and goes till _n - 1_ where n is the number of elements in array.
3+
- Arrays are the most basic type of data structure that stores similar kind of values.
4+
- Each item in an array is an element and can be accessed using an index.
5+
- Normally arrays have 0 based index which means indexing starts from 0 and goes till _n - 1_ where n is the number of elements in an array.
66
- Arrays can have 0 based indexing, 1 based indexing or n based indexing (for negative values)
77
- Size of an array is fixed at runtime when initialized. It can't be changed after initialization.
8-
- If size has to be changed after initialization, use _ArrayList_ (Collection class) instead.
9-
- Size of an array can be specified using int only, since arrays are int based index.
8+
- If the size has to be changed after initialization, use _ArrayList_ (Collection class) instead.
9+
- Size of an array can be specified using int only since arrays are int based index.
1010
- The ArrayIndexOutOfBoundsException is thrown when a non-existing index of an array is being accessed.
1111
- Arrays are used to implement mathematical vectors and matrices, as well as other kinds of rectangular tables.
1212
- Many databases, small and large, consist of (or include) one-dimensional arrays whose elements are records.
1313
- Arrays are used to implement other data structures, such as heaps, hash tables, deques, queues, stacks, strings, and VLists.
1414
- Below is the representation,
1515

16-
<img width="426" alt="screen shot 2016-08-31 at 2 21 49 pm" src="https://cloud.githubusercontent.com/assets/3439029/18146774/600b0d4a-6f86-11e6-8005-3f6da1afc95f.png">
16+
<img width="426" alt="array" src="https://cloud.githubusercontent.com/assets/3439029/18146774/600b0d4a-6f86-11e6-8005-3f6da1afc95f.png">
1717
**************************************
1818

1919
**Defining Arrays**
@@ -30,7 +30,7 @@ However, since it's an empty array, no elements can be assigned to it:
3030
```java
3131
array[0] = 1; // Throws java.lang.ArrayIndexOutOfBoundsException.
3232
```
33-
Such empty arrays are typically useful as return values, so that the calling code only has to worry about dealing with an array, rather than a potential null value that may lead to a NullPointerException.
33+
Such empty arrays are typically used as return values so that the calling code only has to worry about dealing with an array, rather than a potentially null value that may lead to a NullPointerException.
3434
The length of an array must be a non-negative integer:
3535
```java
3636
int[] array = new int[-1]; // Throws java.lang.NegativeArraySizeException
@@ -65,9 +65,9 @@ Below is the representation of multi dimensional array
6565

6666
![two-dimensional-array](https://cloud.githubusercontent.com/assets/3439029/18147340/0729cd8a-6f89-11e6-841f-5ac5bf53bd02.png)
6767

68-
There are two orders that can exists in a multi dimensional array, i.e
68+
There are two orders that can exist in a multidimensional array, i.e
6969
_Row major_ and _Column major_
70-
For ex, consider below matrix
70+
ex, consider below matrix
7171

7272
<img width="185" alt="screen shot 2016-08-31 at 9 50 23 pm" src="https://cloud.githubusercontent.com/assets/3439029/18155706/04e2045c-6fc5-11e6-847e-8d8f406de844.png">
7373

@@ -106,14 +106,14 @@ Here the class of T has to be explicitly passed to the constructor. The return t
106106

107107
**Sorted Arrays**
108108

109-
Arrays are considered to be sorted in ascending order when each element on left of that element in a array is smaller then that element itself. Vice versa goes for descending order.
109+
Arrays are considered to be sorted in ascending order when each element on the left of that element in an array is smaller than that element itself. Vice versa goes for descending order.
110110

111111
**Pros:**
112112
- Accessing an element is fast using the index - access time is O(1).
113113
- Much faster to process - see this question.
114114

115115
**Cons:**
116-
- Insertion and deletion are slow, subsequent elements must be moved - complexity for insertion in that case is O(n).
116+
- Insertion and deletion are slow, subsequent elements must be moved - complexity for insertion, in that case is O(n).
117117
- A large enough block of memory is needed to hold the array.
118118
- Easily corrupted (data could be inserted in the middle).
119119

@@ -126,14 +126,14 @@ Arrays are considered to be sorted in ascending order when each element on left
126126
| **Size** | _Fixed length. Cannot change the size after creation_ | _Dynamic in size. Capacity grows as the elements are added_ |
127127
| **Content** | _Can contain primitive data types and objects_ | _Objects only. No primitive data types_ |
128128
| **Dimension** | _Can be multi-dimensional_ | _Normally single dimensional, but can be made multi dimensional_ |
129-
| **Type Safety** | _Typesafe, meaning that array will contain objects of specific class or primitives of specific data type_ | _Not type safe by default. Generics can be used to make a List type safe_ |
129+
| **Type Safety** | _Typesafe, meaning that array will contain objects of specific class or primitives of specific data type_ | _Not type-safe by default. Generics can be used to make a List type safe_ |
130130
| **Insertion/Deletion** | _Shifting existing elements may be needed if action is performed not at the end of the array_ | _Easy insertion/deletion methods provided_ |
131131
**************************************
132132

133133
**Disadvantages of Arrays**
134-
- **Fixed Size** : The size of the array is static, i.e we define the size when we create the array, which can't change later on.
135-
- **One block allocation** : To allocate the array in the beginning, we may not have enough memory to hold entire array because of continous block of allocation.
136-
- **Complex position based insertion** : This is applicable only in case of dynamic array or list, where size can change. If we want to insert an element at position n, we have to shift all the elements in the right by one position to make space for this new element, which is a time consuming and costly operation.
134+
- **Fixed Size**: The size of the array is static, i.e we define the size when we create the array, which can't change later on.
135+
- **One block allocation**: To allocate the array, in the beginning, we may not have enough memory to hold entire array because of continuous block of allocation.
136+
- **Complex position based insertion**: This is applicable only in case of dynamic array or list, where size can change. If we want to insert an element at position n, we have to shift all the elements to the right by one position to make space for this new element, which is a time consuming and costly operation.
137137

138138
**Operations on Arrays**
139139

@@ -145,7 +145,7 @@ Below operations on Arrays are implemented [here](../Arrays/BasicOperations.java
145145
- Traversing through the elements of array
146146
- Copying/Resizing arrays
147147
- Removing elements from arrays
148-
- Sorting elements in a array
148+
- Sorting elements in an array
149149
- Arrays as method params
150150
- Arrays in memory
151151
- Casting arrays

0 commit comments

Comments
 (0)