SORTING ALGORITHMS TRICKS gate cse
SORTING ALGORITHMS TRICKS gate cse
FOUNDER AT GATE
NOTEBOOK
Mentored 81,000+ Students |
My Multiple Students secured
AIR Below 100 in GATE |
Joined top IISc, IITs & NITs |
Joined PSUs |
Sweta Kumari
6 Years Teaching Exp.
Code : HELLOSONU01
DISCOUNT CODE :
HELLOSONU01
DISCOUNT CODE :
HELLOSONU01
BEST REVISION Book For GATE CS IT
(Covers all the Important Concepts , All the Important PYQs , Important Formulae , Short Tricks
From All the Units of Computer science subjects + General Aptitude)
FOR NEW SUBSCRIBERS
Free with
Unacademy
Subscription using
referral code
HELLOSONU01
(ALSO DISCOUNT
Code)
HAMILTONINAN CIRCUIT (n>=3) = Passes through every vertex
Check Planarity of graph Bipartite graph = No odd
1. e, v where v >= 3 DIRAC’S THEOREM = Degree of every vertex should be at least n/2 GRAPH
length cycle
Circuits of length 3 THEORY
ORE’S THEOREM = deg(u) + deg(v) >= n (non adjacent)
Revise in 1
E <= 3v-6 E(G’) + E(G) = Complete graph
NOTE – Degree of 1 vertex means not Hamiltonian circuit Page
2. e, v where v >= 3 E(G’) = n(n-1)/2 - E(G)
No Circuits of length 3
E <= 2v-4 strongly connected components = edge EULER GRAPH = Passes through every edge
between every pair of vertex VERTICES OF EVEN DEGREE =
Single Revision Page (SRP) EULER CIRCUIT
Maximum number of edges in a
Handshaking thm :
Sum of degree of vertices = 2 x edges
PYQs connected planar, simple graph = 3n-6 EXACTLY 2 VERTICES OF ODD DEGREE =
EULER PATH BUT NOT CIRCUIT
Four Color thm : 4 colors are sufficient to color planar 90 Minutes Lecture Converted in 1 Page
graph Kn,n => K3,3
Kn+1,n => K8,9 Isomorphic Graphs = Count nodes , count edges ,
Always Hamiltonian circuit.
Self Complementary graph – Isomorphic to its Check degree of each vertex , check length of cycle
complement (in both graphs)
DISCRETE MATHEMATICS
= Half no. of edges in complete graph = n(n-1)/4 (must
be disable by 4 or 0) Maximum number of edges in undirected
A connected graph ‘G’ may have graph
C5 cycle is the only graph which is self complementary
at most (n–2) cut vertices. = n(n-1)/2
Euler’s formula : R = E – V + 2 (Always 1 region is
the maximum number of cut No. of graphs can be constructed = 2 n(n-1)/2
bounded)
edges possible is ‘n-1’.
Undirected Graph :
If all weights distinct in MST ,
Number of odd degree vertices is even.
1. Always contain emin
Sum of degree of all vertices is even. Maximum number of edges in Complete 2. Unique MST
bipartite graph = n2/4 3. Emax present in MST
Max. edges in connected graph which doesn’t form cycle
= (n-1) Circuit Rank = m-(n-1)
5000+ FROM WHERE YOU
PRACTICE
QUESTIONS
SHOULD PRACTICE ?
CS IT WORKBOOK
TEST SERIES : 350 ASK A DOUBT
12 GATE CS IT BOOKS That will be delivered to your home
The algorithm that change the sequence of Which is not stable algorithm ?
elements after sorting is? 1. Bubble sort 2. Insertion sort 10QS
1. Stable Sort 2. Online algorithm 3. Merge sort 4. Heap sort
3. Unstable sort 4. Offline algorithm
Which is in –place algorithm ?
which algorithm take already sorted elements into 1. Bubble sort 2. Insertion sort
account and not reorder them? 3. Merge sort 4. Selection
1. Non adaptive 2. Adaptive algorithm
3. Unstable sort 4. Offline algorithm
The algorithm that do not require extra space is ? which algorithm do not take already sorted
1. Stable Sort 2. In place sort elements into account and reorder them?
3. Not in place sort 4. Online algorithm 1. Non adaptive 2. Adaptive algorithm
3. Unstable sort 4. Offline algorithm
The algorithm that require extra space is ?
1. Stable Sort 2. In place sort Which is not adaptive algorithm ?
3. Not in place sort 4. Online algorithm 1. Bubble sort 2. Insertion sort
3. Merge sort 4. Quick sort
The algorithm that do not change the sequence of
elements after sorting is? Which is not Non- adaptive algorithm ?
1. Stable Sort 2. Online algorithm 1. Bubble sort 2. Selection sort
3. Unstable sort 4. Offline algorithm 3. Merge sort 4. Heap sort
The algorithm that change the sequence of Which is not stable algorithm ?
elements after sorting is? 1. Bubble sort 2. Insertion sort
1. Stable Sort 2. Online algorithm 3. Merge sort 4. Heap sort
3. Unstable sort 4. Offline algorithm
Which is in –place algorithm ?
which algorithm take already sorted elements into 1. Bubble sort 2. Insertion sort
account and not reorder them? 3. Merge sort 4. Selection
1. Non adaptive 2. Adaptive algorithm
3. Unstable sort 4. Offline algorithm
------------ algorithm is given the whole problem data from Which is the correct sequence of online and offline
the beginning and is required to output an answer which algorithm ?
solves the problem at hand. 1. Insertion sort , Insertion sort
1. Online Algorithm 2. Selection Sort , Selection sort
2. Offline Algorithm 3. Insertion sort , Selection sort
3. On algorithm 4. Selection sort , Insertion sort
4. Comparison sort
Radix Sort
Tim Sort
Shell Sort
Counting Sort
Randomized
O(nk)
O(n)
O(n)
O(n+k)
O(nlogn)
O(nk)
O(nlogn)
O((nlogn)^2)
O(n+k)
O(nlogn)
O(n+k)
O(nlogn)
O((nlogn)^2)
O(n+k)
O(nlogn)
13SORTING
Quick Sort
ALGORITHMS
…………..is the simplest sorting algorithm that Why modified Bubble sort is necessary ?
works by repeatedly swapping the adjacent 1. To minimize Time complexity
elements if they are in wrong order. 2. To minimize no. of passes
1. Insertion sort 3. Both 1 & 2
2. Radix sort 4. None
3. Heap sort
4. Bubble sort
what is time complexity of bubble sort ?
Array given in descending order and you have 1. O(1)
to sort in ascending order then it falls under 2. O(n) 3. O(n^2) 4. O(log n)
which case ?
1. Best Case What is time complexity of modified bubble
2. Worst case sort in Best Case ?
3. Average case 1. O(1) 6 QS
4. Both 1 & 3 2. O(n) 3. O(n^2) 4. O(log n)
-------------------useful when input array is almost Which algorithm has time complexity :
sorted, only few elements are misplaced in Best case : O(n^2) , Worst Case : O (n^2) and
complete big array. average case : O(n^2)
1. Bubble sort 2. Merge sort 1. Bubble sort 2. Selection sort
3. Insertion sort 4. Quick sort 3. Insertion sort 4. Both 1 & 2
-------------------useful when input array is almost Which algorithm has time complexity :
sorted, only few elements are misplaced in Best case : O(n^2) , Worst Case : O (n^2) and
complete big array. average case : O(n^2)
1. Bubble sort 2. Merge sort 1. Bubble sort 2. Selection sort
3. Insertion sort 4. Quick sort 3. Insertion sort 4. Both 1 & 2
-----------------examines the data only by comparing two What is the worst case of quick sort ?
elements with a comparison operator. 1. O(n) 2. O(n log n)
1. Counting sort 3. O(n^2) 4 . None
2. Comparison sort
3. Heap sort
4. Tim sort
7 QS
A comparison sort cannot perform better than
1. O(n) 2. O(n log n) What is the best case, average case and worst case
3. O(log n) 4 . None complexity of Heap and merge sort ?
What is the worst case of Randomized quick sort ? 1. O(n) 2. O(nlogn) 3. O(log n) 4. O(n^2)
-----------------examines the data only by comparing two What is the worst case of quick sort ?
elements with a comparison operator. 1. O(n) 2. O(n log n)
1. Counting sort 3. O(n^2) 4 . None
2. Comparison sort
3. Heap sort
4. Tim sort What is the best case, average case and worst case
complexity of Heap and merge sort ?
A comparison sort cannot perform better than
1. O(n) 2. O(n log n) 1. O(n) 2. O(nlogn) 3. O(log n) 4. O(n^2)
3. O(log n) 4 . None