Merge Sort

Merge Sort is a Divide and Conquer algorithm. It divides input array in two halves, calls itself for the two halves and then merges the two sorted halves. The merge() function is used for merging two halves. The merge(arr, l, m, r) is key process that assumes that arr[l..m] and arr[m+1..r] are sorted and merges … Continue reading Merge 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

Fibonacci Search

Fibonacci Search is a comparison-based technique that uses Fibonacci numbers to search an element in a sorted array. Similarities with Binary Search: Works for sorted arrays A Divide and Conquer Algorithm. Has Log n time complexity. Differences with Binary Search: Fibonacci Search divides given array in unequal partsBinary Search uses division operator to divide range. … Continue reading Fibonacci Search

Sublist Search-(Search a linked list in another list)

Sublist search is used to detect a presence of one list in another list. Suppose we have a single-node list (let's say the first list), and we want to ensure that the list is present in another list (let's say the second list), then we can perform the sublist search to find it. For instance, … Continue reading Sublist Search-(Search a linked list in another list)