Articles for category: Data Structures and Algorithms

Which Data Structure May Produce an Overflow Error?

Overflow error is an error that happens when a program receives a number, value or variable outside the scope of its ability to handle. Takeaways A linear queue can throw an Overflow error even if it has empty spaces for elements in it. Which Data Structure May Produce an Overflow Error? Correct Answer a. A Linear Queue can produce an ...

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

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

Trapping Rain Water Problem

Problem Statement The width of each and every bar on to an elevation map is 1. Determine how much water it can hold after it rains by computing the heights of the elevation map bars, which are represented by n non-negative integers. Example Input: Output: Example Explanation Representation of above input heights is given below in ...

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