Problem 1. Select the running time of each function. void print_array (int* A, int n) for...
(a) Consider the following C++ function: 1 int g(int n) { 2 if (n == 0) return 0; 3 return (n-1 + g(n-1)); 4} (b) Consider the following C++ function: 1 bool Function (const vector <int >& a) { 2 for (int i = 0; i < a. size ()-1; i ++) { 3 for (int j = i +1; j < a. size (); j ++) { 4 if (a[i] == a[j]) return false; 5 6 } 7 return...
homework c++ find the error/correction void Showval (int n) for (int i = 0; i<10;-) cout <<n [i; )
This is for C in Linux: Problem 1: Given the following recursive function: void recursiveFunction( int m ) printf("%d", m); if( m <= 0 ) return; if( n + 2 == 0 ) recursiveFunction( m - 1); else recursiveFunction( m - 2); What is the output when the following functions are called with these parameters? recursiveFunction( 5 ); recursiveFunction( 10 ); recursiveFunction( 0);
1. 2. Find the tight bound on the run time for problem 1 and 2 void phone (int n) if (n <147) time +54 else { for (int 0; i< n/2; i++ time++ phone (n/3); for int i = 0; i <13*n; it+) time++ phone (2*n) 3) } void belt (int n) if (n 200) time +=700 else belt (7*n)/10) for (int i-0; i<n; i++) time++ belt (n/5) 0 i <130n; i+-10) for (int i time++ }
Data Structures, C++, SORT running time. Would help is small explanation is included. Problem 1. Select the worst-case running time of each function. bool search (int x, int* A, int n) if (linear search(x, A, n)) return true; insertion_sort(A, n); return binary_search (x, A, n); bool search_n_sort (int* A, int n) for (int x = 1; x <= n; ++x) if (linear_search(x, A, n)) ae()og(n) n) return true; insertion_sort(A, n); return false; bool sort_n_search (int* A, int n) insertion_sort(A, n);...
Please write code in C++ class S ( private: int data; public: S0 0; S(int n); void Inc0; void Grow(int n); Problem 3: Given: void Reset(int n); int GetSO:3; S:S (int n) ( data n;) void S: Inc0 (data++) void S::Grow(int n) {data + =n;} void S: Reset(int n) data n;) int S: GetsO f return data; ) Find: int maino t S a(8), b(2); a.Inc0; cout<ca.GetsOendl; I.. b.Grow(4); cout<<b.GetsO<endl; II
1.4.6 Give the order of growth (as a function of n) of the running times of each of the following code fragments: a, int sum=0; for (int k n: k > 0; k /= 2) for (int i 0; ǐ < k; İ++) sum++; b.int sum 0; for (int i = 1; i < n; i *= 2) for (int j = 0; j < i; j++) sum++; int sum = 0; for (int í = 1; i < n;...
5. What is the Big Oh method m2? public static void m2(int[] arr, int n) for (int í = 1; í <= n- 1; i++) pM2(arr [i], arr, 0, i - 1); // end m2 private static void pM2(int entry, int[l arr, int begin, int end) int i- end; for(; (i 〉= begin) && (entry 〈 arr [i]); i--) arr [1 + 1] = arr L1] arr[i + 1] - entry; return // end pM2
QUESTION 26 Given the following function: int secret(int num, int m) inti, prod=1; if (m=0) return 1: - for (i=0; i<m; i++) { prod = prod * num; } return prod; What is the output for this function call? cout << secret(10,6);
Give a big-Oh characterization, in terms of n,of the running time for each of the following code segments (use the drop-down): - public void func1(int n) { A. @(1). for (int i = n; i > 0; i--) { System.out.println(i); B. follogn). for (int j = 0; j <i; j++) System.out.println(j); c.e(n). System.out.println("Goodbye!"); D.@(nlogn). E.e(n). F.ein). public void func2 (int n) { for (int m=1; m <= n; m++) { system.out.println (m); i = n; while (i >0){ system.out.println(i); i...