For each of the following program fragments: Give an analysis of the running time (Big-Oh). Justify your answer A. public class GFG { // Linearly search x in att]. if x is present then //return the index, otherwise return -1 static int search (int arr[], int n, intx) { int i; for (i = 0: i

icon
Related questions
Question
100%
For each of the following program fragments:
Give an analysis of the running time (Big-Oh). Justify your answer?
A.
public class GFG {
// Linearly search x in att[]. if x is present then
//return the index, otherwise return -1
static int search (int arr[], int n, intx)
{
int i;
for (i = 0: i<n;i++){
if (arr[i] ==x){
return i;
}
}
return -1;
}
Transcribed Image Text:For each of the following program fragments: Give an analysis of the running time (Big-Oh). Justify your answer? A. public class GFG { // Linearly search x in att[]. if x is present then //return the index, otherwise return -1 static int search (int arr[], int n, intx) { int i; for (i = 0: i<n;i++){ if (arr[i] ==x){ return i; } } return -1; }
B.
sum=0;
for(i=0; i<n; i++)
for(j = 0; j <i* i; j++ )
for(k = 0; k<j; k++ )
sum++;
Transcribed Image Text:B. sum=0; for(i=0; i<n; i++) for(j = 0; j <i* i; j++ ) for(k = 0; k<j; k++ ) sum++;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS