Articles for category: Data Structures and Algorithms

Subset Sum Problem

Problem Statement You have a collection of non-negative values, representing available options, and a non-negative target value. Your task is to determine whether there exists a subset within the collection whose sum equals the given target value. Example Example1:   Example2: Approach 1: Using Recursion We can approach the Subset Sum Problem recursively by considering ...

Static Data Structure

In this article, we are going to learn about the static data structure. Before getting started with the static data structure let us get a short overview of what is a data structure and which data structure is of type static. Data Structure: A computer can contain an abundant amount of data, so a Data Structures. helps in organizing those ...

Sort an Array of 0s 1s and 2s

Problem Statement We are given an array consisting of only 0s, 1s, and 2s. Our task is to write a program to sort the given array without using inbuilt functions. Example Example Explanation Since we already know that an array is a linear data structure that contains data elements of the same data type at ...

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

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