Optimal Binary Search Tree

Farhan Muhamed
Updated on 12-Aug-2025 16:23:36

9K+ Views

In this article, we will discuss a classic Dynamic Programming problem that involves constructing an optimal binary search tree for a given set of keys with their search probabilities. Before diving into the problem, let us understand what are Binary Search Trees and Dynamic Programming. Optimal Binary Search Tree Problem In this problem, you are given: A sorted array of keys[] of size n that contains the keys to make the binary search tree. An array freq[] of size n, where freq[i] is how many times keys[i] is searched. ... Read More

Check if array can be sorted with one swap in Python

Yaswanth Varma
Updated on 08-Aug-2025 17:10:14

341 Views

Sorting is a task used to organize the numbers in increasing order. Usually, we use the sorting algorithms to do this, but in most cases, the array is almost sorted, with two or three numbers in the wrong position. In such scenarios, instead of sorting the entire array, we can check if swapping just one pair of elements will make the entire array sorted. Checking if Array can be Sorted with One Swap The given task is to check if an array can be sorted with one swap in Python. i.e., given an array with distinct integers, we need ... Read More

Check if any square (with one colored cell) can be divided into two equal parts in Python

Yaswanth Varma
Updated on 08-Aug-2025 16:17:50

191 Views

Dividing a Square into two Equal Parts In this article, we are given a square of size n*n with exactly one cell coloured. The task is to determine whether this square can be divided into two equal splits by making a single straight cut along the square, ensuring that the coloured cell lies entirely within one of the splits. Two equal splits here indicate that both parts must contain the same number of cells, which is possible if the square side length is even. In this article we are not only checking whether the split is possible but also whether the ... Read More

Can an anonymous class have constructors in Java?

Aishwarya Naglot
Updated on 08-Aug-2025 15:39:51

2K+ Views

Anonymous Classes in Java are classes that do not have a name. They are typically used to extend a class or implement an interface without the need for a separate named class. The following are the common uses of anonymous classes:Implementing event listeners.Creating Runnable objects for threads.Providing custom implementations for abstract methods of an abstract class. Constructors in an Anonymous class Anonymous classes cannot have a constructor, but the compiler provides a default constructor for them. This means that when you create an instance of an anonymous class, it will call the constructor of the superclass or the interface it ... Read More

Class with a constructor to initialize instance variables in Java

Aishwarya Naglot
Updated on 08-Aug-2025 15:09:08

12K+ Views

Constructors are special methods in Java that are invoked when an object is instantiated. They are typically used to initialize instance variables of a class. In this article, we will explore how to create a class with a constructor to initialize instance variables in Java. Creating a Class with a Constructor To create a class with a constructor, you define the class and then create a constructor that has the same name as the class. The constructor accepts parameters to initialize instance variables. Example In the example below, we have a class named 'Car' with three instance variables: 'model', 'year', ... Read More

Binary Search on Singly Linked List in C++

Ravi Ranjan
Updated on 08-Aug-2025 14:40:31

2K+ Views

In this article, we are given a sorted singly linked list, and our task is to search for a given node using a binary search algorithm. The binary search algorithm works on the divide-and-conquer principle as it keeps dividing the list in half before searching. To search for an element in the linked list using binary search, it should be sorted. In the sorted linked list, we find the middle node using two pointers (slow and fast) and compare it with the target node, and based on the comparison, we either search in the left or right sub-list or return ... Read More

Binary Search in C++

Ravi Ranjan
Updated on 08-Aug-2025 14:26:16

19K+ Views

The binary search algorithm works as per the divide-and-conquer principle, as it keeps dividing the array in half before searching. To search for an element in an array using binary search, it should be sorted. In the sorted array, we find the middle element and compare it with the element that has to be searched, and based on the comparison, we either search in the left or right sub-array or return the middle element. In this article, we are given a sorted array of integers, and our task is to search for the given target element using the binary search ... Read More

Angle between a chord and a tangent when angle in the alternate segment is given in C++?

Manisha Chand
Updated on 08-Aug-2025 11:17:45

168 Views

In this problem, we are given a circle whose chord and tangent meet at a particular point. The angle in the alternate segment of a circle is given. We need to find the angle between the chord and the tangent. According to the Alternate Segment Theorem the angle between a chord and a tangent is equal to the angle in the alternate segment of the circle. Chord and Tangent The chord of a circle can be defined as the line segment joining any two points on ... Read More

10 Essential Web Scraping Tools for Data Collection in 2025

sudhir sharma
Updated on 08-Aug-2025 10:43:32

157 Views

Data is more than just a business asset – it's a strategic advantage. Whether you're monitoring competitors, tracking product prices, gathering SEO insights, or creating machine learning models, relevant and structured web data is the modern gold. That’s where web scraping can become your winning strategy. Web scraping is the extraction of digital data and information from websites. Most businesses use it for market research, lead generation, brand monitoring, and much more. But scraping the modern web is way different nowadays, with dynamic content, anti-bot systems, and ever-changing layouts making it more difficult by the day. Depending on your needs, ... Read More

Write a program in C++ to count the Number of substrings that starts with ‘1’ and ends with ‘1’

Nishu Kumari
Updated on 08-Aug-2025 10:33:58

514 Views

We are given the length of a binary string str and the string itself. The task is to count the number of substrings that start with '1' and end with '1'. A binary string contains only '0's and '1's, and a substring is any continuous part of the given string. Let's look at a few example scenarios to understand the problem clearly: Scenario 1 Input: N = 5, str = "11101" Output: 6 Explanation: In the given binary string, there are 6 substrings that start and end with '1'. These are: ("11", "111", "1110", "11101", "1101", and "101"). Scenario ... Read More

Advertisements