Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 1. Write a recursive function countSmallerElements, which passes arrays A and B, both of them with same size. The array size, size and

image text in transcribed

Question 1 1. Write a recursive function countSmallerElements, which passes arrays A and B, both of them with same size. The array size, size and n are equal. The parameter size is constant and cannot be changed, but n changes. The function's main goal is to allow the algorithm run through each element of array A, and for each element, counts other elements that are smaller than itself. The algorithm stores the count result in corresponding array B. Use the algorithm in (2) below to help. The function declaration is given as: void countsmallerElements (int A[], int B[], const int size, int n ) 2. Write another overloaded function with the same function name, which counts and returns the count of elements in array A that are smaller than elem (or element). The function passes array A, the element to be checked against, and the size n. Use this function in the above function of (1) to help count the elements. The function signature (or declaration) is given as. int countsmallerElements(int A[], int elem, int n ) For this algorithm, you're free to implement it iteratively or recursively. If you are taking the recursive path, it's probably better to write the iterative algorithm first which is easier, test it to make sure it's working, and while placing it next to you, translate it into its recursive version. This way, you may understand better. 3. In the main function, declare arrays A and B and initialize them with given values before running them to obtain results in B as B={3,0,1,4,2}. Display array B to show the results. For the purposes of testing, you next test-case, is to add 5 more elements to A, change size to 10 and run the program. If you receive the expected results from the same algorithm, it would mean your algorithm is the solution to the question. A={7,2,3,8,4}B={0}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Put Your Data To Work 52 Tips And Techniques For Effectively Managing Your Database

Authors: Wes Trochlil

1st Edition

0880343079, 978-0880343077

More Books

Students also viewed these Databases questions

Question

5. To determine the financial benefits and costs of the program.

Answered: 1 week ago