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
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
Related questions
Question
100%
answer (A)
(B)
with explanation
![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;
}
[Marking criteria: 1 mark for answer, 1 mark for the Justify]](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9c19599b-77d1-4720-9166-c90506483400%2F481f2ac0-f099-4548-bbd1-fa7ed7850d8a%2Fdlngpcc_processed.jpeg&w=3840&q=75)
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;
}
[Marking criteria: 1 mark for answer, 1 mark for the Justify]
![B.
sum=0;
for(i=0; i<n; i++)
for(j = 0; j <i* i; j++ )
for(k = 0; k<j; k++)
sum++;
[Marking criteria: 1 mark for answer, 1 mark for the Justify]](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F9c19599b-77d1-4720-9166-c90506483400%2F481f2ac0-f099-4548-bbd1-fa7ed7850d8a%2Fw7bfv0m_processed.jpeg&w=3840&q=75)
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++;
[Marking criteria: 1 mark for answer, 1 mark for the Justify]
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)