Just the correct answer only please please
37. In an ascending sorted List named myVals
the kth smallest item is found by which of the following?
myVals [ k ]
myVals [ k-1 ]
myVals [ numItems - k ]
myVals [ numItems + k ]
38. What is the Time Complexity of the following snippet of code?
for ( int i = 0; i < n; ++i){
int j = 1;
while(j < n ){
j = 2 * j;
}
}
O(1)
O(logn)
O(n)
O(nlogn)
O(n2)
40. Which of the following is a prefix expression?
/ a + b c
a b c + /
a * b + c
a / ( b + c )
37 ans:
The elements are ascending order take example
2,4,6,9,13,17
So if we want find 3rd smaller element so we simple said 6 so
The index start from 0 in languages such as c,java,python,c++
6 is at position at 2 because index stat from 0 so
3-1=2
So answer is
Myvals[k-1]
If the index start from 1 such as like MATLAB .in MATLAB programming index start from 1 so then only answer is myvals[k]
Most languages index start from 0 so the answer is myvals[k-1]
38ans:
O(nlogn)
Because based on i for loop iterates n times and inner while loop iterated logn times based on j value so time complexity is
O(nlogn)
40ans:
/a + bc
Because the infix expression of above prefix is
(a/(b+c))
If you have any doubt comment below...
Just the correct answer only please please 37. In an ascending sorted List named myVals the...
3. (20 pts.) You are given two sorted lists of numbers with size m and n. Give an O(logn+ logm) time algorithm for computing the k-th smallest element in the union of the two lists. 4. (20 pts.) Solve the following recurrence relations and give a bound for each of them. CMPSC 465, Fall 2019, HW 2 (a) T(n) = 117(n/5)+13n!.3 (b) T(n) = 2T (n/4)+nlogn (c) T(n) = 5T (n/3) +log-n (d) T(n) = T(n/2) +1.5" (e) T(n) =...
Please help me with question 13(c,f,h,i,k,m) 13. Show that the following equalities are correct: (a) 5n2 - 6n(n2) (b) n! - O(n) (c) 2n22"+ n logn-e(n22) (d) I012(n3) (h) 6n3/(log n+1)O(n3) (i) n1.001 + n logn (n1.001) (j) nkte + nk logn 6(nkte) for all fixed k and e, k 0 and e> 0 (1) 33n3 + 4n2 2(n2) (m) 33n3 + 4n23)
1). What is the complexity of the following code snippet? { for (int count2 = 0; count2<n; count2++) { /*some sequence of O(1) step*/ } } select one: a. O(N^2) b. O(Log N) c. O(1) d. O(N!) 2). What is the complexity of the following code snippet? for (int count = 0; count<n; count++) { printsum(count) } select one: a. We need to know the complexity of the printsum() function. b. O(Log N) c. O(1) d. O(N) e. O(N^2) 3)....
Which big-O expression best characterizes the worst case time complexity of the following code? public static int foo(int N) ( int count = 0; int i1; while (i <N) C for (int j = 1; j < N; j=j+2) { count++ i=i+2; return count; A. O(log log N) B. O(log N2) C. O(N log N) D. O(N2)
hi show your solution in full details not just the final answer ,cheers mate can you help please thanks I am stuck please Answer the following questions: Given the code segments below with n as the problem size, answer the following questions: //Code Segment 1 (Consider n as a power of 3) int sum = 0; for(int i = 1; i <= n; i = i*3) sum++; // statement1 //Code Segment 2: (Consider both possibilities for x) if(x...
8. R-4.8 Order the following functions by asymptotic growth rate. 4nlogn + 2n 2^10 2^logn 3n + 100logn 4n 2^n n^2 + 10n n^3 nlogn 9. R-4.9 Give a big-Oh characterization, in terms of n, of the running time of the example 1 method shown in Code Fragment 4.12. 10. R-4.10 Give a big-Oh characterization, in terms of n, of the running time of the example 2 method shown in Code Fragment 4.12. 11. R-4.11 Give a big-Oh characterization, in...
Prove Big O in terms of nₒ and C? There are 5 examples: class Exercise { public static int example1(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j++) // loop from 0 to n-1 total += arr[j]; return total; } public static int example2(int[] arr) { int n = arr.length, total = 0; for (int j=0; j < n; j += 2) // note the increment of 2 total += arr[j]; return...
II. ALGORITHM COMPLEXITY AND ASYMPTOTIC ANALYSIS The below visual representations of iterative looping structures are provided for Question 3 through Question 20. Algorithm 1 Algorithm 2 log.n 256 Algorithm 3 Algorithm 4 n (10) Match one of our algorithms to the below code snippet. for (int i = 0; i <n; i++) { for(int j = 0; j<n; j++) { for (int k = 0; k<n; k++) { nop++; nop++; nop++; } } } for (int i = 0; i...
Hey, I really need help understanding the math get the answer that is given. Please help. Thanks in advance. for (int k =0; k s Ign; k++) {for (int i =0; is n2; i++) Print “Hello World"; for (int j =0; j s n; j++) Print “Hello World"; } When n = 2, how many times will “Hello World” be printed?16 When n =4, how many times will “Hello World” be printed? 66 Assuming that the print is the basic...
Using C++ please explain What is the Big-O time complexity of the following code: for (int i=0; i<N; i+=2) { ... constant time operations... Select one: o a. O(n^2) O b. O(log n) c. O(n) O d. 0(1) What is the Big-O time complexity of the following code: for(int i=1; i<N; i*=2) { ... constant time operations... Select one: O O a. O(n^2) b. 0(1) c. O(n) d. O(log n) O What is the Big-O time complexity of the following...