Hypotenuse refers to the longest side, which is opposite to the right angle of a right-angled triangle. Following is the diagram of the Hypotenuse: Length of the Hypotenuse The length of the hypotenuse can be calculated using the Pythagorean theorem. According to it, the sum of the squares of the lengths of two sides is equal to the square of the length of the third side as follows: a2 + b2 = c2 c = √(a2 + b2) Where a, b, and c refer to the three sides of the right-angled triangle. You can write the above formula ... Read More
Knapsack is a classic problem that involves decision-making based on constraints. Suppose we have a knapsack with fixed capacity, and items with fixed values and sizes (it might be volume of the item or weight). We need to add items into the knapsack such that we pack the maximum value items. From the available combinations, we need to provide an optimized solution. There are three types of knapsack problems 0-1 Knapsack: We can either pick an item or not (0 or 1). Fractional Knapsack: We can pick a part of an ... Read More
In this article, we will learn to load a file into the JShell session in Java 9. We will learn about Jshell and different ways we can load a file in Jshell, which is the command line and the /open command. What is a JShell? JShell is a new command-line interactive REPL (Read-Evaluate-Print-Loop) tool introduced in Java 9 to evaluate declarations, statements, and expressions written in Java. This tool also allows us to execute Java code snippets and get immediate results. Loading a file into the JShell There are two ways to load a file into the JShell session in ... Read More
In this article, we will learn to implement a lambda expression in JShell in Java 9. We will learn the syntax, explain the working of lambda expressions, and how they work with functional interfaces, and give examples with the JShell environment. JShell JShell is Java's first REPL and command-line tool that provides interactive use of Java programming language elements. We can test the functionality in isolation of a class by using this tool. JShell creates a simple and easy programming environment in the command-line that takes input from the user, reads it, and prints the result. What is a ... Read More
In this article, we will learn about the new methods added to the String class in Java 9. We will learn about Strings and the new methods in the String class, along with examples. Strings A String is the type of object that contains a collection of characters enclosed by double quotes (" "). The Java platform provides the String class to create and manipulate strings in Java. The String class is immutable, so that once it is created, a String object cannot be changed. String is the only class where operator overloading is supported in Java, we can concatenate ... Read More
A structure in C++ is a user-defined data type, which is used to group and store variables of different data types under a single name. In this article we will see how to sort an array of structures using conditions on member variables. For this we will be using the sort() function which is defined under header file. Syntax Here is the following syntax of sort() function. sort(start_index, end_index, comparison_function); start_index is an iterator (or pointer) to the first element of the array of structures.end_index is an iterator (or pointer) to one past the last element (means last_index + ... Read More
JavaScript Program for the Number of local extrema in an array is a common problem in the field of computer science and data analysis. Local extrema are the peaks and valleys in a sequence of numbers. In this article we are having two arrays, our task is to write a Javascript program for number of local extrema in an array. Example Input: arr1 = [1, 2, 3, 2, 1, 4, 5, 6, 5, 4, 3, 2, 1]; First local extrema: 3, {2 < 3 > 2} Second local extrema: 1, {2 > 1 < 4} Third local ... Read More
A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. In this article, our task is to find the maximum element in the given sorted and rotated array. We will use the following two approaches mentioned below: Using Linear Search Using Binary Search Example Here is an example of ... Read More
A sorted and rotated array is an array that is sorted in ascending or descending order and then rotated either left or right by a specific number of elements. There should exist exactly one pivot point around which the array is rotated. In this article, our task is to find the minimum element in the given sorted and rotated array. We will use the following two approaches mentioned below: Using Linear Search Using Binary Search Example Here is an example of searching the ... Read More
The subsets of a set refers to all the possible combinations of choosing elements from the set. For example, if we have a set {1, 2}, the subsets are {}, {1}, {2}, and {1, 2}. In this article, we will learn how to generate subsets of a set using the Binary Counting Method in C++. // Set of elements int arr[] = {1, 2, 3}; // Subsets of the above set {}, {1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3} Binary Counting Method The binary counting method is a technique used to generate ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP