#include <bits/stdc++.h>
using namespace std;
void convert(int arr[], int n)
{
int temp[n];
memcpy(temp, arr, n*sizeof(int));
sort(temp, temp + n);
unordered_map<int, int> map;
int sort_index = 0;
for (int i = 0; i < n; i++)
map[temp] = sort_index++;
for (int i = 0; i < n; i++)
arr = map[arr];
}
void printArr(int arr[], int n)
{
for (int i=0; i<n; i++)
cout << arr << " ";
}
int main()
{
int arr[] = {10, 20, 15, 12, 11, 50};
int n = sizeof(arr)/sizeof(arr[0]);
convert(arr , n);
printArr(arr, n);
return 0;
}
a) O(n)
b) O(1)
c) O(n log n)
d) O(n2)
What is the time complexity of the following code?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
What is the time complexity of the following code?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!