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 34

The output of: int arr[]={1,2,3,4,5}; int*p=arr+2; cout<<*(p-1)<<*p<<*(p+1);
234
click to copy
The output of: string s="Hello World"; istringstream iss(s); string word; vector<string> words; while(iss>>word)words.push_back(word); cout<<words.size()<<words[0];
2Hello
click to copy
C++ is best described as which type of programming language?
Compiled, statically-typed, multi-paradigm language supporting OOP, generic, and procedural programming
click to copy
Ford-Fulkerson algorithm solves:
Maximum flow in a network
click to copy
Longest Increasing Subsequence (LIS) of {3,10,2,1,20} has length:
3
click to copy
Matrix Chain Multiplication uses which technique?
Dynamic Programming
click to copy
Edit distance (Levenshtein distance) between "kitten" and "sitting" is:
3
click to copy
Coin change problem (minimum coins) uses:
Dynamic Programming for general case
click to copy
KMP (Knuth-Morris-Pratt) algorithm efficiently solves:
String pattern matching in O(n+m)
click to copy
The failure function in KMP is used to:
Skip unnecessary comparisons by tracking longest proper prefix-suffix
click to copy
Rabin-Karp algorithm uses:
Rolling hash for efficient multi-pattern search
click to copy
Boyer-Moore algorithm searches string from:
Right to left (more efficient skips)
click to copy
Aho-Corasick algorithm enables:
Multiple pattern search simultaneously in O(n+m+z)
click to copy
Z-algorithm computes for each position:
Length of longest substring starting from position that is also a prefix
click to copy
Manacher algorithm finds:
Longest palindromic substring in O(n)
click to copy
Two-pointer technique is used for:
Efficiently solving array/string problems with two indices moving toward each other
click to copy
Sliding window technique is used for:
Finding optimal subarray/substring of fixed or variable size
click to copy
Kadane algorithm maintains:
Current subarray sum and global maximum
click to copy
The stock buy-sell problem (one transaction) is solved in:
O(n) by tracking minimum price seen so far
click to copy
Finding majority element (appearing > n/2 times) is solved by:
Boyer-Moore Voting Algorithm in O(n)
click to copy
Reservoir sampling is used for:
Randomly selecting k items from stream of unknown size in O(n)
click to copy
The output of: int x=5; cout<<((x%2)==0?"Even":"Odd");
Odd
click to copy
The output of: int n=100; int sum=n*(n+1)/2; cout<<sum;
5050
click to copy
The output of: int a=10,b=5; a=a^b; b=a^b; a=a^b; cout<<a<<" "<<b;
5 10
click to copy
The output of: for(int i=1;i<=5;i++) cout<<i*(i+1)/2<<" ";
1 3 6 10 15
click to copy
The output of: int n=16; while(n>1){n/=2; cout<<n<<" ";}
8 4 2 1
click to copy
The output of: int x=255; cout<<(x & 0x0F);
15
click to copy
The output of: int x=170; cout<<(x & 0xFF)<<" "<<(x>>4);
170 10
click to copy
The output of: int n=7; cout<<__builtin_popcount(n);
3
click to copy
The output of: cout<<__builtin_clz(8); on 32-bit int?
28
click to copy
The output of: int x=12; cout<<(x&(x-1));
8
click to copy
n & (n-1) equals 0 iff n is:
Power of 2 (or n=0)
click to copy
What is the output: cout<<(0b1010 | 0b1100);
14
click to copy
What is the output: cout<<(0b1010 & 0b1100);
8
click to copy

Data Structures and Algorithms → Graphs 1

Kruskal algorithm finds MST by:
Sorting all edges and adding non-cycle-forming edges
click to copy

Data Structures and Algorithms → Dynamic Programming 2

Which problem is solved by dynamic programming with O(nW) complexity?
0/1 Knapsack problem
click to copy
Longest Common Subsequence (LCS) of "ABCBDAB" and "BDCABA" has length:
4
click to copy

Data Structures and Algorithms → Arrays 3

Suffix array is used for:
Efficient string operations (search, LCP) by storing sorted suffixes
click to copy
The maximum subarray sum problem is solved by:
Kadane algorithm in O(n)
click to copy
Dutch National Flag problem sorts array of 0s, 1s, 2s in:
O(n) using three-way partitioning
click to copy