bisectw
Wrappers around bisect python standard library.
bs_add(a, x)
#
Adds x
to the sorted list a
while maintaining sorted order.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
List[int]
|
Sorted list of int numbers. |
required |
x |
int
|
Element to be added to |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Index where |
Time Complexity
O(log n + n), where n is the length of list a
.
Source code in ranged_heap/bisectw.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
bs_delete(a, x)
#
Deletes the first occurrence of x
from the sorted list a
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a |
List[int]
|
Sorted list of int numbers. |
required |
x |
int
|
Element to be deleted from |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
Index of the deleted element if found, otherwise -1. |
Time Complexity
O(log n + n), where n is the length of list a
.
Source code in ranged_heap/bisectw.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|