Skip to content

Commit 45f1e39

Browse files
committed
Array Implementation in Python
1 parent fb4ee6c commit 45f1e39

File tree

2 files changed

+127
-2
lines changed

2 files changed

+127
-2
lines changed

Arrays/.ipynb_checkpoints/Arrays-checkpoint.ipynb

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
"\n",
151151
"* Search: O(n)\n",
152152
"* Insert: O(n)\n",
153-
"* Delete: O(n)"
153+
"* Delete: O(n)\n",
154+
"* Indexing: O(1)"
154155
]
155156
},
156157
{
@@ -258,7 +259,7 @@
258259
},
259260
{
260261
"cell_type": "code",
261-
"execution_count": 6,
262+
"execution_count": 1,
262263
"metadata": {},
263264
"outputs": [
264265
{
@@ -308,6 +309,22 @@
308309
"for i in range (0, 6):\n",
309310
" print (arr[i], end=\" \")\n"
310311
]
312+
},
313+
{
314+
"cell_type": "markdown",
315+
"metadata": {},
316+
"source": [
317+
"### Disadvantages of Array"
318+
]
319+
},
320+
{
321+
"cell_type": "markdown",
322+
"metadata": {},
323+
"source": [
324+
"* __Fixed size__: The size of the array is static (specify the array size before using it, this can be overcome using Dynamic Arrays).\n",
325+
"* __One block allocation__: To allocate the array itself at the beginning, sometimes it may not be possible to get the memory for the complete array (if the array size is big).\n",
326+
"* __Complex position-based insertion__: To insert an element at a given position, we may need to shift the existing elements. This will create a position for us to insert the new element at the desired position. If the position at which we want to add an element is at the beginning, then the shifting operation is more expensive ."
327+
]
311328
}
312329
],
313330
"metadata": {
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"#### Author: OMKAR PATHAK"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"# Linked Lists"
15+
]
16+
},
17+
{
18+
"cell_type": "markdown",
19+
"metadata": {},
20+
"source": [
21+
"### What are Linked Lists?"
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"A linked List is a data structure used for storing collections of data. A linked list has the following properties.\n",
29+
"* Successive elements a re connected by pointers\n",
30+
"* The last element points to NULL(__None__ in Python)\n",
31+
"* Can grow or shrink in size during execution of a program\n",
32+
"* Can be made just as long as required (until systems memory exhausts)\n",
33+
"* Does not waste memory space (but takes some extra memory for pointers)"
34+
]
35+
},
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": [
40+
"### Properties of Linked Lists:"
41+
]
42+
},
43+
{
44+
"cell_type": "markdown",
45+
"metadata": {},
46+
"source": [
47+
"* Linked lists are linear data structures that hold data in individual objects called nodes. These nodes hold both the data and a reference to the next node in the list.\n",
48+
"* Each node contains a value, and a reference (also known as a pointer) to the next node. The last node, points to a null node. This means the list is at its end.\n",
49+
"* Linked lists offer some important advantages over other linear data structures. Unlike arrays, they are a dynamic data structure, resizable at run-time. Also, the insertion and deletion operations are efficient and easily implemented.\n",
50+
"* However, linked lists do have some drawbacks. Unlike arrays, linked lists aren't fast at finding the __n__th item.To find a node at position __n__, you have to start the search at the first node in the linked list, following the path of references times. Also, because linked lists are inherently sequential in the forward direction, operations like backwards traversal--visiting every node starting from the end and ending in the front--is especially cumbersome. (__Only sequential search possible__)\n",
51+
"* Additionally, linked lists use more storage than the array due to their property of referencing the next node in the linked list.\n",
52+
"* Finally, unlike an array whose values are all stored in contiguous memory, a linked list's nodes are at arbitrary, possibly far apart locations in memory."
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"### Common Operations:\n",
60+
"* Insert \n",
61+
"* Insert at end\n",
62+
"* Insert at beginning\n",
63+
"* Insert between\n",
64+
"* Delete \n",
65+
"* Search \n",
66+
"* Indexing"
67+
]
68+
},
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": [
73+
"### Time Complexity:"
74+
]
75+
},
76+
{
77+
"cell_type": "markdown",
78+
"metadata": {},
79+
"source": [
80+
"* Insertion: O(1)\n",
81+
"* Deletion: O(1)\n",
82+
"* Indexing: O(n)\n",
83+
"* Searching: O(n)"
84+
]
85+
}
86+
],
87+
"metadata": {
88+
"kernelspec": {
89+
"display_name": "Python 3",
90+
"language": "python",
91+
"name": "python3"
92+
},
93+
"language_info": {
94+
"codemirror_mode": {
95+
"name": "ipython",
96+
"version": 3
97+
},
98+
"file_extension": ".py",
99+
"mimetype": "text/x-python",
100+
"name": "python",
101+
"nbconvert_exporter": "python",
102+
"pygments_lexer": "ipython3",
103+
"version": "3.5.2"
104+
}
105+
},
106+
"nbformat": 4,
107+
"nbformat_minor": 2
108+
}

0 commit comments

Comments
 (0)