java - Big-O of Triple Nested Loop -


what time complexity (big-o) of such algorithm be

for (int = 1; < n; i++) {     (int j = 1; j < i; j++) {         (int k = 1; k < j; k++) {             x++;         }     }  } 

is exponential?

assuming input n

thanks!

for (int = 1; < n; i++) { // o(n) time complexity     (int j = 1; j < i; j++) { // o(n) time complexity         (int k = 1; k < j; k++) { // o(n) time complexity             x++;         }     }  } 

the first loop n number of computations. second loop continues go until i reaches condition, n, , k continues until jreaches condition. each loop reaching same condition, n

so, each loop has time complexity of o(n); because nested, multiply each n, results in total time complexity of o(n^3)


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -