0% found this document useful (0 votes)
6 views

SORTING ALGORITHMS TRICKS gate cse

Sweta Kumari, a founder at GATE NOTEBOOK, has over 6 years of teaching experience and has mentored over 81,000 students, helping many secure top ranks in GATE and gain admission to prestigious institutions. The document promotes a revision book for GATE CS IT, offers a discount code for new subscribers, and discusses various sorting algorithms along with their complexities. It also includes a variety of questions and answers related to sorting algorithms and graph theory.

Uploaded by

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

SORTING ALGORITHMS TRICKS gate cse

Sweta Kumari, a founder at GATE NOTEBOOK, has over 6 years of teaching experience and has mentored over 81,000 students, helping many secure top ranks in GATE and gain admission to prestigious institutions. The document promotes a revision book for GATE CS IT, offers a discount code for new subscribers, and discusses various sorting algorithms along with their complexities. It also includes a variety of questions and answers related to sorting algorithms and graph theory.

Uploaded by

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

ABOUT ME

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.

Expertise in : TOC, Computer


Networks , Operating
systems , DBMS, Compilers ,
Code : HELLOSONU01
LAST DATE TO
ENROLL : 9TH DEC

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

Only With ICONIC


SUBSCRIPTION
HELLOSONU01
Code : HELLOSONU01
Sorting Algorithms
A Sorting Algorithm is used to rearrange a
given array or list elements according to a
comparison operator on the elements. The
comparison operator is used to decide the new
order of element in the respective data
structure.
Sorting Algorithms
A Sorting Algorithm is used to rearrange a
given array or list elements according to a
comparison operator on the elements. The
comparison operator is used to decide the new
order of element in the respective data
structure.
Sorting Algorithms
A Sorting Algorithm is used to rearrange a
given array or list elements according to a
comparison operator on the elements. The
comparison operator is used to decide the new
order of element in the respective data
structure.
Sorting Algorithms
A Sorting Algorithm is used to rearrange a
given array or list elements according to a
comparison operator on the elements. The
comparison operator is used to decide the new
order of element in the respective data
structure.
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 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

Selection sort repeatedly selects the minimum


------------- algorithm is one that can process its input element from the unsorted remainder and places it
piece-by-piece in a serial fashion, i.e., in the order that at the front, which requires --------------
the input is fed to the algorithm, without having the 1. Access to only 1 input
entire input available from the start. 2. Access to entire input
1. Online Algorithm 3. Access to only 2 inputs 5QS
2. Offline Algorithm 4. None
3. On algorithm
4. Comparison sort
If the ratio between the performance of an online
algorithm and an optimal offline algorithm is
bounded, the online algorithm is called …………..
1. Stable sort 2. In place sort 3. comparison sort
4. Competitive sort
------------ 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

Selection sort repeatedly selects the minimum


------------- algorithm is one that can process its input element from the unsorted remainder and places it
piece-by-piece in a serial fashion, i.e., in the order that at the front, which requires --------------
the input is fed to the algorithm, without having the 1. Access to only 1 input
entire input available from the start. 2. Access to entire input
1. Online Algorithm 3. Access to only 2 inputs
2. Offline Algorithm 4. None
3. On algorithm
4. Comparison sort
If the ratio between the performance of an online
algorithm and an optimal offline algorithm is
bounded, the online algorithm is called …………..
1. Stable sort 2. In place sort 3. comparison sort
4. Competitive sort
Sorting Description
Algorithms
Bubble Sort Repeatedly moving the largest element to the highest index of the array. It comprises of comparing each
element to its adjacent element and replace them accordingly.
Heap Sort In the heap sort, Min heap or max heap is maintained from the array elements deending upon the choice
and the elements are sorted by deleting the root element of the heap.
Insertion As the name suggests, insertion sort inserts each element of the array to its proper place. It is a very simple
Sort sort method which is used to arrange the deck of cards while playing bridge.
Merge Sort Merge sort follows divide and conquer approach in which, the list is first divided into the sets of equal
elements and then each half of the list is sorted by using merge sort. The sorted list is combined again to
form an elementary sorted array.
Quick Sort Quick sort is the most optimized sort algorithms which performs sorting in O(n log n) comparisons. Like
Merge sort, quick sort also work by using divide and conquer approach.
Radix Sort In Radix sort, the sorting is done as we do sort the names according to their alphabetical order.
Selection Selection sort finds the smallest element in the array and place it on the first place on the list, then it finds
Sort the second smallest element in the array and place it on the second place. This process continues until all
the elements are moved to their correct ordering. It carries running time O(n2) which is worst than
insertion sort.
Shell Sort Shell sort is the generalization of insertion sort which overcomes the drawbacks of insertion sort by
comparing elements separated by a gap of several positions.
Sort Average Best Worst
Bubble sort
Modified Bubble
O(n^2)
O(n^2)
O(n^2)
O(n)
O(n^2)
O(n^2)
39 SHORT
sort

