Unsorted Arrays vs Binary Search
1. How do you describe an array?
2. What is the time complexity of traversing through all the elements in an array?
3. Let us consider the following code:
int a = 0, b[N];
for (i = 0; i < M; i++) {
a+=i;
}
for (i = 0; i < N; i++) {
scanf(\“%d\”, &b[i]);
a+=b[i];
}
What is the space and time complexity of the above code?
4. Let us consider following four arrays:
A = [9, 5, 11, 25, 7, 35]
B = [1, 2, 9, 15, 27]
C = [29, 27, 27, 18, 4, 2]
D = [1, 8, 2, 5, 6, 7, 8, 9]
Which of the arrays are sorted?
A = [9, 5, 11, 25, 7, 35]
B = [1, 2, 9, 15, 27]
C = [29, 27, 27, 18, 4, 2]
D = [1, 8, 2, 5, 6, 7, 8, 9]
Which of the arrays are sorted?
5. If for large inputs, X is a better choice than Y, then: