Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Splay Tree for City ID Lookup #1

Open
Acesonnall opened this issue Dec 5, 2017 · 0 comments
Open

Implement Splay Tree for City ID Lookup #1

Acesonnall opened this issue Dec 5, 2017 · 0 comments
Assignees

Comments

@Acesonnall
Copy link
Owner

Acesonnall commented Dec 5, 2017

At the moment, the main component of the application -- the "getWeather()" function in routes.js 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.

@Acesonnall Acesonnall self-assigned this Dec 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant