Question
CAN SOMEONE HELP ME WITH THIS C++ PROBLEM PLEASE ( RECURSION ONLY ) Write a recursive function named matchCount that accepts two references to vectors
CAN SOMEONE HELP ME WITH THIS C++ PROBLEM PLEASE (RECURSION ONLY)
Write a recursive function named matchCount that accepts two references to vectors of integers as parameters and that returns the number of elements that match between them. Two elements match if they occur at the same index in both vectors and have equal values. For example, given the two vectors shown below, the call of matchCount(v1, v2) would compare as follows:
v1: {2, 5, 0, 3, 8, 9, 1, 1, 0, 7} | | | | | | | v2: {2, 5, 3, 0, 8, 4, 1}
The function should return 4 in this case because 4 of these pairs match (2-2, 5-5, 8-8, and 1-1). If either vector is empty, by definition it has no matches with the other vector, so your function should return 0.
Constraints: Your function must be recursive and not use any loops (for, while, etc.). You may not use a string, array, or any data structure (stack, map, set, etc.) other than the vectors passed. When your code is done running, the two vectors should have the same contents as when the call began. Either do not modify the vectors, or if you do modify them, restore them to their original state afterward. Note again that you may not declare any additional data structures. Your solution should run in no worse than O(N) time, where N is the number of elements in the vectors.
Show Header O matchCount Favorite Language/Type C++ recursion return Related Links: Stanford CH library API docs Vector Author: Marty Stepp (on 2016/06/16) write a recursive function named matchCount that accepts two references to vectors of integers as parameters and that returns the number of elements that match between them. Two elements match if they occur at the same index in both vectors and have equal values. For example, given the two vectors shown below the call of matchCount (v 1, v2) would compare as follows v1: 12, 5, 0, 3, 8, 9, 1, 1, 0, 7) I I I I I I v2: 12, 5, 3, 0, 8, 4, 1) The function should return 4 in this case because 4 of these pairs match (2-2, 5-5, 8-8, and 1-1). If either vector is empty, by definition it has no matches with the other vector, so your function should return 0. Constraints: Your function must be recursive and not use any loops (for, while, etc.). You may not use a string, array, or any data structure (stack, map, set, etc.) other than the vectors passed. When your code is done running, the two vectors should have the same contents as when the call began. Either do not modify the vectors, or if you do modify them, restore them to their original state afterward. Note again that you may not declare any additional data structures. Your solution should run in no worse than O(N) time, where Nis the number of elements in the vectors. Type your solution here: 1 int matchCountHelper (const Vector kint & v 1, const Vector kint & v2, int index)
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