Skip to content

Commit 79b5b8c

Browse files
committed
resolved merge conflicts
2 parents 228b3f6 + 0f23c98 commit 79b5b8c

File tree

3 files changed

+53
-56
lines changed

3 files changed

+53
-56
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2019-2020 PyDataStructs Development Team
1+
Copyright (c) 2019-2021 PyDataStructs Development Team
22

33
All rights reserved.
44

pydatastructs/linear_data_structures/algorithms.py

Lines changed: 52 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ def is_ordered(array, **kwargs):
799799
Parameters
800800
==========
801801
802-
array: Array
802+
array: OneDimensionalArray
803803
The array which is to be checked for having
804804
specified ordering among its elements.
805805
start: int
@@ -847,55 +847,55 @@ def is_ordered(array, **kwargs):
847847
return False
848848
return True
849849

850-
851850
def upper_bound(array, value, **kwargs):
852851
"""
853-
Finds the index of the first occurence of an element greater than value according
854-
to an order defined,in the given sorted OneDimensionalArray
852+
Finds the index of the first occurence of an element greater than the given
853+
value according to specified order, in the given OneDimensionalArray using a variation of binary search method.
855854
856855
Parameters
857-
========
856+
==========
858857
859858
array: OneDimensionalArray
860-
The sorted array (sorted according to a custom comparator function) in which the
861-
upper bound has to be found
862-
863-
start: int, optional
859+
The array in which the upper bound has to be found.
860+
start: int
864861
The staring index of the portion of the array in which the upper bound
865-
of a given value has to be looked for
866-
862+
of a given value has to be looked for.
863+
Optional, by default 0
867864
end: int, optional
868865
The ending index of the portion of the array in which the upper bound
869-
of a given value has to be looked for
870-
871-
comp: boolean function, optional
872-
A function that specifies the ordering of elements. By default, it takes two
873-
parameters and returns True if 1st parameter is strictly smaller than
874-
2nd parameter
866+
of a given value has to be looked for.
867+
Optional, by default the index
868+
of the last position filled.
869+
comp: lambda/function
870+
The comparator which is to be used
871+
for specifying the desired ordering.
872+
Optional, by default, less than or
873+
equal to is used for comparing two
874+
values.
875875
876876
Returns
877877
=======
878878
879-
output: int
880-
Index of the upper bound of the given value in the given sorted OneDimensionalArray
879+
index: int
880+
Index of the upper bound of the given value in the given OneDimensionalArray.
881881
882882
Examples
883883
========
884884
885885
>>> from pydatastructs import upper_bound, OneDimensionalArray as ODA
886-
>>> arr = ODA(int, [4, 5, 5, 6, 7])
887-
>>> upperBound = upper_bound(arr, 5, start = 0, end = 4)
888-
>>> upperBound
886+
>>> arr1 = ODA(int, [4, 5, 5, 6, 7])
887+
>>> ub = upper_bound(arr1, 5, start=0, end=4)
888+
>>> ub
889889
3
890-
>>> arr = ODA(int, [7, 6, 5, 5, 4])
891-
>>> upperBound = upper_bound(arr, 5, comp = lambda x, y: x > y)
892-
>>> upperBound
890+
>>> arr2 = ODA(int, [7, 6, 5, 5, 4])
891+
>>> ub = upper_bound(arr2, 5, comp=lambda x, y: x > y)
892+
>>> ub
893893
4
894894
895895
Note
896896
====
897897
898-
The OneDimensionalArray must be sorted beforehand
898+
DynamicOneDimensionalArray objects may not work as expected.
899899
"""
900900
start = kwargs.get('start', 0)
901901
end = kwargs.get('end', len(array))
@@ -913,56 +913,56 @@ def upper_bound(array, value, **kwargs):
913913
inclusive_end = mid - 1
914914
return index
915915

916-
917916
def lower_bound(array, value, **kwargs):
918917
"""
919918
Finds the the index of the first occurence of an element which is not
920-
less than value according to an order defined, in the given OneDimensionalArray
919+
less than the given value according to specified order,
920+
in the given OneDimensionalArray using a variation of binary search method.
921921
922922
Parameters
923-
========
923+
==========
924924
925925
array: OneDimensionalArray
926-
The sorted array (sorted according to a custom comparator function)
927-
in which the lower bound has to be found
928-
929-
start: int, optional
930-
The staring index of the portion of the array in which the lower
931-
bound of a given value has to be looked for. Default value is set to 0.
932-
926+
The array in which the lower bound has to be found.
927+
start: int
928+
The staring index of the portion of the array in which the upper bound
929+
of a given value has to be looked for.
930+
Optional, by default 0
933931
end: int, optional
934-
The ending index of the portion of the array in which the lower
935-
bound of a given value has to be looked for. Default value is set to
936-
end of array, i.e., len(arr)
937-
938-
comp: boolean function, optional
939-
A function that specifies the ordering of elements. By default, it takes two
940-
parameters and returns True if 1st parameter is strictly smaller than
941-
2nd parameter
932+
The ending index of the portion of the array in which the upper bound
933+
of a given value has to be looked for.
934+
Optional, by default the index
935+
of the last position filled.
936+
comp: lambda/function
937+
The comparator which is to be used
938+
for specifying the desired ordering.
939+
Optional, by default, less than or
940+
equal to is used for comparing two
941+
values.
942942
943943
Returns
944944
=======
945945
946-
output: int
947-
Index of the lower bound of the given value in the given sorted OneDimensionalArray
946+
index: int
947+
Index of the lower bound of the given value in the given OneDimensionalArray
948948
949949
Examples
950950
========
951951
952952
>>> from pydatastructs import lower_bound, OneDimensionalArray as ODA
953-
>>> arr = ODA(int, [4, 5, 5, 6, 7])
954-
>>> lowerBound = lower_bound(arr, 5, end = 4, comp = lambda x, y : x < y)
955-
>>> lowerBound
953+
>>> arr1 = ODA(int, [4, 5, 5, 6, 7])
954+
>>> lb = lower_bound(arr1, 5, end=4, comp=lambda x, y : x < y)
955+
>>> lb
956956
1
957957
>>> arr = ODA(int, [7, 6, 5, 5, 4])
958-
>>> lowerBound = lower_bound(arr, 5, start = 0, comp = lambda x, y : x > y)
959-
>>> lowerBound
958+
>>> lb = lower_bound(arr, 5, start=0, comp=lambda x, y : x > y)
959+
>>> lb
960960
2
961961
962962
Note
963963
====
964964
965-
The OneDimensionalArray must be sorted beforehand
965+
DynamicOneDimensionalArray objects may not work as expected.
966966
"""
967967
start = kwargs.get('start', 0)
968968
end = kwargs.get('end', len(array))
@@ -980,7 +980,6 @@ def lower_bound(array, value, **kwargs):
980980
inclusive_end = mid - 1
981981
return index
982982

983-
984983
def longest_increasing_subsequence(array):
985984
"""
986985
Returns the longest increasing subsequence (as a OneDimensionalArray) that

pydatastructs/linear_data_structures/tests/test_algorithms.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ def test_is_ordered():
159159
output = is_ordered(arr4)
160160
assert output == expected_result
161161

162-
163162
def test_upper_bound():
164163
ODA = OneDimensionalArray
165164
arr1 = ODA(int, [3, 3, 3])
@@ -245,7 +244,6 @@ def test_lower_bound():
245244
expected_result = 1
246245
assert expected_result == output
247246

248-
249247
def test_longest_increasing_subsequence():
250248
ODA = OneDimensionalArray
251249

0 commit comments

Comments
 (0)