@@ -799,7 +799,7 @@ def is_ordered(array, **kwargs):
799
799
Parameters
800
800
==========
801
801
802
- array: Array
802
+ array: OneDimensionalArray
803
803
The array which is to be checked for having
804
804
specified ordering among its elements.
805
805
start: int
@@ -847,55 +847,55 @@ def is_ordered(array, **kwargs):
847
847
return False
848
848
return True
849
849
850
-
851
850
def upper_bound (array , value , ** kwargs ):
852
851
"""
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.
855
854
856
855
Parameters
857
- ========
856
+ ==========
858
857
859
858
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
864
861
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
867
864
end: int, optional
868
865
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.
875
875
876
876
Returns
877
877
=======
878
878
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.
881
881
882
882
Examples
883
883
========
884
884
885
885
>>> 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
889
889
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
893
893
4
894
894
895
895
Note
896
896
====
897
897
898
- The OneDimensionalArray must be sorted beforehand
898
+ DynamicOneDimensionalArray objects may not work as expected.
899
899
"""
900
900
start = kwargs .get ('start' , 0 )
901
901
end = kwargs .get ('end' , len (array ))
@@ -913,56 +913,56 @@ def upper_bound(array, value, **kwargs):
913
913
inclusive_end = mid - 1
914
914
return index
915
915
916
-
917
916
def lower_bound (array , value , ** kwargs ):
918
917
"""
919
918
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.
921
921
922
922
Parameters
923
- ========
923
+ ==========
924
924
925
925
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
933
931
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.
942
942
943
943
Returns
944
944
=======
945
945
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
948
948
949
949
Examples
950
950
========
951
951
952
952
>>> 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
956
956
1
957
957
>>> 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
960
960
2
961
961
962
962
Note
963
963
====
964
964
965
- The OneDimensionalArray must be sorted beforehand
965
+ DynamicOneDimensionalArray objects may not work as expected.
966
966
"""
967
967
start = kwargs .get ('start' , 0 )
968
968
end = kwargs .get ('end' , len (array ))
@@ -980,7 +980,6 @@ def lower_bound(array, value, **kwargs):
980
980
inclusive_end = mid - 1
981
981
return index
982
982
983
-
984
983
def longest_increasing_subsequence (array ):
985
984
"""
986
985
Returns the longest increasing subsequence (as a OneDimensionalArray) that
0 commit comments