Question: C++ run time analysis analyse the following algorithms with regards to the running time do they terminate and are they correct? Give a short explanation

C++ run time analysis

analyse the following algorithms with regards to the running time

do they terminate and are they correct?

Give a short explanation for running time, termination and correctness.

Given is a vector v with any length n.

a) the function verify wether the product of to vector elements is the sum of all elements

bool test_product(vector & v) { int sum = 0; for (int i=0; i

return found; }

b) the function adds the even elements sum_even_odd[0] and the elements that are odd sum_even_odd[1]

vector sum_at_even_and_odd(vector & v) { vector sum_even_odd(2,0); for (int i=0; i<=1; i++) for (int j=0; j

return sum_even_odd; }

c) the function appends for every element in the vector the digit with opposite sign

void append_inverted_values(vector & v) { for (int i=0; i

}

d) the function calculates the sum of the elements at the index position that are a power of two (as far as this is a valid index)

int sum_at_scale(vector & v) { int sum = 0; int i = 2; while (i

e) the function determines the set of all subsets in the vector e.g v={1,2,3} { {},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3} })

vector> get_subsets(vector & v) { vector> subsets; vector single_set; subsets.push_back(single_set); // leere Menge for (int i=0; i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!