Check If a Given Matrix is Sparse or Not in JavaScript

Prabhdeep Singh
Updated on 15-Dec-2024 16:29:10

265 Views

To check if a given matrix is sparse or not, we will be discussing two different approaches, their complexities, and example codes. A sparse matrix is a special type of matrix in which the number of zeroes is strictly more than half of the the total number of elements present in the given matrix. In this article we are having a 2D matrix, our task is to write a JavaScript program to check if a given matrix is sparse or not. Users must be familiar with conditional statement, nested for loop and javascript methods. Example Input: Matrix: [[1, ... Read More

Convert Integer to Hex String in Java

Revathi Satya Kondra
Updated on 14-Dec-2024 17:03:48

15K+ Views

In Java, converting an integer value to a hexadecimal (hex) string means transforming the number from its base-10 (decimal) format to base-16 format. This conversion uses digits 0-9 and letters A to F to represent the values. Integer: An integer is a whole number without having a fractional part, such as -2, -1, 0, 1, 2, etc. Hex String: A hexadecimal (hex) string represents a number in base-16, using digits 0-9 and letters A-F. We represent the A-F in numbers as 10 to 15. Example Let’s say the following are our integer values. int val1 = 5; int val2 ... Read More

Reverse a Number and Check if it is a Palindrome in Java

Rudradev Das
Updated on 13-Dec-2024 21:52:25

4K+ Views

What is a Palindrome Number? If a number is given (two, three or four-digit number) and reversing each individual number with the positions from front to back and then vice versa , and then if the number output is the same after reversing all the elements then it is said to be a palindrome number. Just like we will check whether the string or array is palindrome number. String - A string is a storing capsule or a storing method in which we can store a sequence of characters in a Java program. Array - An array is a collection ... Read More

Java Program for Pigeonhole Sort

Alshifa Hasnain
Updated on 13-Dec-2024 21:50:47

466 Views

In this article, we will learn Pigeonhole Sort in Java, a sorting algorithm designed for arrays with a small range of integer values. It organizes elements into "pigeonholes" based on their values and then reconstructs the sorted array. We’ll discuss two approaches: a basic method using arrays and an optimized approach using LinkedLists. What is Pigeonhole Sort? Pigeonhole Sort works by distributing elements into a range of buckets based on their values. It is most effective when the range of input values is relatively small compared to the size of the dataset. The algorithm ensures stability and simplicity in sorting ... Read More

Find the Third Maximum Number in an Array using JavaScript

Alshifa Hasnain
Updated on 13-Dec-2024 21:50:14

906 Views

In this article, we will learn to find the third maximum unique number in an array of JavaScript, or the largest number if there are fewer than three unique values. We will be using three methods: a single-pass approach for efficiency, a sorting method to identify the number after removing duplicates, and a combination of Set and Max-Heap for optimal handling of large datasets. Each method includes examples and a comparison of time and space complexities. Problem Statement Given an array of integers, find the third maximum unique number. If the array contains fewer than three unique numbers, return the ... Read More

Java Program to Save Decimal

Alshifa Hasnain
Updated on 13-Dec-2024 21:49:28

898 Views

In this article, we will learn two ways to handle decimal values in Java. First, we will use the BigDecimal class to ensure precision when working with decimals. Then, we will use the DecimalFormat class to format decimal values. Both examples will show how to scale decimal values to three places. Different Approaches to Save Decimal Values The following are the two approaches to save decimal values in Java − Using BigDecimal Using DecimalFormat Save Decimal Values Using BigDecimal for Precision Control The BigDecimal class of java.math package is used for ... Read More

Check If a Number is a Happy Number in C#

AYUSH MISHRA
Updated on 13-Dec-2024 21:46:55

8K+ Views

Problem DescriptionWe are given a number as input, we have to check whether the number is a happy number or not. In this article, we are going to learn how we can check if a number is a happy number or not in C#. What is a happy number?A happy number is a special type of number that will at last become equal to 1 when we replace the number with the sum of the square of its digits again and again. If the number is stuck in the loop such that it never becomes equal to 1 then the ... Read More

Get Frequency of Words Using Lambda Expression in Java

Alshifa Hasnain
Updated on 13-Dec-2024 13:55:29

645 Views

In this article, we will learn how to calculate the frequency of words in a text using Java and Lambda Expressions. By leveraging concise syntax and functional programming techniques, we can efficiently process text data and determine word occurrences. This approach is particularly useful for applications like text analysis and natural language processing. What is Lambda Expression? A lambda expression in Java is a concise way to represent an anonymous function(a function without a name). Introduced in Java 8, it simplifies the implementation of functional interfaces (interfaces with a single abstract method), enabling cleaner and more readable code. Syntax of ... Read More

Java Program for Pancake Sorting

Alshifa Hasnain
Updated on 13-Dec-2024 13:54:50

726 Views

In this article, we will learn pancake sorting which is a unique way to sort an array by flipping sections of it. The algorithm finds the largest unsorted element, flipping it to the front, and then flipping it to its correct position. Although not the fastest sorting method, it’s an interesting and creative way to learn about problem-solving and data manipulation. This article explains the algorithm in simple steps and shows how to implement it in Java. What is Pancake Sorting? Pancake sorting is a sorting technique that resembles selection sort, i.e. sorting the largest element first thereby reducing the ... Read More

Check If String is a Palindrome in JavaScript

Nikitasha Shrivastava
Updated on 13-Dec-2024 13:54:15

830 Views

In the given problem statement we have to find that the string is a palindrome and the string should also have punctuation and write code with the help of Javascript functionalities. Here we will learn two methods to determine if a string is a palindrome in JavaScript while handling punctuation and spaces effectively. What is a Palindrome? A palindrome is not limited to single words like "radar" or "level"; it can include phrases or sequences like "Madam, in Eden, I’m Adam." We need to ignore punctuation, spaces, and case differences to ensure accurate palindrome checks.   Using JavaScript String and Array ... Read More

Advertisements