Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ * File: binarySearch.c * Author: Cindy * Description: example of linear, binary search algorithm iterative and * recursive versions * / #include #include #include
File: binarySearch.c
Author: Cindy
Description: example of linear, binary search algorithm iterative and
recursive versions
#include
#include
#include "binarySearch.h
linearSearch linearly searches for key and returns index where found or
Parameters
a array to search
n number elements in array
k key to find
iPtr number of iterations made
cPtr number of comparisons made
Precondition: iPtr and cPtr have been initialized to
Postcondition: iPtr contain number of iterations for the search
and cPtr number of comparisons
Returns: index where key found or
int linearSearch double a int n double k int iPtr int cPtr
ADD CODE HERE
iterativeBSearch uses an iterative binary search to find key and
returns index where found or
Parameters
a array to search
Returns: index where key found or
int linearSearch double a int n double k int iPtr int cPtr
ADD CODE HERE
iterativeBSearch uses an iterative binary search to find key and
returns index where found or
Parameters
a array to search
b bottom index of subarray to search
t top index of subarray
k key to find
iPtr pointer to number of recursive calls made
cPtr pointer to number of comparisons made
Precondition: iPtr and cPtr has been initialized to
Postcondition: cPtr contain number of comparisons for the search
and iPtr the number of recursive calls
Returns: index where key found or
int recursiveBSearch double a int b int t double k int iPtr int cPtr$
ADD CODE HERE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started