Selection Sort O(n^2) O(n^2) O(n^2) TRICKS


Insertion Sort O(n^2) O(n) O(n^2)

Heap Sort O(n*log(n)) O(n*log(n)) O(n*log(n))

Merge Sort O(n*log(n)) O(n*log(n)) O(n*log(n))

Quicksort O(n*log(n)) O(n*log(n)) O(n^2)

Bucket Sort O(n+k) O(n+k) O(n^2)

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)

When array is already sorted , then what is


time complexity using bubble sort ?
1. O(1)
2. O(n)
3. O(n^2)
4. O(log n)
…………..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
2. Worst case What is time complexity of modified bubble
3. Average case sort in Best Case ?
4. Both 1 & 3 1. O(1)
2. O(n) 3. O(n^2) 4. O(log n)
When array is already sorted , then what is
time complexity using bubble sort ?
1. O(1)
2. O(n)
3. O(n^2)
4. O(log n)
--------------Is A Simple Sorting Algorithm That Works Which algorithm has time complexity :
The Way We Sort Playing Cards In Our Hands. Best case : O(n) , Worst Case : O (n^2) and average
1. Bubble Sort 2. Insertion Sort case : O(n^2)
2. 3. Selection Sort 4. Quick Sort 1. Modified Bubble sort 2. Merge sort
3. Insertion sort 4. Both 1 & 3

-------------------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

------------- algorithm sorts an array by repeatedly


Which sorting uses Divide & Conquer ? finding the minimum element from unsorted part
1. Quick Sort 2. Merge sort 3. Heap sort and putting it at the beginning.
4. 1 & 2 1. Selection sort 2. Heap sort
3. Merge sort 4. Quick sort

7 QS The good thing about ------------ is it never makes


more than O(n) swaps and can be useful when
memory write is a costly operation.
1. Selection sort 2. Heap sort
3. Merge sort 4. Quick sort
--------------Is A Simple Sorting Algorithm That Works Which algorithm has time complexity :
The Way We Sort Playing Cards In Our Hands. Best case : O(n) , Worst Case : O (n^2) and average
1. Bubble Sort 2. Insertion Sort case : O(n^2)
2. 3. Selection Sort 4. Quick Sort 1. Modified Bubble sort 2. Merge sort
3. Insertion sort 4. Both 1 & 3

-------------------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

------------- algorithm sorts an array by repeatedly


finding the minimum element from unsorted part
Which sorting uses Divide & Conquer ? and putting it at the beginning.
1. Quick Sort 2. Merge sort 3. Heap sort 1. Selection sort 2. Heap sort
4. 1 & 2 3. Merge sort 4. Quick sort

The good thing about ------------ is it never makes


more than O(n) swaps and can be useful when
memory write is a costly operation.
1. Selection sort 2. Heap sort
3. Merge sort 4. Quick sort
-----------------the sorting is done as we do sort the names -----------------------Efficient on small data, due to low
according to their alphabetical order. overhead, but not efficient on large data.
1. Counting sort 1. Insertion sort
2. Radix sort 2. Selection sort
3. Heap sort 3. Both
4. Tim sort 4. None

-----------------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)

1. O(n) 2. O(nlogn) 3. O(log n) 4. O(n^2)


-----------------the sorting is done as we do sort the names -----------------------Efficient on small data, due to low
according to their alphabetical order. overhead, but not efficient on large data.
1. Counting sort 1. Insertion sort
2. Radix sort 2. Selection sort
3. Heap sort 3. Both
4. Tim sort 4. None

-----------------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

What is the worst case of Randomized quick sort ?

1. O(n) 2. O(nlogn) 3. O(log n) 4. O(n^2)

You might also like