Learnitweb

Category: Data structures and algorithms

  • Finding the Middle Node of a Linked List in Java

    In this tutorial, we will explore different approaches to find the middle node of a linked list in Java. This is a common coding interview question, and understanding its logic is essential for working with linked lists. Approach 1: Using Slow and Fast Pointers (Tortoise and Hare Algorithm) Logic This is the most common and…

  • Detecting Cycles in a Directed Graph

    Introduction Cycle detection in directed graphs is an essential problem in computer science, with applications in various domains, such as financial trading, multithreading, and operating systems. Understanding how to detect cycles allows us to optimize systems, prevent deadlocks, and even identify arbitrage opportunities in financial markets. Applications of Cycle Detection Detecting Cycles in a Directed…

  • Finding shortest path with topological ordering

    1. Introduction In this tutorial, we’ll discuss about finding the shortest path with topological ordering. Usually we use Dijkstra’s algorithm if we want to find the shortest path in an arbitrary graph G(V,E) graph. But if the graph is a directed acyclic graph, we can achieve linear running time to calculate the shortest path in…

  • Topological ordering

    1. Introduction Topological ordering is a fundamental concept in graph theory and is particularly applied to Directed Acyclic Graphs (DAGs). The algorithm for obtaining a topological order was introduced by Robert Tarjan in 1976. Topological ordering(topological sort) of a G(V,E) directed graph is a linear ordering of its vertices such that for every directed (u,v)…

  • Maze problem

    1. Problem description The problem is that we have to construct an algorithm that can find its way out of an NxN maze. We can represent this maze with an NxN matrix. The maze problem is a classic application of Depth First Search (DFS), where the objective is to find a path from a starting…

  • Depth First Search Algorithm

    1. Introduction In this tutorial, we will explore another graph traversal technique: Depth First Search (DFS). This algorithm is designed to visit each vertex exactly once. Consider a graph with vertices A, B, C, D, E, and F, connected by multiple directed edges. DFS navigates through the graph by exploring as far as possible along…

  • Doubly linked list

    Introduction In this tutorial, we are going to discuss Doubly Linked Lists (DLL), how they are structured, their advantages, disadvantages, and why they are often preferred over singly linked lists in certain situations. We will also look into Java’s built-in LinkedList class that uses a doubly linked list internally. What is a Doubly Linked List? A Doubly…

  • Linked list data structure

    1. Introduction A Linked List is a linear data structure where elements (nodes) are stored in a sequence, and each node holds two components: the data and a reference to the next node. Unlike arrays, linked lists don’t need to be stored in contiguous memory locations, making insertions and deletions easier. In this tutorial, we…

  • Array data structure

    1. Introduction The goal of a data structure is to make operations as fast as possible such as inserting new items or removing given items from the data structure. Arrays are data structures where all the items are identified by an index – an integer starting with 0. The items of the array are located…

  • Abstract Data Type(ADT) vs Data Structures

    1. Introduction Abstract Data Types (ADTs) and Data Structures are related but distinct concepts in computer science. In this short tutorial, we’ll discuss Abstract Data Type and Data Structures. 2. Abstract Data Types (ADTs) An ADT describes a conceptual model for data types by outlining the operations that can be performed on the data, without…