Quick Revision

GK One-Line Question & Answer

15541+ short questions with short answers, covering every category and sub-category on the site — no long articles to scroll through. Good for a fast recap before an exam, or a few minutes of daily practice.

Data Structures and Algorithms → Introduction to DSA 32

The output of: int a=INT_MIN; cout<<(a<0?"negative":"positive");
negative
click to copy
What is the output: cout<<numeric_limits<int>::max();
All correct
click to copy
The output of: double x=1.0/3.0; cout<<fixed<<setprecision(15)<<x;
0.333333333333333
click to copy
What is epsilon comparison for floating point?
abs(a-b)<epsilon (for small epsilon)
click to copy
The output of: cout<<(0.1+0.2==0.3);
0
click to copy
Which is the output: double a=0.1+0.2; cout<<fixed<<setprecision(20)<<a;
0.30000000000000004440
click to copy
The output of: int n=5; string s(n,*); cout<<s;
*****
click to copy
The output of: string s="Hello"; s.insert(5," World"); cout<<s;
Hello World
click to copy
The output of: string s="Hello World"; s.replace(6,5,"C++"); cout<<s;
Hello C++
click to copy
What does string::npos equal?
-1 as size_t (maximum size_t value)
click to copy
The output of: string s="hello"; for(auto &c:s) c=toupper(c); cout<<s;
HELLO
click to copy
The output of: string s="12345"; int n=stoi(s); cout<<n*2;
24690
click to copy
The output of: int n=42; string s=to_string(n); cout<<s.length();
2
click to copy
The output of: vector<string> v={"Hello","World"}; string result=accumulate(v.begin(),v.end(),string("")); cout<<result;
HelloWorld
click to copy
The output of: auto f=function<int(int)>([](int n){return n*n;}); cout<<f(7);
49
click to copy
The output of: map<string,int> freq; string words[]={"a","b","a","c","b","a"}; for(auto w:words)freq[w]++; cout<<freq["a"]<<freq["b"]<<freq["c"];
321
click to copy
The output of: vector<pair<int,int>> v={{3,1},{1,3},{2,2}}; sort(v.begin(),v.end()); cout<<v[0].first<<v[0].second;
13
click to copy
The output of: priority_queue<pair<int,int>> pq; pq.push({1,2}); pq.push({3,1}); pq.push({2,3}); cout<<pq.top().first;
3
click to copy
The output of: auto it=find(begin({5,3,8,1,9}),end({5,3,8,1,9}),8); cout<<*it;
8
click to copy
What is the time complexity of std::sort?
O(n log n) average
click to copy
What is the space complexity of quicksort (average)?
O(log n) recursion stack
click to copy
Which sort is best for nearly sorted arrays?
Insertion Sort
click to copy
Counting sort is not a comparison sort and runs in:
O(n + k) where k is range of values
click to copy
Bucket sort is efficient when input is:
Uniformly distributed in a known range
click to copy
Tim sort (used in Python and Java) combines:
Insertion sort for small runs + merge sort
click to copy
The output of: int arr[]={5,2,8,1,9}; int n=5; for(int i=0;i<n-1;i++) for(int j=0;j<n-i-1;j++) if(arr[j]>arr[j+1]) swap(arr[j],arr[j+1]); cout<<arr[0];
1
click to copy
What is the maximum comparisons in binary search for n=1024 elements?
11
click to copy
Interpolation search works best when:
Data is uniformly distributed (better than binary search)
click to copy
Exponential search is useful when:
Array is sorted and size is unknown (infinite/very large)
click to copy
Jump search works by:
Jumping ahead by sqrt(n) steps then linear search back
click to copy
The output of: int a[]={1,1,2,2,3}; cout<<distance(a,unique(a,a+5));
3
click to copy
What is Big Theta of the best sort algorithm for general data?
O(n log n)
click to copy

Data Structures and Algorithms → Sorting Algorithms 5

What is the space complexity of merge sort?
O(n)
click to copy
What is the space complexity of heap sort?
O(1) in-place
click to copy
Radix sort time complexity for n numbers with d digits:
O(d*n)
click to copy
Shell sort is a generalization of:
Insertion sort (with gap sequences)
click to copy
The output of: int arr[]={64,34,25,12,22,11,90}; // selection sort: for(int i=0;i<6;i++){int m=i; for(int j=i+1;j<7;j++) if(arr[j]<arr[m]) m=j; swap(arr[i],arr[m]);} cout<<arr[0];
11
click to copy

Data Structures and Algorithms → Linked List 1

Which sort is best for linked lists?
Merge Sort
click to copy

Data Structures and Algorithms → Arrays 2

Binary search on sorted array {1,3,5,7,9,11,13}: how many comparisons to find 7?
3
click to copy
Ternary search divides array into:
Three parts (finds max/min of unimodal function)
click to copy