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 ...

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 ...

NP Hard and NP Complete Problem

The NP-hard problems are solved in polynomial time by non-deterministic machines and are difficult to find but simple to prove. NP (Nondeterministic Polynomial) is a class of decision problems in computer science where a proposed solution can be verified quickly. NP-hard problems are at least as challenging as the hardest problems in NP, and solving ...

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 ...

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 ...

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 ...

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 ...