-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaggregate_analysis.py
44 lines (33 loc) · 2.08 KB
/
aggregate_analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
"""Aggregate_Analysis.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/12R3_Nr6Tud2pSyWGs8fIieasntlLeR_K
# **Amortized Analysis** :: Aggregate Method
*Amortized Analysis : Amortized analysis is a method of analyzing the costs associated with a data structure that averages the worst operations out over time. Often, a data structure has one particularly costly operation, but it doesn't get performed very often. That data structure shouldn't be labeled a costly structure just because that one operation, that is seldom performed, is costly.*
#### This is an implementation of a Dynamic Array, where any insertion in the Array at a position *x* (where *x* is a power of 2) leads to the generation of a new array. This array adds an overhead in the process as the new array has to copy the previous array into itself then insert the new element, thus having a complexity of *O(n)*.
---
-----------------------------------------------------------*Initializations*-----------------------------------------------------------
"""
import math
Dict = {}
List =[]
memarr=0
"""-----------------------------------------------------------*Logic*----------------------------------------------------------------"""
for i in range (0,10):
print(":::::::::::::::::::::::::::::::::::::")
x=input("DATA : ")
List.append(x)
print(len(List))
if math.ceil(math.log10(len(List))/(math.log10(2)))==math.floor(math.log10(len(List))/(math.log10(2))):
print("power of 2 : TRUE ------ NEW ARRAY GENERATED")
Dict[memarr]=List[0:len(List)]
print("COPYING DATA ******")
# print(len(List))
memarr=memarr+1
"""-----------------------------------------------------------*Displaying Output*-----------------------------------------------------------"""
print("DATA Entered ----------------->")
print(List)
print("MEMORY ALLOCATION ------------->")
print(Dict)
"""### In the above example, the no. of *keys* in the Dictionary *Dict* represents the no. of arrays created in the internal memory."""