#include <stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
void swap(char *x, char *y)
{
char temp;
temp = *x;
*x = *y;
*y = temp;
}
void func(char *a, int l, int r)
{
int i;
if (l == r)
cout<<a<<” ,”;
else
{
for (i = l; i <= r; i++)
{
swap((a+l), (a+i));
func(a, l+1, r);
swap((a+l), (a+i));
}
}
}
int main()
{
char str[] = "AB";
int n = strlen(str);
func(str, 0, n-1);
return 0;
}
a) O(n2)
b) O(n * n!)
c) O(n!)
d) O(n log n)
What will be the time complexity of the given code?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
What will be the time complexity of the given code?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!