Quick Sort

QuickSort is a Divide and Conquer algorithm. It picks an element as pivot and partitions the given array around the picked pivot. There are many different versions of quickSort that pick pivot in different ways. Always pick first element as pivot.Always pick last element as pivot (implemented below)Pick a random element as pivot.Pick median as pivot. … Continue reading Quick Sort

Google Coding Problem- #001

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same element twice.Example:Given nums = [2, 7, 11, 15], target = 9,Because nums[0] + nums[1] = 2 + 7 … Continue reading Google Coding Problem- #001

Kadane’s algorithm – (Largest Sum Contiguous Sub-array)

Kadane’s algorithm is to look for all positive contiguous segments of the array (max_ending_here is used for this). And keep track of maximum sum contiguous segment among all positive segments (max_so_far is used for this). Each time we get a positive sum compare it with max_so_far and update max_so_far if it is greater than max_so_far … Continue reading Kadane’s algorithm – (Largest Sum Contiguous Sub-array)

Lambda- Anonymous Functions

Anonymous function means that a function is without a name. As we already know that def keyword is used to define the normal functions and the lambda keyword is used to create anonymous functions. It has the following syntax: lambda arguments: expression This function can have any number of arguments but only one expression, which is evaluated and returned.One … Continue reading Lambda- Anonymous Functions

Sorting Algorithm

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. Selection Sort The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering ascending … Continue reading Sorting Algorithm