You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, the main component of the application -- the "getWeather()" function in has a worst-case time complexity of O(n) if we ignoring the time complexity of functions from imported packages. This is calculated from the for-loop on line 66 since, worst-case scenario, the loop will iterate through every entry in the JSON array.
To make the algorithm more efficient, the contents of the JSON array could be inserted into a self-adjusting binary search tree, or splay tree (amortized O(log n)) and then a value can be searched for in O(log n) time, making the worst-case time complexity of the "getWeather()" function O(log n) overall instead of O(n) as it is now. This is because a splay tree would allow for the most recently accessed elements to also be the quickest to access again. For a weather application, this would make sense since we can assume that cities with larger populations will be looking up the weather for their location very frequently and, thus, could easily benefit from the speed improvements provided by a splay tree.
The text was updated successfully, but these errors were encountered:
At the moment, the main component of the application -- the "getWeather()" function in has a worst-case time complexity of O(n) if we ignoring the time complexity of functions from imported packages. This is calculated from the for-loop on line 66 since, worst-case scenario, the loop will iterate through every entry in the JSON array.
To make the algorithm more efficient, the contents of the JSON array could be inserted into a self-adjusting binary search tree, or splay tree (amortized O(log n)) and then a value can be searched for in O(log n) time, making the worst-case time complexity of the "getWeather()" function O(log n) overall instead of O(n) as it is now. This is because a splay tree would allow for the most recently accessed elements to also be the quickest to access again. For a weather application, this would make sense since we can assume that cities with larger populations will be looking up the weather for their location very frequently and, thus, could easily benefit from the speed improvements provided by a splay tree.
The text was updated successfully, but these errors were encountered: