Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A few questions from a quiz that I need help answering: 1. #include <iostream> u

ID: 655390 • Letter: A

Question

A few questions from a quiz that I need help answering:

1.
#include <iostream>
using namespace std;
void decToBin(int num, int base);

int main()
{
    int decimalNum;
    int base;
    base = 2;
    cout << "Enter number in decimal: ";
    cin >> decimalNum;
    cout << endl;
    cout << "Decimal " << decimalNum << " = ";
    decToBin(decimalNum, base);
    cout << " binary" << endl;
    return 0;
}

void decToBin(int num, int base)
{
    if (num > 0)
    {
        decToBin(num / base, base);
        cout << num % base;
    }
}

Invocation of decToBin(13, 4) will result in _______ and invokes decToBin _______ times.
Invocation of decToBin(13, 8) will result in _______ and invokes decToBin _______ times.


2.

int new_largest(const int list[], int lowerIndex, int upperIndex)
{
    int max1, max2, half_items;

    if (lowerIndex == upperIndex)
        return list[lowerIndex];

    half_items = (upperIndex - lowerIndex + 1) / 2;

    max1 = new_largest(list, lowerIndex, lowerIndex + half_items-1);
    max2 = new_largest(list, lowerIndex + half_items, upperIndex);

    if (max1 > max2)
        return max1;
    else
        return max2;               
}

Function largest() is invoked _______ times when largest(list, 0, 7) is executed, whereas function new_largest() is invoked _______ times when new_largest(list, 0, 7) is executed.
Max recursion depth reached while computing largest(list, 0, 63) is _______, whereas max recursion depth reached while computing new_largest(list, 0, 63) is _______.



3.

Here is a recursion function to compute & return the quotient of (x/y). Fill in the blanks in the function to complete it.

int division(int x, int y)
{
    if (x < y)
        return ________;
    else
         return 1 + division(________, y);
}

Explanation / Answer

1)

Invocation of decToBin(13, 4) will result in 31 and invokes decToBin 4 times

Invocation of decToBin(13, 8) will result in 15 and invokes decToBin 4 times

2)

Note: largest function is not given here

function new_largest() is invoked 15 times when new_largest(list, 0, 7) is executed.

max recursion depth reached while computing new_largest(list, 0, 63) is 63.

3)

int division(int x, int y)
{
    if (x < y)
        return 0;
    else
         return 1 + division(x-y, y);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote