searching

Blog Cover Image
AVL Tree (Self-Balancing Binary Search Tree)

AVL Trees named after its inventors Adelson-Velsky and Landis, is a unique variation of the Binary Search Tree, which is a self-balancing BST. The property of AVL Trees is that they automatically attain the tree's minimum possible height after executing any operation.

Blog Cover Image
Introduction to Trie Data Structure

Trie is a famous data structure used to store and process data, especially strings. It is a tree where each node represents a prefix or end of a word (the path traced from the root to that node). The word trie comes from retrieval as a trie can retrieve all the words with a given prefix.

Blog Cover Image
Hash Functions in Data Structures and Algorithms

We use hash functions to uniformly distributes keys in the hash table. In other words, a good hash function satisfies the assumption of uniform hashing, where each key is equally likely to hash to any slots in the hash table. This blog has discussed the design and properties of some popular hash functions used in programming and data structures.

Blog Cover Image
Hashing and Hash Table in Data Structures and Algorithms

Hashing is a technique to map (key, value) pairs into the hash table using a hash function. It uses an array of size proportional to the number of keys and calculates an array index from the key using a hash function. Explore this blog to learn how hash tables work in programming?

Blog Cover Image
Maximum difference in an array

Given an array A[] of integers, find out the maximum difference between any two elements such that the larger element appears after the smaller element. In other words, we need to find max(A[j] - A[i]), where A[j] > A[i] and j > i. This is an excellent problem to learn problem-solving using divide and conquer, transform and conquer and a single loop.

Blog Cover Image
Binary Search Algorithm

The binary search is one of the fastest searching algorithms, which search a value in the sorted array in an O(logn) time complexity. Here we search a value using divide and conquer by repeatedly dividing the search interval in half. Problem statement: Given a sorted array X[] of n elements, search a given element key in X[]. If the key exists, then return its index in the sorted array. Otherwise, return -1.

Blog Cover Image
A* search algorithm

The A-star algorithm is a searching algorithm used to find the shortest path between an initial and a final point. The algorithm is optimal and complete as it searches for shorter paths first. An optimal algorithm finds the least-cost outcome for a problem, while a complete algorithm finds all the possible outcomes.

Blog Cover Image
kth smallest element in an array

Given an array and a positive integer k, write a program to find the kth smallest element in the array. This is an excellent problem to learn problem-solving using the heap data structure. The quick-select approach (divide and conquer) is also worth exploring that helps optimize time complexity to O(n) time average.

Blog Cover Image
Intersection of Two Unsorted Arrays

Given two integer arrays, X[] and Y[] of size m and n. Write a program to find the intersection of these two arrays. The intersection of two arrays is a list of distinct elements present in both arrays. The elements in the intersection can be in any order. Suppose m > n and elements in both arrays are distinct.

Blog Cover Image
Check if two arrays are equal or not

Given two integer arrays X[] and Y[], write a program to check if the arrays are equal or not. Two arrays are equal if they have the same elements in any order. If there are repeated elements, then counts of repeated elements must also be the same for both arrays.

Blog Cover Image
Find row with maximum number of 1s

Given a boolean 2D array, where each row is sorted. Find the row with the maximum number of 1s. This is an excellent matrix problem that can be solved in linear time complexity. The best part is — we are using the sorted order property and nested loops to improve the solution over the binary search approach.

Blog Cover Image
Find the maximum in an array which is first increasing and then decreasing

You are given an array of integers that is initially increasing and then decreasing, find the maximum value in the array.

Blog Cover Image
Find first and last positions of an element in a sorted array

Given an array of integers sorted in ascending order, find the first and last position of a given value. This is a good interview problem to learn problem-solving using binary search.

Blog Cover Image
Search in a row-wise sorted 2D matrix

You are given a row-wise sorted 2D matrix and a given integer k, write a program to find whether the integer ‘k’ is present in the matrix or not. The matrix has the following properties: Integers in each row are sorted from left to right and the first integer of each row is greater than the last integer of the previous row.

Blog Cover Image
Check for pair in an array with a given sum

Given an array of n integers and a target number, write a program to check whether a pair sum exits in the array or not. In other words, we need to check whether pair of elements in the array sum exactly to the target value.

Blog Cover Image
n Repeated element in 2n size array

In an array of size 2n, there are n+1 unique elements, and exactly one of these elements is repeated n times. Return the element repeated n times.

Blog Cover Image
Find the minimum and maximum value in an array

Given an array X[] of size n, we need to find the maximum and minimum element present in the array. This coding problem has been asked during facebook and microsoft interview.

Blog Cover Image
Equilibrium Index of an Array

Write a program to find the equilibrium index of an array. An array's equilibrium index is an index such that the sum of elements at lower indexes equals the sum of elements at higher indexes. This is an excellent coding question to learn time and space complexity optimization using several approaches.

Our weekly newsletter

Subscribe to get free weekly content on data structure and algorithms, machine learning, system design, oops design and mathematics.