Articles for category: Data Structures and Algorithms

Binary Search Tree (BST)

A binary search tree (BST) is a sorted binary tree, where we can easily search for any key using the binary search algorithm. To sort the BST, it has to have the following properties: The node’s left subtree contains only a key that’s smaller than the node’s key. Takeaways Searching is a trivial part of everyday life. It’s ...

Counting Sort Algorithm

Counting Sort Algorithm is a sorting algorithm that works best when you have a small range of numbers to sort. Instead of comparing elements like in other sorting methods, it counts how many times each number appears and then puts them in order based on that count. This makes it really fast when the range ...

Types of Graph in Data Structure with Examples

A graph can be defined as group of vertices and edges that are used to connect these vertices. In data structure, a graph G=(V,E) is a collection of sets V and E where V and E are the collections of vertices and edges respectively. An edge is a line or arc connecting 2 vertices and it is denoted by a pair (i,j) where i,j belong to a set of vertices V. Let’s see types ...

Insertion Sort Algorithm

Insertion sort is an important method in organizing data, especially good at sorting small groups of information. It works by dividing a list into two parts: one that’s already sorted and one that’s not. Just like when you sort playing cards, it takes each item from the unsorted section and finds the right spot for ...

0-1 BFS

In normal BFS of a graph all edges have equal weight but in 0-1 BFS some edges may have 0 weight and some may have 1 weight. For Example: A vector, d will be defined to store distances between different vertices from source(s). d[s] will be 0 as the distance from source to source is 0. s will be pushed into the front of the deque(q). We’ll visit connected nodes ...

Linear Search Algorithm

Searching is a method to find some relevant information in a data set. In computer programming, searching is usually referred to as finding a particular element in a data structure. Linear search algorithm is a straightforward search algorithm. This type of search performs a sequential search on all items individually. In this article, we will ...

Selection Sort Algorithm

The selection sort algorithm efficiently arranges elements into two sections: sorted and unsorted sublists. This method simplifies list organization, enhancing sorting efficiency. In this article, we delve into the mechanics of selection sort, explaining its process and effectiveness in sorting various types of lists. Let’s explore what selection sort is and how it works. Takeaways ...

Bubble Sort Algorithm

Bubble Sort, a basic sorting algorithm, operates by repeatedly swapping adjacent elements if they are incorrectly ordered. Consider a list with elements 5, 4, 3, and 2; sorting algorithms like Bubble Sort can organize them in either ascending or descending order, rearranging elements to form meaningful sequences, as illustrated in this example. Ascending Sorting  Descending Sorting  ...

Binary Subtraction – Rules, Examples, Procedure

Binary subtraction of numbers can be done by adding the 2’s complement of the second number to the first number. Binary subtraction is just the binary addition of a negative number. Takeaways In binary subtraction, we are adding the 2’s complement of the subtrahend and adding into the number from which we want to subtract that. Before we begin, let’s look ...

Merge Sort Algorithm

Merge Sort algorithm is a Divide and Conquer algorithm. It divides the input array into two halves, calls itself for the two halves, and then merges the two sorted halves. Merge Sort algorithm is one of the most respected sorting algorithms, with a worst-case time complexity of O(nlogn). Merge sort works by dividing the array repeatedly to ...