What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.
void fun(){ int i, j; for (i=1; i<=n; i++) for (j=1; j<=log(i); j++) printf("GeeksforGeeks");} |
What is the time complexity of following function fun()? Assume that log(x) returns log value in base 2.
void fun(){ int i, j; for (i=1; i<=n; i++) for (j=1; j<=log(i); j++) printf("GeeksforGeeks");} |
0, 1, 2, 3 0 - 0, 1, 1, 2 -------- GROUP_A(0)
4 - 1, 2, 2, 3 -------- GROUP_A(1)16 - 1, 2, 2, 3 -------- GROUP_A(1)
8 - 1, 2, 2, 3 -------- GROUP_A(1)
void connect(Node* p) { if (p == NULL) return; if (p->leftChild == NULL || p->rightChild == NULL) return; Node* rightSibling; Node* p1 = p; while (p1) { if (p1->nextRight) rightSibling = p1->nextRight->leftChild; else rightSibling = NULL; p1->leftChild->nextRight = p1->rightChild; p1->rightChild->nextRight = rightSibling; p1 = p1->nextRight; } connect(p->leftChild);}