Anagram checking in Java

Let's go over Anagram checking in Java. An anagram is when two strings have the same characters in a different order, e.g., "listen" and "silent". There are multiple ways to check for anagrams. I’ll cover the most common and efficient methods. Using Sorting Idea: Convert strings to char arrays. Sort both arrays. If they…

0 Comments

String reversal in Java

Let's go over string reversal in Java. There are several ways to reverse a string, from simple to more advanced. I’ll cover the most common methods. 1️⃣ Using a for loop public class StringReversal { public static String reverseString(String str) { String reversed = ""; for (int i = str.length() - 1; i >=…

0 Comments

Linear Search in Java

Linear Search Algorithm Linear Search checks each element one by one until it finds the target. Works on unsorted or sorted arrays. Time Complexity: O(n) Space Complexity: O(1) Iterative Linear Search public class LinearSearch { public static int linearSearch(int[] arr, int target) { for (int i = 0; i < arr.length; i++) { if…

0 Comments

Binary Search in Java

Binary Search Algorithm Binary Search works on sorted arrays and uses divide-and-conquer: Find the middle element. If it matches the target, return the index. If target < middle, search the left half. If target > middle, search the right half. Repeat until found or range is empty. Time complexity: O(log n)Space complexity: O(1) for…

0 Comments

Power Function using recursion in Java

Problem We want to compute: ab=a×a×a…  (b times)a^b = a \times a \times a \dots \; (b \text{ times}) For example: 25=322^5 = 32 34=813^4 = 81 Recursive Idea Base case: If b=0b = 0, return 1 (since a0=1a^0 = 1). Recursive case: ab=a×a(b−1)a^b = a \times a^{(b-1)}. Simple Recursive Code public class PowerRecursion { //…

0 Comments

Greatest Common Divisor (GCD)

What is GCD? The Greatest Common Divisor (GCD) of two numbers is the largest positive integer that divides both numbers without leaving a remainder. Examples: GCD(48, 18) = 6 GCD(56, 98) = 14 Recursive Idea (Euclidean Algorithm) The Euclidean algorithm is the most efficient recursive method for GCD: gcd(a,b)={aif b=0gcd(b,a%b)if b≠0\text{gcd}(a, b) = \begin{cases} a &…

0 Comments

Fibonacci using recursion in Java

What is Fibonacci? The Fibonacci sequence is defined as: F(0)=0,F(1)=1F(0) = 0, \quad F(1) = 1 F(n)=F(n−1)+F(n−2)for n≥2F(n) = F(n-1) + F(n-2) \quad \text{for } n \geq 2 So, the sequence looks like:0, 1, 1, 2, 3, 5, 8, 13, 21 … Recursive Idea Base cases: If n == 0, return 0. If n ==…

0 Comments

Factorial using recursion in Java

What is Factorial? The factorial of a number n (denoted as n!) is the product of all positive integers up to n. n!=n×(n−1)×(n−2)×⋯×1n! = n \times (n-1) \times (n-2) \times \dots \times 1 Examples: 5!=5×4×3×2×1=1205! = 5 \times 4 \times 3 \times 2 \times 1 = 120 0!=10! = 1 (by definition) Recursive Idea…

0 Comments

Sum of Digits in recursion

The "Sum of Digits in recursion" in Java refers to solving the problem of finding the sum of digits of a number using a recursive method. For example, if the number is 1234, the sum of digits is: 1+2+3+4=101 + 2 + 3 + 4 = 10 How recursion works here: Base case: If…

0 Comments

npm vs pnpm vs npx vs yarn

1. npm (Node Package Manager) Comes by default when you install Node.js. Used to install packages, manage versions, and run scripts. 🔹 Example: Install React npm install react npm install react 🔹 Install globally: npm install -g typescript npm install -g typescript 🔹 Run project scripts (from package.json): npm run build npm run build…

0 Comments

End of content

No more pages to load