Question
Recursion vs Iterative functions. For this assignment you will make a Recursion class with two recursive member functions. a) Implement the recursive binSearchRec algorithm presented
Recursion vs Iterative functions.
For this assignment you will make a Recursion class with two recursive member functions.
a) Implement the recursive binSearchRec algorithm presented in this chapter, starting on page 68 for a vector of vehicles. Sort first by year then take that list and sort it by make and then take that list and sort it by model. Read in the vehicles from a vehicle file (vehiclein.txt) that has a year, make, and model. Each vehicle is separated with a | (straight bar) on it's own line. (Note that make and models might have spaces in them)
b)Implement a member function with the same functional requirements, except instead of a recursive member function, use an iterative (non-recursive) binarySearchIter. Your iterative function should produce the same results as your recursive function.
vehiclein.txt file:
2010
Ford
Escape
|
2014
BMW
328xi
|
2014
BMW
428xi
|
2012
Ford
Fusion SE
|
2014
Lamborghini
Gallardo
|
***********************************************************
The coding language should be in c++. Thank you!
***********************************************************
CHAPTER 2 Recursion: The Mirrors 68 Question 4 In the previous definition of writeArrayBackward, why does the bo occur when the value of first exceeds the value of last Question 5 a recursive function that computes and returns the product of a 2 1 real numbers in an array Question 6 show how that you wrote for the previous question satisfi the function the properties of a recursive function Question write a recursive function that computes and returns the product of 7 integers in the array an Array[first last 4.2 Searching a sorted Array: The Binary Search Searching is an that occurs frequently. Often, searches are for a particular important task en n an array. We now will examine a few searching problems that have recursive solutions. Our goal is to develop further your understanding of recursion. This chapter began with an intuitive approach to a binary search algorithm by presenting high way to find a word in a dictionary. We now develop this algorithm fully and illustrate some important programming issues. ary search Recall the earlier solution to the dictionary problem: ers one of its problems at search (aDictionary: Dictionary, word string step if (aDictionary is one page in size) Scan the page for word else e middle Determine which ha of aDictionary contains word if (word is in the first half of aDictionary) search (first half of aDictionary, word) else search (second half of aDictionary, word) the Now alter the problem slightly by searching an array anArray of integers for a given value, target. The array, like the dictionary, must be sorted, or else a binary search is not applicable. Hence, assume that anArray[0] s anArray[1] s Array[2] s where size is s anArray [size 11 the size of the array. A level binary search for the array problem is binarysearch (anArray: ArrayType, target: Value Type if (anArray is of size 1) Determine if anArray's value is equal to target else Find midpoint of Determine which half of an Array contains target (target is in the first half of anArray) binary search (first half of anArray, target) else binary search (second half of anArray, target)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