Vidyalelo
Data Structure · Q101

Arrays in Data Structures

Programming · Data Structure · question 101

Q101

What will be the time complexity of the following code? #include using namespace std; void func(int a[], int n, int k) if (k <= n) for (int i = 0; i < k/2; i++) swap(a[i], a[k-i-1]); int main() int a[] = 1, 2, 3, 4, 5; int n = sizeof(a) / sizeof(int), k = 3; func(a, n, k); for (int i = 0; i < n; ++i) cout << a[i]<<" "; return 0;

A.
O(k)
Answer
B.
O(n)
C.
O(k log k)
D.
O(n log n)

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board