Skip to content

List ordered push: search from back if lower than pivot#693

Merged
therault merged 1 commit intoICLDisco:masterfrom
devreal:ordered_list_insert_rev
Nov 1, 2024
Merged

List ordered push: search from back if lower than pivot#693
therault merged 1 commit intoICLDisco:masterfrom
devreal:ordered_list_insert_rev

Conversation

@devreal
Copy link
Copy Markdown
Contributor

@devreal devreal commented Nov 1, 2024

Determine a pivot point (mid point of priority range) and search from front or back depending on where the new item lies. Inserting elements with highest or lowest priority becomes a constant operation and elements within the current range will on average be O(N/2).

This works best with linear distribution of priorities. For non-linear distributions the insertion will be skewed to either front or back but and the worst case will still be O(N). Average complexity would still be closer to O(N/2) and insertion with highest and lowest priorities will still be O(1).

@devreal devreal requested a review from a team as a code owner November 1, 2024 20:50
Determine a pivot point (mid point of priority range) and search from
front or back depending on where the new item lies. Inserting elements
with highest or lowest priority becomes a constant operation and
elements within the current range will on average be O(N/2).

This assumes a linear distribution of priorities. For non-linear
distributions the insertion will be skewed to either front or back but
and the worst case will be O(N) but average complexity would still be
closer to O(N/2) and we win in cases of highest and lowest priorities.

Signed-off-by: Joseph Schuchart <joseph.schuchart@stonybrook.edu>
@devreal devreal force-pushed the ordered_list_insert_rev branch from 2be9718 to 2740a14 Compare November 1, 2024 21:52
@devreal
Copy link
Copy Markdown
Contributor Author

devreal commented Nov 1, 2024

Force-pushed a small correction: use !A_HIGHER_PRIORITY_THAN_B instead of A_LOWER_PRIORITY_THAN_B to put elements with same priority in the back.

@therault therault merged commit 7b5c423 into ICLDisco:master Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants