Skip to content

Commit

Permalink
Organized readme.md of data structures and added time complexity (#31)
Browse files Browse the repository at this point in the history
* Update readme.md

* Create Array.md

* Update Array.md

* Update Array.md

* Update readme.md

* Update readme.md

* Update readme.md

* Update readme.md

* Update readme.md

* added blobaccess

* Cleaning Readme.md

* Update readme.md

* Create LinkedList.md

* Created New readme.md files for array and ll

Created a blob access for other readme.md files which prevents the data structures readme to get too long. Will be adding the same for stack and other data structures as well

* added changes

* changed file structure

* added array and linked list

* Update readme.md
  • Loading branch information
AnjumanHasan authored Oct 2, 2022
1 parent 41d0108 commit 4cfd905
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Data Structures/Array.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Array
An array is a data structure that stores a collection of data values in contiguous memory locations.

### Example
```
let array = [4,3,8,1,0,14,6];
```

| Memory Location | Value |
|-----------------|-------|
| 1000 | 4 |
| 1001 | 3 |
| 1002 | 8 |
| 1003 | 1 |
| 1004 | 0 |
| 1005 | 14 |
| 1006 | 6 |

Accessing an element in an array is done by indexing into it.
```
array[0] // 4 (index 0 is the first element) (1000)
array[1] // 3 (index 1 is the second element) (1001)
array[2] // 8 (index 2 is the third element) (1002)
array[3] // 1 (index 3 is the fourth element) (1003)
array[4] // 0 (index 4 is the fifth element) (1004)
array[5] // 14 (index 5 is the sixth element) (1005)
array[6] // 6 (index 6 is the seventh element) (1006)
```

#### Time complexities of some basic array operations

| Operation | Time Complexity |
|-----------------|-------|
| Accessing an element | O(1) |
| Searching an element | O(N) |
| Inserting an element | O(N) |
| Deleting an element | O(N) |

43 changes: 43 additions & 0 deletions Data Structures/LinkedList.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

## LinkedList
A linked list is a data structure that consists of a group of nodes where each node contains a data value and a reference (or link) to the next node in the list.

### Example
```
let list = [4,3,1,0,14,6];
```

| Memory Location | Value |
|-----------------|-------|
| 1000 | 4 |
| 1001 | 1008 |
| 1002 | 1 |
| 1003 | 1004 |
| 1004 | 0 |
| 1005 | 1006 |
| 1006 | 14 |
| 1007 | 1010 |
| 1008 | 3 |
| 1009 | 1002 |
| 1010 | 6 |
| 1011 | 1000 |

Accessing an element in a linked list is done by traversing the list and finding the element at the correct index.
```
index 0 value is 4 with memory location 1000 and pointer to next node 1008
index 1 value is 3 with memory location 1008 and pointer to next node 1002
index 2 value is 1 with memory location 1002 and pointer to next node 1004
index 3 value is 0 with memory location 1004 and pointer to next node 1006
index 4 value is 14 with memory location 1006 and pointer to next node 1010
index 5 value is 6 with memory location 1010 and pointer to first node 1000
```

#### Time complexities of some basic Linked List operations

| Operation | Time Complexity |
|-----------------|-------|
| Accesing an element | O(N) |
| Searching an element | O(N) |
| Inserting an element | O(1) |
| Deleting an element | O(1) |

25 changes: 25 additions & 0 deletions Data Structures/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ array[5] // 14 (index 5 is the sixth element) (1005)
array[6] // 6 (index 6 is the seventh element) (1006)
```

#### Time complexities of some basic array operations

| Operation | Time Complexity |
|-----------------|-------|
| Accessing an element | O(1) |
| Searching an element | O(N) |
| Inserting an element | O(N) |
| Deleting an element | O(N) |

[More on Array](Array.md)


## LinkedList
A linked list is a data structure that consists of a group of nodes where each node contains a data value and a reference (or link) to the next node in the list.

Expand Down Expand Up @@ -73,6 +85,19 @@ index 4 value is 14 with memory location 1006 and pointer to next node 1010
index 5 value is 6 with memory location 1010 and pointer to first node 1000
```

#### Time complexities of some basic Linked List operations

| Operation | Time Complexity |
|-----------------|-------|
| Accesing an element | O(N) |
| Searching an element | O(N) |
| Inserting an element | O(1) |
| Deleting an element | O(1) |


[More on Linked List](LinkedList.md)


## Stack
A stack is a data structure that stores a collection of data values in a LIFO (last in, first out) order.

Expand Down

0 comments on commit 4cfd905

Please sign in to comment.