Articles for category: Data Structures and Algorithms

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

Tower of Hanoi Algorithm

The Tower of Hanoi problem consists of three rods (for example A, B, and C) and N disks initially stacked on rod A in decreasing order of diameter (smallest one is at the top). The goal is to transfer the entire stack to another rod (in this case, rod C) with the help of auxiliary rod(in this ...

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

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

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