Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C++ code only please also include the interative code for the pascal traingle too Task 0: Modify your Lab1 function so it only contains

in C++ code only please also include the interative code for the pascal traingle too
image text in transcribed
image text in transcribed
image text in transcribed
Task 0: Modify your Lab1 function so it only contains the code necessary to generate the Pascal Triangle iteratively (still using a dynamically allocated 2d array). Take out any input/output statements (cin/cout), so they don't affect time measurement in Task 2. Include this function in your lab2.cpp. Your function prototype should look like: int** iterativePascal(int degree) //returns 2d array filled with Pascal Triangle values up to given degree Task 1: Write function recursiveBico(int degree, int index) using recursion and use it to fill in your Pascal Triangle when called from a recursivePascal function. recursiveBico(int degree, int index) should have two parameters: the first one is the degree of binomial expression, and the second parameter is the ith coefficient. For example, bico (4,2) should return 6 because (x+y)4=x4+4x3y+6x2y2+4xy3+y4 Like Lab 1, you will need to (1) provide a user interface that asks the user for the desired degree and index of the coefficient, (2) build a 2d dynamic array to store the Pascal Triangle up to the desired degree This time you will fill in the values of your Pascal Triangle by calling a recursive function recursiveBico(int degree, int index). Hint: it will be similar to recursive Fibonacci. (3) print out the Pascal Triangle and requested coefficient for each approach (example below) Lab 1, iterative pascal triangle: 111 11121 111234136141 The result is: 6 Output 2 Task 2: Compare the execution time between your newly implemented recursive bic and the original you implemented in Lab 1. There are multiple ways to measure you program execution time. For example, using the time library chrono. // include chrono library and using its own namespace \#include chrono> using namespace std:: chrono; // set a clock before the program executes auto start = high_resolution_clock:: now(); // program execution, call either Pascal Triangle function here // make sure NOT to include cin or cout operations here, // as they will invalidate your time execution measurement! // set a clock after the program executes auto stop = high_resolution_clock:: now(); // get the execution time by calculating the difference auto duration = stop - start; auto duration_ns = duration_cast> (duration); // output the duration cout duration_ns. count () endl; Use different input sizes to test the two different approaches. For example, suppose yo old bico() in Lab 1 is bico(int degree, int index), and your new recursive bico is recursiveBico(int degree, int index), compare the following inputs

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

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

What is the basic difference from facing and a cutoff operation?

Answered: 1 week ago