This repository has been archived by the owner on Apr 4, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ArrayMap.py #17
ArrayMap.py #17
Changes from 14 commits
96b946e
c9fd473
abace70
7b84b64
e2b1a27
94be139
87625b2
257968e
94e5e54
b42617a
bae3364
4b727d5
a718872
98f9485
a77bebc
9946167
7597c2c
b3bdaf4
7b51b13
4795d28
e891d43
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach! Here are the tradeoffs:
plusOrThis
and it will do an O(n) search, followed by an O(n log n) sort in the constructor if it wasn't foundempty
and plus things from itplusOrThis
does an O(log n) search to find out if something has to be added or not. If it does need to be added, the search tells you where it needs to be added, so the constructor doesn't need to do any checks.Basically, by making the constructor private, we can rely on the data always being sorted, by induction from the empty starting set. That means we never need to do an
n log n
sort, and can instead always do alog n
search.Your code is simpler and easier to read. There's a good argument to be made that this python is better than the Kotlin. Wait until there's a performance problem, then speed it up.
But if we have allowed the constructor to be public, then it's too late. People might be passing unsorted data in, so we can't make the switch.
It's okay to do the
n log n
sort instead of thelog n
search, we can improve performance later, but it's important to hide the constructor.