Skip to main content

Posts

Showing posts from 2025

Word Frequency Counter

Word Frequency Counter in Java Task Write a Java program to count the frequency of each word in a given sentence. The program should: 1. Take a sentence as input. 2. Split the sentence into individual words. 3. Count how many times each word appears. 4. Print each word along with its frequency. Example Input: the quick brown fox jumps over the lazy dog Output: the : 2 quick : 1 brown : 1 fox : 1 jumps : 1 over : 1 lazy : 1 dog : 1 --- Code import java.util.HashMap; import java.util.Map; public class WordFrequencyCounter {     public static void main(String[] args) {         // Input sentence         String sentence = "the quick brown fox jumps over the lazy dog";         // Split the sentence into words (using space as delimiter)         String[] words = sentence.split(" ");         // Create a HashMap to store words and their counts         Map<String, In...

BASICS OF ALGORITHMS

Definition of an Algorithm: An algorithm is a step-by-step procedure or a set of rules designed to solve a specific problem or accomplish a defined task in a finite amount of time. It is a well-defined computational process that takes input and produces output. *** Characteristics of an Algorithm *** An algorithm must satisfy the following characteristics: Input: The algorithm should have well-defined inputs. Inputs can be zero or more quantities. Output: The algorithm must produce at least one output. The output should be the solution to the problem. Finiteness: The algorithm must terminate after a finite number of steps. Infinite loops or unending calculations violate this characteristic. Definiteness: Each step of the algorithm must be precisely defined. Ambiguity in any step should be avoided. Effectiveness: Each operation should be basic enough to be carried out by a computing agent (such as a person or a computer) in a finite amount of time. Performan...