Skip to main content

DSF

Java Collections Framework: Choosing the Right Data Structure

A complete, reference-level guide to the Java Collections Framework. Covers ArrayList vs LinkedList, HashSet vs LinkedHashSet vs TreeSet, HashMap vs LinkedHashMap vs TreeMap, PriorityQueue, ArrayDeque, and immutable collections u2014 with time-complexity tables, annotated code examples, and a decision guide for choosing the right data structure.

Java Streams API: The Complete Reference Guide

A complete, reference-level guide to the Java Streams API (Java 8+). Covers stream creation, intermediate operations (filter, map, flatMap, sorted, distinct, peek), terminal operations (collect, reduce, count, findAny, anyMatch), collectors, parallel streams, and the most common pitfalls u2014 with fully annotated code and sample output for every example.

Implementing Tower of Hanoi Problem in Java

The Tower of Hanoi is a classic mathematical puzzle that elegantly demonstrates the power of recursion. It consists of three rods (pegs) and a number of disks of different sizes that can slide onto any rod. The puzzle begins with all disks stacked in ascending size order on one rod (smallest on top) and the goal is to move the entire stack to another rod. Three rules must be followed: Only one disk may be moved at a time. A disk may only be moved if it is the uppermost disk on its rod. No disk may be placed on top of a smaller disk. The minimum number of moves required to solve the puzzle with n disks is 2n − 1. For 3 disks, that's 7 moves; for 10 disks, 1023 moves.

Implementation of Stack in Java

A stack is a LIFO (Last In, First Out) abstract data type where all insertions and deletions happen at the same end, called the top. Think of a stack of plates: you always add to the top and remove from the top. Stacks are used everywhere in computing — from function call management to expression evaluation and undo functionality. In this post, we implement a stack in Java using a fixed-size integer array, with push, pop, peek, and display operations accessible through a menu-driven console program.

Implementing Singly Linked List in Java

A singly linked list is a linear data structure made up of nodes, where each node contains a data field and a pointer to the next node in the sequence. Unlike arrays, linked lists do not require contiguous memory — elements can be inserted or removed at any position without shifting other elements. In this post, we implement a full-featured singly linked list in Java that supports insertion (at first, at last, at a given position), deletion (from first, last, or a given position), search, and display. A singly linked list — each node stores a value and a link to the next node.

Java Implementation of Queue using Linked List

A queue is a FIFO (First In, First Out) data structure where elements are added at the rear and removed from the front. While a queue can be implemented using a fixed-size array, backing it with a linked list removes the capacity constraint — the queue grows and shrinks dynamically as elements are enqueued and dequeued. In this post, we implement a queue using a singly linked list in Java, supporting enqueue, dequeue, peek, and display operations.

Implementing Quick Sort in Java

Quick Sort is a highly efficient, comparison-based sorting algorithm that uses the divide-and-conquer strategy. It selects a pivot element, partitions the array into elements smaller than the pivot and elements larger than the pivot, then recursively sorts each partition. Its average-case time complexity is O(n log n), making it one of the fastest general-purpose sorting algorithms in practice.

Java Program to Convert Infix Notation to PostFix Notation

Infix notation is the standard way we write arithmetic expressions, with operators between operands — e.g., A + B. Postfix notation (also called Reverse Polish Notation or RPN) places operators after their operands — e.g., A B +. Postfix expressions can be evaluated by machines without needing parentheses or operator-precedence rules, making them ideal for expression evaluators and compilers. In this post, we implement a Java program that converts an infix expression to its equivalent postfix form using a character stack and an operator-precedence table.

Implementing Graph Traversing Algorithms in Java

Graph traversal is the process of visiting all nodes in a graph in a systematic order. It is a fundamental operation in graph algorithms used for pathfinding, connectivity analysis, cycle detection, and more. There are two standard traversal strategies: Breadth-First Search (BFS) — Explores all neighbours of the current node before going deeper. Uses a queue internally. Depth-First Search (DFS) — Explores as far as possible along each branch before backtracking. Uses recursion (implicit call stack) internally. In this post, we implement both BFS and DFS on an undirected graph represented as an adjacency matrix.

Java Program to Evaluate PostFix Expressions

Postfix notation (also called Reverse Polish Notation or RPN) places every operator after its operands. For example, the infix expression (6 - (2 + 3)) * (3 + 8/2) becomes the postfix expression 623+-382/+*. Evaluating postfix expressions is straightforward using a stack — no parentheses or precedence rules are needed. This post implements a postfix evaluator in Java using an integer stack. The program accepts a postfix string as input and prints the computed result.