Articles for category: Data Structures and Algorithms

Sort a Linked List

A linked list is a sequential collection of data elements connected via links. The data element of a linked list is known as a node which contains two parts namely- the data part and the pointer. For sorting a linked list, we can use the insertion sort-based algorithm as well as the merge sort algorithm. The insertion sort-based algorithm uses ...

Skip List in Data structure

Skip list data structure is an extension to a sorted linked list; it provides indexing and querying data with reduced time complexity because there is a concept of skipping nodes while exploring data, somewhat similar to binary search. Each node contains a few forward pointers (not just one or two as in a linked list), therefore ...

Time and Space Complexity of Selection Sort

Time complexity measures the execution time of an algorithm’s instructions. For the selection sort, the average, worst-case, and best-case time complexity of the selection sort are all $O(N^2)$, and the space complexity is O(1), indicating it requires a constant amount of extra storage space. Time Complexity of Selection Sort The Time complexity of Selection Sort ...

Palindrome String

A Palindrome string is a string which is equal to its reverse or we can say a string is palindrome if the reverse of the string is the same as the original one. Properties of Palindrome String A palindrome string is characterized by its symmetric structure, where the characters in the first half mirror those ...

Program to Find Largest Element in an Array

Problem Statement You are given an array arr[] of size N, where N represents the number of elements in the array. The task is to write a program to find and determine the largest element within this array. Examples Example 1: Example 2: Example 3: Example Explanation In above all the examples, we are finding the largest element from the ...

Palindrome Partitioning

Problem Statement Partitioning of any string ss is considered to be palindrome partitioning if every substring of the partition is a palindrome. In this problem, you have been given a string ss and you need to determine the fewest cuts needed for a palindrome partitioning of the given string. Examples Example 1 Input : abaaabOutput : Explanation : abaaab can be partitioned into a|baaab. It can be shown ...

n Queen Problem

What is N Queen Problem? The N-Queen is the problem of placing n queens on a chessboard of dimensions $n\times n$ such that no queen can attack another queen in a single move. Problem Statement We need to check if there exists such an arrangement of n queens and if it exists then print the ...

N-ary Trees

An N-ary tree or Generic Tree is a tree that can have at most N children. If we replace N with 2 then we get a binary tree. In other words, an n-ary tree node can have between 0 to N child nodes. N-ary trees are used in various use cases but moreover, these are useful where we are required to represent hierarchical data with multiple branching points at ...

Reverse Words in a String

In this problem “Reverse words in a String”, we are given an input string s. We need to reverse the order of the words and return a string of the words in reverse order. Takeaways In this article we will learn how to reverse words in a string using different approach. Example Input : Output : Example ...

Postfix Evaluation

Postfix notation (also known as Reverse Polish Notation) is a way to represent an expression, where operators follow their corresponding operands. Evaluating an expression represented as postfix notation can easily be done using the stack data structure. Scope Takeaways Introduction Postfix notation is one of the few ways to represent algebraic expressions. It is used ...