Pair With Given Sum in Unsorted Array

In this question, we have to find the pair with given sum in unsorted array. We have been given an unsorted array along with a number say k. You’ll have to look if there is a pair in the given array whose sum is equal to k. Brute Force Approach to Find Pair With Given …

Read morePair With Given Sum in Unsorted Array

Two Pointer Approach: An Efficient Technique

In this article we will discuss a linear and constant space technique to solve the programming questions. Two pointer Approach is an efficient technique to solve the problem with optimized time and space complexity. Two Pointer Approach Algorithm is mostly used for solving the array problems, where pointers are actually array indexes. Whenever the solution …

Read moreTwo Pointer Approach: An Efficient Technique

Insertion Sort – A Stable Sorting Algorithm

Have you ever played card? If yes, then you’ll feel that insertion sort is somewhat similar to arranging cards in your hand. While arranging cards you’ll place the first card in your hand. After picking the second card you’ll compare it with the existing card and place it in the correct order. In the same …

Read moreInsertion Sort – A Stable Sorting Algorithm

QuickSort Algorithm

Here you’ll learn how to write a program for quicksort algorithm understand its theory, and using an example learn how its implemented. Contrary to the name, this isn’t the fastest sorting algorithm out there, this will be clearer once the time complexity of QuickSort is discussed later. But first, let’s start with the algorithm approach. …

Read moreQuickSort Algorithm

Merge Sort Algorithm: An Efficient Sorting Approach

In this article, we will learn about Merge Sort Algorithm.¬†There are many well known sorting algorithms but the cool thing about Merge sort is that it takes O(log n) time complexity even in the worst case. Merge sort is a sorting algorithm based on the Divide and Conquer technique. The approach is to transform the …

Read moreMerge Sort Algorithm: An Efficient Sorting Approach

Bubble Sort – A Stable Algorithm

Bubble sort is one of the simplest sorting algorithms that is based on swapping adjacent elements if they are present in the wrong order. It is a stable algorithm since it preserves the order of the original vector in case of repetition. Bubble Sort C++ Algorithm Implementation Dry Run Input: nums = [5, 2, 10, …

Read moreBubble Sort – A Stable Algorithm

Rotating Elements of a Matrix by 90 Degrees

We’ll understand rotating elements of a matrix by 90 degrees, without using extra space and write the program to implement the same. Directly placing the elements of a matrix row by row in a temporary matrix is a reasonable solution, but the space complexity doubles in that case, when we have large sets of data, …

Read moreRotating Elements of a Matrix by 90 Degrees

Program for Spiral Traversal of a Matrix

We’ll learn to write a program for spiral traversal of a matrix of size m x n, which does mean as it sounds, we’ll start the corner of the matrix and traverse in a spiral towards the center of the matrix. Understanding the question, and output Given: Matrix, SizeOutput: Printing elements in a line using …

Read moreProgram for Spiral Traversal of a Matrix

Median of Two Sorted Arrays | Leetcode Problem #4

In this question, given two sorted arrays nums1 and nums2 of size m and n respectively, you have to return the median of two sorted arrays Goal: The overall run time complexity should be O(log(m+n)) Naive Solution to Find Median of Two Sorted Arrays In this solution, we create a vector and then insert all …

Read moreMedian of Two Sorted Arrays | Leetcode Problem #4