1. Name Pick an algorithm that can be implemented recursively and non-recursivel
ID: 3706478 • Letter: 1
Question
1. Name Pick an algorithm that can be implemented recursively and non-recursively. What is the name of the algorithm? Describe what the algorithm does. 2. 3. 4 Implement the non-recursive version using C language. (save the file) 5. Implement the recursive version using C language. (save the file) 6. Implement the non-recursive version using MIPS. (save the file) 7. Implement the recursive version using MIPS. (save the file) 8. Simulate your implementations and compare the execution times in the table below. Algorithm version Time Non-recursive C language Recursive C language Non-recursive MIPS Recursive MIPSExplanation / Answer
2)Linear search, it can be implemented recursively and non recursively
3)Linear search is a searching algorithm, which search a given element in list, by matching with each element in the list...if found returns the position of it, in the list, if not found returns -1
4)
int linear_search_Nonrecursive(int a[],int n,int d)
{
//a[] array
//n array size
//d element to find
int i=0;
while(i<n)
{
if(a[i]==d)
return i;//returning the position where it found
i++;
}
return -1;//if not found...
}
5)int linear_search_recursive(int a[],int n,int d)
{
//a[] array
//n array size
//d element to find
if(n>0)
{
if(a[n-1]==d)
return n-1; //returning the position where it found
return linear_search_recursive(a,n-1,d);//recursive call
}
return -1;//if not found...
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.