58uint64_t interpolationSearch(
const std::vector<uint64_t> &arr,
60 uint64_t size = arr.size();
61 uint64_t low = 0, high = (size - 1);
65 while (low <= high && number >= arr[low] && number <= arr[high]) {
67 if (arr[low] == number) {
75 ((
static_cast<uint64_t
>(high - low) / (arr[high] - arr[low])) *
78 if (arr[pos] == number) {
82 if (arr[pos] < number) {
105 std::vector<uint64_t> arr = {{10, 12, 13, 16, 18, 19, 20, 21, 1, 2, 3, 4,
106 22, 23, 24, 33, 35, 42, 47}};
107 sort(arr.begin(), arr.end());
108 uint64_t number = 33;
109 uint64_t expected_answer = 15;
110 uint64_t derived_answer =
111 search::interpolation_search::interpolationSearch(arr, number);
112 std::cout <<
"Testcase: ";
113 assert(derived_answer == expected_answer);
114 std::cout <<
"Passed!\n";
Functions for the Recursive version of Inorder, Preorder, and Postorder Traversal of the Tree algorit...
Testcases to check Union of Two Arrays.