Articles for category: Data Structures and Algorithms

Word Break Problem

Problem Statement In the word break problem, you will be given a string, say s, and a dictionary of strings say wordDict. The wordDict will contain several strings. Now, our job is to determine if we can break or segment the string using the words in the dictionary. If we can do that, then we return a True, otherwise, ...

What are Data Structures in C?

Data Structures in C is a way of storing and organizing data in the computer memory so that it can be processed efficiently. Using the data structures in C, we can make our program to be able to utilize the memory efficiently as well as improve it’s performance. Depending on how the elements are organized ...

Ugly Numbers

Problem Statement We are provided with a number n. We need to print the n-th ugly number. An ugly number is a number whose prime factors are 2, 3, or 5 only. Note: $1$ is considered as an ugly number (conventionally). Refer to the Example and Explanation sections for more details and the Approach section ...

Unbounded Knapsack

Problem Statement Given a knapsack weight W and a set of N items with certain values(benefit or profit) val, and weights wt, find the maximum amount that could make up the exact knapsack weight.In Unbounded Knapsack, you may select an item multiple times. Example N = 4 W = 10 val[] = {15, 25, 20, ...

Types of Binary Tree

Binary trees are a fundamental data structure with various types. The two primary types of binary tree are full binary trees, where each node has either two children or no children, and complete binary trees, which are filled from left to right at each level. Additionally, there are balanced types of binary tree, such as ...

Triplet Sum in Array

Problem Statement An array of integers and a target sum are given, find out if there is any triplet whose sum is equal to the given target sum exists in the array or not, print the triplet, if a triplet sum in array is present and return true. Otherwise, return false. Example Input-1 Output-1 Explanation ...

Uniform-Cost Search Algorithm

The Uniform Cost Search Algorithm is a search algorithm to find the minimum cumulative cost of the path from the source node to the destination node. It is an uninformed algorithm i.e. it doesn’t have prior information about the path or nodes and that is why it is a brute-force approach. What is the Uniform ...

Wave Array

Problem Statement Sort an unsorted array arr of length n in a waveform. An array is said to be in wave form if it satisfies the following conditions: Example Example Explanation Input: arr = [7, 7, 11, 3, 4, 5, 15] Output: [4, 3, 7, 5, 11, 7, 15] or any other array in wave form. Explanation: In the ...

Two Pointer Algorithm

A reference to an object is a pointer. In some circumstances, memory-mapped computer hardware or another value located in computer memory is the value that is stored in that object’s memory address. To put it another way, a variable with an array’s address is likewise a pointer. As an example, we estimated the size of ...