Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
15 views2 pages

GSWCP Week - 2

The document contains a quiz with questions related to algorithms and data structures, including complexity analysis and array manipulation. It also includes two code snippets in C++ that demonstrate searching for an element in an array and finding a critical value in a sorted array. The quiz and code examples focus on understanding algorithm efficiency and array operations.

Uploaded by

ilakkiyanj01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

GSWCP Week - 2

The document contains a quiz with questions related to algorithms and data structures, including complexity analysis and array manipulation. It also includes two code snippets in C++ that demonstrate searching for an element in an array and finding a critical value in a sorted array. The quiz and code examples focus on understanding algorithm efficiency and array operations.

Uploaded by

ilakkiyanj01
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

QUIZ:

1) 12
2) [9, 7, 6, 5, 4, 3, 2, 1] , [5, 2, 1, 7, 3, 4, 8, 6]
3) Yes
4) 7
5) List L sorted in descending order
6) O(n2)
7) O(logN)
8) I.O(logn), II.O(1)
9) O(nloglogn)
10) (a) If p < x > q , then x is the maximum in the array,
(c) If p < x < q , then the maximum element is in the right half of the array.

PQ1:
#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin >> t;

while (t--) {
int n;
long long x;
cin >> n >> x;

vector<long long> arr(n);


for (int i = 0; i < n; i++) {
cin >> arr[i];
}

int idx = -1;


for (int i = 0; i < n; i++) {
if (arr[i] == x) {
idx = i;
break;
}
}

cout << idx << endl;


}

return 0;
}

PQ2:

#include <bits/stdc++.h>
using namespace std;

int main() {
long long t;
cin >> t;

while (t--) {
long long n;
cin >> n;
vector<long long> arr(n);
for (int x = 0; x < n; x++) {
cin >> arr[x];
}

sort(arr.rbegin(), arr.rend());

int critical_x = -1;


for (int x = 1; x <= n; x++) {
if (arr[x - 1] >= x && (x == n || arr[x] < x)) {
critical_x = x;
break;
}
}

cout << critical_x ;

if(t!=0)cout<<endl;
}

return 0;
}

You might also like