-
Notifications
You must be signed in to change notification settings - Fork 0
/
RecursiveSearch.c
37 lines (31 loc) · 1009 Bytes
/
RecursiveSearch.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <stdio.h>
/**
* Performs recursive search on an array to find the target element.
*
* Time Complexity: O(n), where n is the number of elements in the array.
* Recursive search traverses through the array recursively until the target element is found or the search ends.
*
* @param array : The array to search in.
* @param begin : The starting index of the subarray to search within.
* @param end : The ending index of the subarray to search within.
* @param checkElement : The element to search for within the array.
*
* @return : The index of the found element if present, otherwise -1.
*/
int recursiveSearch(int array[], int begin, int end, int checkElement);
int main()
{
return 0;
}
int recursiveSearch(int array[], int begin, int end, int checkElement)
{
if(begin > end)
{
return -1;
}
if(array[begin] == checkElement)
{
return begin;
}
return recursiveSearch(array, begin + 1, end, checkElement);
}