Question

For each implementation, answer the following question: Suppose I run this with a particular value of...

For each implementation, answer the following question: Suppose I run this with a particular value of n, and it takes 10 seconds. Suppose I run it again, but I double the value of n. How long should I expect it to run?

Implementation 1
void Q4(vector <int> &v, int n) {
    int i;
    v.clear();
    for (i = 0; i < n; i++) v.push_back(i);
    for (i = 0; i < n; i++) v.push_back(i);
    for (i = 0; i < n; i++) v.push_back(i);
    for (i = 0; i < n; i++) v.push_back(i);
}

Implementation 2
void Q4(vector <int> &v, int n) {
    int i;
    v.clear();
    for (i = 0; i < n; i++) v.push_back(i);
  
Implementation 3
int Q4(int n) {
    if(n == 0) return 1;
    return 1 + Q4(n-1);
}

Implementation 4
int Q4(int n) {
    if(n == 0) return 1;
    return Q4(n-1) + Q4(n-1);
  
Implementation 5
void Q4(vector <int> &v, int n) {
    int i, j;
    v.clear();
    for (i = 0; i < n; i++) {
        for (j = 0; j < i; j++) v.push_back(i);
    }
    for (i = 0; i < n; i++) {
        for (j = 1; j < n; j *= 2) v.push_back(i+j);
    }
}

Choose your answers from the following multiple choice: Possible Answers: 1.) 20 seconds 2.) 10 seconds 3.) >60 seconds 4.) 44 seconds 5.) 40 seconds

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1)  1.) 20 seconds
2)  1.) 20 seconds
3)  1.) 20 seconds
4)  3.) >60 seconds
5)  5.) 40 seconds

Add a comment
Know the answer?
Add Answer to:
For each implementation, answer the following question: Suppose I run this with a particular value of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For each implementation, answer the following question: Suppose I run this with a particular value of...

    For each implementation, answer the following question: Suppose I run this with a particular value of n, and it takes 10 seconds. Suppose I run it again, but I double the value of n. How long should I expect it to run? Implementation 1 void Q4(vector <int> &v, int n) {     int i;     v.clear();     for (i = 0; i < n; i++) v.push_back(i);     for (i = 0; i < n; i++) v.push_back(i);     for (i =...

  • 5.35 LAB: Sort a vector Write a program that gets a list of integers from input,...

    5.35 LAB: Sort a vector Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 10 4 39 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space, including the last...

  • Provide a "big oh" run-time analysis for each of the following. When a value of “n”...

    Provide a "big oh" run-time analysis for each of the following. When a value of “n” is used, it is the size of the input. 4.) void problem 40 cin n min max for (int i min i n, i++) for (int j- 1: j< max, j++) tota while (total n tota total 2 total 5.) void problem 50 cin n; for (int i 0: i n, i++) for (int j 0; j i2; j++) for (int k 0; k...

  • hey I need help finishing this simplex program. public class Main {       /**       *...

    hey I need help finishing this simplex program. public class Main {       /**       * @param args       */       public static void main(String[] args) {             // TODO Auto-generated method stub             //FAIRE LES TODO dans Simplex             test1();test2();                   }       private static void test1() {             double[][] A = {                         { -1, 1, 0 },                         { 1, 4, 0 },                         { 2, 1, 0 },                         { 3, -4, 0 },                        ...

  • C++ Create a program that finds the dot product of two vectors. I'm currently trying to...

    C++ Create a program that finds the dot product of two vectors. I'm currently trying to display the dot product by calling the dotProduct member function however I am confused as to how to do this. What would be the proper way to display the dot product? I don't believe my dotProduct member function is set up correctly to access the proper data. Feel free to modify the dotProduct member function to allow for it to work with the other...

  • Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number...

    Add binary_search() (page 462) to your program. Modify main() to prompt the user for a number to search (until ^D) and display the position of the number in the sorted vector. Try your program for the following user input: 1 15 18 40 30 50 ^D The output should be: -1 2 -1 7 5 -1 int binary_search(vector<int> v, int from, int to, int value) { if (from > to) return -1; int mid = (from + to) / 2;...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;...

  • I am having trouble understanding how this code is able to use the contents of the...

    I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) {    if(!isdigit (s[0]))    {        if(s[0] != '-')        return false;               else if(s.length() == 1)        return false;    }       for...

  • Suppose that your implementation of a particular algorithm appears in Java as for (int pass =...

    Suppose that your implementation of a particular algorithm appears in Java as for (int pass = 1; pass<=n; pass++) { for (int index = 0; index<n; index++) { for (int count = 1; count<10; count++) { The previous code shows only the repetitions in the algorithm, not the computations that occur within the loops. These computations, however, are independent of n. what is the order of the algorithm? Justify your answer.

  • Question 4 1 pts Which of the following is an edge in this graph? (select all...

    Question 4 1 pts Which of the following is an edge in this graph? (select all that apply) 0 (4,5) O (3,5) O (2,4) (0,3) (3,1) (1,4) Question 5 1 pts Given the following vector v, what will the final value of v be? std::vector<int> y = {6,4,81,99,17}; v.pop_back(); v.pop_back(); v.push_back(32); v.pop_back(); v.push_back(12); v.pop_back() v.push_back(18); v.push_back(21); v.pop_back() O V = {17,32,18,21} O v = {21,18,12,32} O V = {32,12,18,21} O v = {6,4,81,18} Question 6 1 pts Given the following...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT