Category Archives: DSF

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.

Continue reading Java Program to Convert Infix Notation to PostFix Notation

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:

  1. Breadth-First Search (BFS) — Explores all neighbours of the current node before going deeper. Uses a queue internally.
  2. 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.

Continue reading Implementing Graph Traversing Algorithms in Java

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.

Continue reading Java Program to Evaluate PostFix Expressions

Demonstrating Few String Manipulation Functions in Java

Java’s String class provides a rich set of built-in methods for manipulating text. In this post, we demonstrate the most commonly used string functions — including case conversion, length, concatenation, trimming, character access, equality checks, and index searching — through a simple interactive Java program.

Continue reading Demonstrating Few String Manipulation Functions in Java

Implementation of Stack using Linked List in Java

A stack is a LIFO (Last In, First Out) data structure where elements are inserted and removed from the same end, called the top. While a stack is commonly implemented using a fixed-size array, it can also be backed by a linked list — which removes the size constraint entirely and allocates memory only as elements are pushed.

In this post, we implement a stack using a singly linked list in Java. Each push operation adds a new node at the head of the list, and each pop removes the head node — making both operations O(1).

Continue reading Implementation of Stack using Linked List in Java

Implementing Circular Queue in Java with Arrays

A circular queue is a fixed-size queue where the storage array is treated as a ring. When elements are dequeued from the front, those positions become available again for future insertions — eliminating the wasted space problem of linear array queues. The queue follows the FIFO (First In, First Out) principle: elements are added at the rear and removed from the front.

This post presents a circular queue implementation in Java using a static array-backed design, demonstrating enqueue, dequeue, peek, and display operations through a menu-driven console program.

Continue reading Implementing Circular Queue in Java with Arrays

Implementing Doubly Linked List in Java

A Doubly Linked List (DLL) is a linked data structure where each node holds a value and two pointers: one pointing to the next node and one pointing to the previous node. This bidirectional linkage enables forward and reverse traversal — something a singly linked list cannot do without extra memory.

Doubly Linked List diagram
A doubly-linked list: each node stores a value, a link to the next node, and a link to the previous node.

In this post, we implement a DLL in Java that supports insertion at the first position, last position, after a given position, and before a given position — as well as deletion, search, and both forward and reverse display.

Continue reading Implementing Doubly Linked List in Java