Sorting – Set 3

Sorting Set 1  Sorting Set 2 [Merge Sort] Sort array after converting elements to their squares Given a array of both positive and negative integers ‘arr[]’ which are sorted. Task is to sort square of the numbers of the Array. GFG Algo: 1. Since half of the array is positive and negative, when we square each… Continue reading Sorting – Set 3


Sorting – Set 2

Sorting Set 1  Sorting Set 3  We have algo for finding the largest and second largest and all. Like we can sort the array and take the last element O(nlog(n)). Or use quick select on unsorted array, but that has worst case O(n^2) complexity. So before such answer consider the situation that simple cases like largest… Continue reading Sorting – Set 2

Sorting Set – 0

Big O CheatSheet  *** - used in questions like this - - Problem set on sorting [Done] Selection Sort - Graphic - Code Algo: The idea is to move the smallest element to the front of the array in each iteration. We find the smallest element in the array and place it at the correct position… Continue reading Sorting Set – 0