Question

In: Computer Science

Description of the problem: 1. Construct the recursive diagram of the Remove function that invokes the...

Description of the problem:
1. Construct the recursive diagram of the Remove function that invokes the function
recursive getIndexOf using the main program described in your module.
2. Construct the recursive diagram of the getFrequencyOf function that invokes the function
recursive countFrequency using the main program described in your module.

C++ Code of getIndex and getFrequency

template void ArrayBag::display() const{ cout int ArrayBag::getFrequencyOf(const ItemType& anEntry) const { return countFrequency(anEntry, 0); } // end getFrequencyOf template int ArrayBag::countFrequency(const ItemType& target,int sear chIndex) const { if (searchIndex < itemCount) { if (items[searchIndex] == target) { return 1 + countFrequency(target, searchIndex + 1); } else { return countFrequency(target, searchIndex + 1); } // end if } else return 0; // Base case } // end countFrequency • getIndexOf(): Retorna el indice donde se encuentra el elemento dentro del arreglo, en caso contrario retorna -1. template int ArrayBag::getIndexOf(const ItemType& target, int searchI ndex) const { int result = -1; if (searchIndex < itemCount) { if (items[searchIndex] == target) { result = searchIndex; } else { result = getIndexOf(target, searchIndex + 1); } // end if } // end if return result; } // end getIndexO .

C++ Main Program

#include<iostream>

using namespace::std;

#include"ArrayBag.h"

int main(){  

  ArrayBag<int> myArrayInteger;

  myArrayInteger.add(5);

  myArrayInteger.add(3);

  myArrayInteger.add(5);

  myArrayInteger.add(10);

  myArrayInteger.display();

  myArrayInteger.remove(5);

  myArrayInteger.display();

  myArrayInteger.add(3);

  myArrayInteger.add(3);

  cout << "El nuemo 3 esta "

<<myArrayInteger.getFrequencyOf(3)

<< "veces repetido en el arreglo\n";

if (myArrayInteger.contains(7)){

cout <"El numero 7 esta dentro del arreglo\n";

}

else{

  cout<<"El numero 7 no esta dentro del arreglo\n";

     }

system("pause");

return 0;

}//end main

Solutions

Expert Solution

1. The first image provided is the recursive function getIndexOf as mentioned in the first part of the question.

*It is a diagrametic representation of the recursive function call executed by the program.

2. The above image is the digrametic representation of the recursive function countFrequency as per executed by the function.

->> a. The oval symbol represents the START and END of the function.

b. The rectangular symbol represents the CODE to EXECUTE in the particular step.

c. The diamond shape represents the CONDITIONAL statement the particuar function.

d. The arrow direction represnts the execution SEQUENCE of the function accordingly.


Related Solutions

Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates...
Write a recursive Racket function "remove-char" that takes two string parameters, s and c, and evaluates to string s with all occurrences of c removed. The string c is guaranteed to be a length-1 string; in other words a single character string. For example (remove-char "abc" "b") should evaluate to "ac". Here is pseudocode that you could implement.
Description Construct a personal retirement problem and solve it. The purpose of this exercise is to...
Description Construct a personal retirement problem and solve it. The purpose of this exercise is to use the chapter’s concepts of future values, annuities, and compounding to your personal financial planning. Instructions ◦Determine the amount of investment funds you currently have available in all personal investments and self-directed and vested retirement accounts ◦Then, determine how much you will be adding to your investments a year in the future ◦Next, decide at what age you plan to retire. Determine what annual...
DESCRIPTION Objectives To develop a recursive solution to an open-ended iterative problem To develop a program...
DESCRIPTION Objectives To develop a recursive solution to an open-ended iterative problem To develop a program that manages bad input Description Write a program (printSquares.scala) that read non-negative Int values from a user one at a time. For each positive Int, print out a message with the square of the number. Your program should quit when the use enters a negative Int. Note: You will also need to manage bad input! If the user types something in that isn't an...
1.what is a base condition of recursive function? 2. why is the base condition of recursive...
1.what is a base condition of recursive function? 2. why is the base condition of recursive function important?
Task 1: Remove Number Complete the function remove number such that given a list of integers...
Task 1: Remove Number Complete the function remove number such that given a list of integers and an integer n, the function removes every instance of n from the list. Remember that this function needs to modify the list, not return a new list. Task 2: Logged List The log2() function is one of an algorithm designer’s favourite functions. You’ll learn more about this later, but briefly – if your input size is 1048576 elements, but you only look at...
Give a recursive algorithm to solve the following recursive function. f(0) = 0;    f(1) = 1;...
Give a recursive algorithm to solve the following recursive function. f(0) = 0;    f(1) = 1;   f(2) = 4; f(n) = 2 f(n-1) - f(n-2) + 2; n > 2 b) Solve f(n) as a function of n using the methodology used in class for Homogenous Equations. Must solve for the constants as well as the initial conditions are given.
Part 1: Write a recursive function that will calculate Fibonacci numbers using a recursive definition. Write...
Part 1: Write a recursive function that will calculate Fibonacci numbers using a recursive definition. Write a short program to test it. The input of this program must be a positive integer n; the output is the corresponding Fibonacci number F(n) Part 2: Write an iterative function to calculate Fibonacci numbers. Write a test driver for it. The input of this program must be a positive integer n; the output is the corresponding Fibonacci number F(n). Part 3: Write a...
1. Give a description of the following organelles and their function: Structure Description Function Plasma membrane...
1. Give a description of the following organelles and their function: Structure Description Function Plasma membrane Cytosol Cell Wall Centrioles Nucleoid Nucleus Nucleolus Chromosome/Chromatin Cytoplasm E.R. Endoplasmic Reticulum (Rough) E.R. Endoplasmic Reticulum (Smooth) Ribosome Golgi Apparatus Nuclear envelope(membrane) Lysosome Peroxisome Plastids Chloroplasts Mitochondria Cytoskeleton -          Microtubules -          Microfilaments -          Intermediate fibers Cilia Flagella 2. Compare plant and animal cells. (Differences and similarities) 3. What are the major roles of the cytoskeleton? 4. Compare Smooth and Rough ER. 5. How are...
Determine if each of the following recursive definition is a valid recursive definition of a function...
Determine if each of the following recursive definition is a valid recursive definition of a function f from a set of non-negative integers. If f is well defined, find a formula for f(n) where n is non-negative and prove that your formula is valid. f(0) = 1, f(n) = -f(n-1) + 1 for n ≥ 1 f(0) = 0, f(1) = 1, f(n) = 2f(n-1) +1 for n ≥ 1 f(0) =0, f(n) = 2f(n-1) + 2 for n ≥...
Problem 3: (a) Implement a sublinear running time complexity recursive function in Java public static long...
Problem 3: (a) Implement a sublinear running time complexity recursive function in Java public static long exponentiation(long x, int n) to calculate x^n. Note: In your function you can use only the basic arithmetic operators (+, -, *, %, and /). (b) What is the running time complexity of your function? Justify. (c) Give a number of multiplications used by your function to calculate x^63. Important Notes: • For the item (a): o You must add the main method in...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT