Learnitweb

Category: Data structures and algorithms

  • Selection Sort in Java

    1. Introduction Selection Sort is a straightforward, comparison-based sorting algorithm that divides the array into two sections: In every iteration, the algorithm selects the minimum element from the unsorted part and places it at the beginning of the unsorted section, effectively expanding the sorted section by one element. 2. How Selection Sort Works – Conceptual…

  • Insertion Sort in Java

    1. Introduction to Insertion Sort Insertion Sort is a simple and intuitive sorting algorithm. It is widely taught in computer science courses because it demonstrates the basic concept of sorting by comparison and shifting. The algorithm mimics the way we sort playing cards in our hands — by inserting one card at a time into…

  • Bubble Sort in Java

    1. What is Bubble Sort? Bubble Sort is a simple sorting algorithm used to arrange elements in ascending or descending order. It works by repeatedly comparing adjacent elements and swapping them if they are in the wrong order. The largest elements “bubble” to the top of the list (i.e., the end of the array) after…

  • Tree Data Structure – Introduction

    In this tutorial, we’ll explore the Tree data structure, its terminologies, and the types of trees based on the number of children a node can have. This is a foundational topic for data structures, often used in technical interviews and essential for real-world programming tasks. What is a Tree Data Structure? A Tree is a…

  • Linear and Non-Linear Data Structure

    1. Introduction to Data Structures In computer science, a data structure is a way of organizing and storing data so that it can be accessed and modified efficiently. Data structures are fundamental for designing efficient algorithms and software systems. Data structures can be broadly categorized into: Understanding the difference between them helps in selecting the…

  • Custom HashMap in Java

    This tutorial walks you through creating a custom HashMap in Java. You’ll learn how to implement: We’ll use: This version does not include initial capacity, load factor, or resizing to keep it simple and focused. Step 1: Define the MyHashMap Class and Entry Nodes Detailed Explanation: Step 2: Compute Hash (Array Index) Explanation: Step 3:…

  • Java ArrayDeque

    What is ArrayDeque? ArrayDeque (Array Double Ended Queue) is a resizable-array implementation of the Deque interface in Java. Key Features: Where is it defined? It is part of the Java Collections Framework, available since Java 6. Class Declaration Constructors Constructor Description ArrayDeque() Creates an empty deque with initial capacity 16 ArrayDeque(int numElements) Creates a deque…

  • Queue Data Structure

    What is an Abstract Data Type? An abstract data type (ADT) defines the behavior of a data structure—what operations it supports and how they behave—but it doesn’t define how it’s implemented. For example, a Queue ADT can be implemented using: So think of ADT as a blueprint or a contract that can be implemented in…

  • Understanding Stack Abstract Data Type (ADT)

    Introduction to Stack ADT In computer science, a Stack is an abstract data type (ADT) that serves as a collection of elements, with two principal operations: A Stack follows the LIFO (Last In, First Out) principle. This means the last item inserted will be the first item removed. It is similar to a deck of…

  • Reversing the linked list in place (without using extra space)

    The goal is to reverse the linked list such that: Approach 1: Reversing a Singly Linked List (SLL) Logic Given a singly linked list like this: We need to reverse it to: Steps to Reverse Initialize three pointers: Traverse the list: Once the loop completes, prev will point to the new head. Java Code to…