Category Archives: Snippets

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.

Continue reading Implementation of Stack in Java

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.

Singly Linked List
A singly linked list — each node stores a value and a link to the next node.
Continue reading Implementing Singly Linked List in Java

Using Localhost For Facebook App Development

Note: This post was written in 2015 using an older version of ngrok. The current ngrok CLI uses different syntax: custom subdomains (-subdomain flag) are no longer available on the free plan, and the auth token command has changed to ngrok config add-authtoken <token>. The general approach of tunnelling localhost for Facebook OAuth is still valid — see the current ngrok documentation for up-to-date instructions.

As a programmer you do develop every application on your machine first and then you test it on same machine and then you push it to remote test/production environment. You are developing a Facebook app and your requirement is user must login to use the app. Now you are ready with local environment, you have created a new project in your powerful IDE, you have downloaded the SDK, you are done with creating a new app in FB developer, now you are trying to add app domains to get access to FB’s oAuth API. Hmm….. Something went wrong!… Facebook is not allowing you to use ‘localhost’ as app domain. Now what to do? Here is solution.

Continue reading Using Localhost For Facebook App Development

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.

Continue reading Java Implementation of Queue using Linked List

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.

Continue reading Implementing Quick Sort in Java

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