Found 1860 Articles for Data Structure

Java Program to Implement the RSA Algorithm

Shubham Vora
Updated on 31-May-2024 15:28:42

6K+ Views

The RSA name is given by their inventors which is used to encrypt the text with high security. The RSA technique is one of the most used techniques to encrypt text, as it is the asymmetric encryption algorithm. It encrypts the text by utilizing the mathematical properties of the prime numbers. In the RSA algorithm, the sender and receiver have private keys. Also, a common public key exists, which the sender shares with the receiver. The sender encrypts the plain text using their own public and private key, and the receiver decrypts the message using their private and public ... Read More

Java Program to Implement the Linear Congruential Generator for Pseudo Random Number Generation

Alshifa Hasnain
Updated on 29-Mar-2025 02:56:11

571 Views

In this article, we will implement the linear congruential generator for pseudo random number generation in Java. Pseudo random number generator (PRNG) are mainly used in simulations, cryptography, or mathematical tasks. What is an LCG? A Linear Congruential Generator (LCG) is a technique to generate a sequence of numbers that looks like random numbers but are actually determined. It is one of the reasons to call it a pseudo-random number. The Linear Congruential Generator (LCG) technique generates a random number based on the previous number and uses linear recurrence to generate the sequence of the random number. Mathematical Formula We can ... Read More

Java Program to Implement the String Search Algorithm for Short Text Sizes

Shubham Vora
Updated on 24-Aug-2023 17:56:59

164 Views

In this problem, we need to find the index of the pattern in the string. Implementing an efficient text search is very important to allow users to search large text databases easily. For example, you are writing a blog in Microsoft Word or code in VSCode, containing 1 lakh+ word. If the search algorithm is inefficient, it can take time to show you search results when searching for any word or sentence. We will learn two different approaches to implementing the string search algorithm. One is the naïve approach, and another is the KMP algorithm. Problem statement - ... Read More

Sum of all prefixes of given numeric string

Shubham Vora
Updated on 24-Aug-2023 17:48:33

194 Views

In this problem, we need to find the sum of all prefixes of the given string. The best solution approach is that traverse through each prefix of the string and add them to get the answer. Problem statement - We have given a string named num_Str containing N digits. We need to find the sum of all prefixes of the given string. Sample examples Input num_str = "1123" Output 1247 Explanation - All prefixes of the given strings are 1, 11, 112, and 1123. The sum of all prefixes is 1247. Input num_str = ... Read More

Minimize the cost to convert given string to either type XYXY… or XXYY…

Shubham Vora
Updated on 24-Aug-2023 17:46:19

134 Views

In this problem, we need to convert the given binary string to abababab or aabbaabb format and find the minimum cost for that. Also, we have given the cost to flip any character in the operations array. Problem statement - We have given a bin_str binary string and operations array containing the positive integers. The size of the string and array is the same and even. The task is to find the minimum costs to convert the string in the ababab… or aabbaabb… format. The cost to flip any character in the given string is the value at the ... Read More

Maximum string length after choosing strings from given Array with given conditions

Shubham Vora
Updated on 24-Aug-2023 17:32:53

398 Views

In this problem, we need to find the maximum length of the resultant string by appending the array strings to it such that if we choose a string of length x, we can choose the next x/2 strings. We can solve the programming using the recursive function, memoization, and dynamic programming approach. Problem statement - We have given an array of strings named str_array containing the N strings. We need to add the strings given in the array and find the maximum size of the resultant string. While appending the string to the resultant string, we need to ... Read More

Maximum adjacent index difference for a subsequence T present in given string S

Shubham Vora
Updated on 24-Aug-2023 17:29:28

170 Views

In this problem, we need to find the maximum difference between the indices of the subsequence present in the given string. To solve the problem, we need to find the indices of the subsequence in the actual and reverse order. After that, we need to take the difference of both. Problem statement - We have given two strings named 'str' and 'sub'. The 'sub' string is always present in the 'str' string as a subsequence. We need to find the maximum index cost. The index cost is the difference between two indices of the subsequence. ... Read More

Maximize characters to be removed from string with given condition

Shubham Vora
Updated on 24-Aug-2023 17:25:16

157 Views

In this problem, we need to remove the maximum characters from the string if the adjacent character is the previous character. We can find the occurrence of each character and check whether any of its adjacent characters is a previous character, we can remove the particular character. Problem statement - We have given a string containing the N alphabetic characters. The given task is we need to remove the maximum number of characters, and we can remove any character of the string if any adjacent character is the previous character in the alphabet. At last, print the count ... Read More

Find the Suffix Array of given String with no repeating character

Shubham Vora
Updated on 24-Aug-2023 17:22:51

142 Views

In this problem, we will find the suffix array of the given string. We can sort all the string's suffixes using their first character, as the input string contains different characters. Problem statement - We have given a string containing the different alphabetical characters, and we need to find the suffix array of the given string. The suffix array of the string is a sorted array containing all suffixes of the given string. Sample examples Input str = "point"; Output 2 3 1 0 4 Explanation All suffixes of the string ... Read More

Find frequency of each digit 0-9 by concatenating ASCII values of given string

Shubham Vora
Updated on 24-Aug-2023 17:21:14

158 Views

In this problem, we need to count digits frequencies after merging the ASCII values of all characters. The approach to solving the problem is to create a string containing each character's ASCII values and count the frequency of the digits in the string. Problem statement - We have a string alpha containing different characters, and the length of the string is N. We need to calculate each digit's frequency after concatenating the ASCII values of the given string's characters. Sample examples Input alpha = "tutorialspoint" Output 4 25 1 0 1 3 3 2 1 1 ... Read More

Advertisements