Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles by Ravi Ranjan
117 articles
Binary search in C#
The binary search algorithm works on 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, the array must 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 sub-array, 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 ...
Read MoreJavaScript Program to Find the Lost Element from a Duplicated Array
To find the lost element from a duplicated array in JavaScript, we will be discussing various approaches. Prerequisites to solve this problem include understanding of JavaScript arrays, loops, Set object, and binary search. In this article we have two arrays where one array is a duplicate of the other with one missing element. Our task is to find the lost element from the duplicated array in JavaScript. Problem Statement Given two arrays where the second array is missing exactly one element from the first array, we need to identify that missing element. Input: array1 = ...
Read MoreJavaScript Program for Rotate a Matrix by 180 degrees
To rotate a matrix by 180 degrees, we can achieve this using various approaches. In this article, we'll explore three different methods with step-by-step explanations and complete examples. A 180-degree rotation of a matrix means that the first row becomes the last row in reverse order, the second row becomes the second-to-last row in reverse order, and so on. Essentially, we're flipping the matrix both horizontally and vertically. Example Input: matrix = [[1, 2, 3, 4], [5, 6, 7, 8], ...
Read MoreJavaScript Program for the Third Largest Element in an Array of Distinct Elements
For the third largest element in an array of distinct elements, we will discuss three different approaches. We will improve efficiency with each approach and discuss their complexities. In this article we are having an array of distinct elements, our task is to find third largest element in an array of distinct elements in Javascript. Users must be familiar with array, loops and conditional statement. Problem Statement Given an array of distinct elements, we need to find the third largest element efficiently. Input: arr = [2, 5, 8, 1, 4, 10, 7] => Highest: 10, ...
Read MoreJavaScript Program to Check if Matrix is Upper Triangular
To check if matrix is upper triangular matrix, we check if all the elements below the main diagonal is 0. We are going to discuss two different approaches and compare their complexities. In this article we are having a 2D square matrix, our task is to write a JavaScript program to check if matrix is upper triangular matrix. Users must be familiar with upper triangular matrix, nested for loop, conditional statement and javascript methods. ...
Read MoreJavaScript Program for Two Pointers Technique
In this article we are given a sorted array, our task is to find if there exists any pair of elements such that their sum is equal to a given number. Users must be familiar with array, loop and nested loops, and if/else statement. Two Pointers Technique Two pointers technique is a commonly used algorithmic approach to solve various problems that require linear time complexity. This technique is used to find a solution for problems that involve searching, sorting, or manipulating arrays, strings, or linked lists. In this article, we are going to solve the pair sum problem using ...
Read MoreJavaScript Program for Counting Frequencies of Array Elements
Counting frequencies of array elements means determining how many times each element appears in an array. This is a common programming task useful for data analysis, statistics, and various algorithms. JavaScript provides multiple approaches to solve this problem efficiently. In this article, we'll explore five different methods to count element frequencies in JavaScript. Each approach has its own advantages - some prioritize simplicity, others performance, and some leverage built-in methods or external libraries. Approaches to Count Array Elements Frequencies Here are the five approaches we'll cover, each with detailed explanations and complete working examples: ...
Read MoreJavaScript Program for Counting sets of 1s and 0s in a binary matrix
Counting sets of 1s and 0s in a binary matrix can be achieved using nested for loops with conditional statements. A binary matrix is a matrix that consists of only two digits: 1 and 0. In this article, we will write a JavaScript program for counting the sets of 1s and 0s in a given binary matrix by counting non-empty subsets in each row and column. Understanding the Formula For any set with n elements, the total number of non-empty subsets is 2^n - 1. Let us consider a set {a, b} having 2 elements ...
Read MoreJavaScript Program for Frequencies of Even and Odd Numbers in a Matrix
To get frequencies of even and odd numbers in a matrix, we will be discussing three different approaches. We will discuss each approach with code examples and solution of the algorithm being used. In this article we are having a 2D matrix, our task is to write a JavaScript program for frequencies of even and odd numbers in a matrix. Users must be familiar with conditional statement, nested loops and javascript operators. Example Input: Matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]; Even numbers: {2, 4, 6, 8} Odd numbers: {1, 3, ...
Read MoreJavaScript Program to Find Lexicographically minimum string rotation
To find lexicographically minimum string rotation in JavaScript, we will understand two different approaches in this article. A lexicographically minimum rotation of a string is the smallest string that can be obtained by rotating the original string any number of times in lexicographical order. By lexicographical order it means dictionary order such as: a < b, ab < ac. In this article we are having a string. Our task is to write a JavaScript program to find lexicographically minimum string rotation. Example Input: bba All lexicographical order are: bba, bab, abb Output: Smallest lexicographical ...
Read More