Skip to document

Time Complexity

Nothing
Course

Computer Science, Engineering (CSC502)

41 Documents
Students shared 41 documents in this course
Academic year: 2023/2024
Uploaded by:
Anonymous Student
This document has been uploaded by a student, just like you, who decided to remain anonymous.
Datta Meghe Institute of Medical Sciences

Comments

Please sign in or register to post comments.

Related Studylists

New

Preview text

####### URBAN

Time Complexity – Competitive Practice Sheet

1. Fine the time complexity of the func1 function in the program show in program1 as follows:

#include <stdio>

void func1( int array[] , int length)

{

int sum = 0 ;

int product = 1 ;

for ( int i = 0 ; i < length; i ++)

{

sum += array[ i ];

}

for ( int i = 0 ; i < length; i ++)

{

product *= array[ i ];

}

}

int main()

{

int arr [] = { 3 , 5 , 66 };

func1( arr , 3 );

return 0 ;

}

2. Fine the time complexity of the func function in the program from program2 as follows:

void func( int n)

{

int sum = 0 ;

int product = 1 ;

for ( int i = 0 ; i < n; i ++)

{

for ( int j = 0 ; j < n; j ++)

{

printf(" %d , %d\n", i , j );

}

}

}

return 1 ;

}
7. What is the time complexity of the following snippet of code?

int isPrime( int n) {

for ( int i = 2 ; i * i < 10000 ; i ++) {

if ( n % i == 0 )

return 0 ;

}

return 1 ;

}

isPrime();

Was this document helpful?

Time Complexity

Course: Computer Science, Engineering (CSC502)

41 Documents
Students shared 41 documents in this course
Was this document helpful?
URBAN