Question
Please, I want to solve all the paragraphs with a correct and clear solution. The solution must be in text format. Handwriting is completely rejected.
Question 1: [ 2 Marks]
Question 2: What is the time complexity of following code: [2 Marks]
static int rec(int n)
{
int g[] = new int[n+2];
int i;
g[0] = 0;
g[1] = 1;
for (i = 2; i <= n; i++)
{
g[i] = g[i-1] + g[i-2];
g[i] = g[i-1] - g[i-2];
}
return g[n];
}
Question 3: Find the complexity of the below program: [2Marks]
int a = 0, b = 0;
for (i = 0; i < N; i++) {
a = a + r();
a = a - r();
}
for (j = 0; j < M; j++) {
b = b + r();
}
Question 4: What is the time complexity of following code: [2Marks]
int a = 0;
for (j = N; j > i; j--) {
a = a + i + j;
}
Question : 5 Find the complexity of the below program [ 2 Marks]
public static int example5(int[ ] first, int[ ] second) { // assume equal-length arrays
int n = first.length, count = 0;
for (int i=0; i < n; i++) { // loop from 0 to n-1
int total = 0;
for (int j=0; j < n; j++) // loop from 0 to n-1
total += first[k];
if (second[i] == total) count++;
} return count;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started