Skip to content

Commit f22d410

Browse files
committed
Array Data Structure Added
1 parent 9ced257 commit f22d410

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/data-structures/Arrays/README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,33 @@
11

2-
#Arrays
2+
# Arrays
3+
34
This data structure organizes data in memory in a sequential manner where data is stored in consecutive memory locations. Because Arrays are mostly used data structures they come inbuilt in many programming languages.In JavaScript, arrays are objects which makes then reference types because they are not primitive types, they are created by the programmer. Arrays are stored in adjucent blocks of memory.
45

5-
##Operations:
6-
###Lookup/Access:
6+
## Operations:
7+
8+
### Lookup/Access:
9+
710
`Iet arr[2]` has time complexity of O(1) because the comp know exactly where the data is (at index 2)
8-
###Push(adding elements at the end of the array):`
11+
12+
### Push(adding elements at the end of the array):
13+
914
`Arr.push(“z”)` has time complexity of O(1) because the computer knows the last index.
1015
Can be O(n) for static arrays(has fixed size to add to this array the entire array is copied to a new location with more memory) even with dynamic arrays at rear times.
11-
###Pop(removing elements at the end of the array):
16+
17+
### Pop(removing elements at the end of the array):
18+
1219
`Arr.pop(“z”)` has time complexity of O(1) because the computer knows the last index
13-
###Insert:
20+
21+
### Insert:
22+
1423
Insertion with arrays has bigO of O(n) because it has to loop through the rest of the array elements to change there indices
15-
###Unshift/shift(adding and removing elements at the beginning of the array):
24+
25+
### Unshift/shift(adding and removing elements at the beginning of the array):
26+
1627
Adding and removing elements at the beginning of the array has bigO of O(n) because it has to loop through the rest of the array elements to change there indices
17-
###Deletion:
28+
29+
### Deletion:
30+
1831
Deleting elements from an array has bigO(n) because it has to loop through the rest of the array elements to change there indices.
1932
So arrays are good for access and adding elements at the end.
2033

0 commit comments

Comments
 (0)