From 0a92dcc89d850e52487bca67ca3ec241d14c0fd1 Mon Sep 17 00:00:00 2001 From: Miguel Alejandro Salgado Zapien Date: Fri, 12 Aug 2022 09:50:21 -0700 Subject: [PATCH] Corrected complexity for build_stats method. --- app.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app.py b/app.py index f2ff9af..cdb846d 100644 --- a/app.py +++ b/app.py @@ -14,12 +14,17 @@ class Stats: a linear amount of time, in the data length. """ _data = {} + # loop is linear in the data. for v in data: + # Dictionary access should be constant time. _data[v] = _data.get(v, 0) + 1 _list, prev = [], 0 + # Adding a constant 1001 steps. for i in range(0, 1002): + # Constant time step new = _data.get(i, 0) + prev + # constant time step _list.append(new) prev = new self._list = _list @@ -72,7 +77,8 @@ class DataCapture: which I think it's a good assumption to start with. """ - return Stats(sorted(self._values)) + # The sorted where turns this in to O(n*log(n)) + return Stats(self._values) if __name__ == "__main__":