Skip to content

Commit 59992e4

Browse files
committed
Added few points in the notebook
1 parent eab82f5 commit 59992e4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Diff for: Arrays/Arrays.ipynb

+19-2
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": {

Diff for: Arrays/Arrays.py

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Array(object):
88
def __init__(self, sizeOfArray, arrayType = int):
99
self.sizeOfArray = len(list(map(arrayType, range(sizeOfArray))))
1010
self.arrayItems =[arrayType(0)] * sizeOfArray # initialize array with zeroes
11+
self.arrayType = arrayType
1112

1213
def __str__(self):
1314
return ' '.join([str(i) for i in self.arrayItems])
@@ -44,6 +45,7 @@ def delete(self, keyToDelete, position):
4445
if(self.sizeOfArray > position):
4546
for i in range(position, self.sizeOfArray - 1):
4647
self.arrayItems[i] = self.arrayItems[i + 1]
48+
self.arrayItems[i + 1] = self.arrayType(0)
4749
else:
4850
print('Array size is:', self.sizeOfArray)
4951

Diff for: Arrays/__pycache__/Arrays.cpython-35.pyc

2.49 KB
Binary file not shown.

0 commit comments

Comments
 (0)