Skip to content

masum-mir/ds-algorithms

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Data Structure & Algorithms


๐Ÿ“ฆ Array Data Structure

An Array implementation in Java with a wide range of operations for mastering Data Structures & Algorithms step-by-step.
This implementation includes dynamic resizing, multiple insertion and deletion methods, searching, sorting, reversing, and more.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • Dynamic Resizing (automatic expand & shrink)
  • Insertion
    • At beginning
    • At end
    • At specific position
    • Multiple elements at specific position
  • Deletion
    • From beginning
    • From end
    • From specific position
    • By element (first occurrence)
    • By element (all occurrences)
  • Searching
    • Linear Search
    • Binary Search (Iterative & Recursive)
  • Sorting
    • Built-in Arrays.sort()
    • Bubble Sort
    • Quick Sort
  • Other Utilities
    • Traverse (print elements)
    • Reverse array
    • Find max and min
    • Copy array

๐Ÿงฎ Time Complexity

Operation Complexity
Append (Add to end) O(1)
Insert/Delete/Search O(n)
Binary Search O(log n)
Bubble Sort O(nยฒ)
Quick Sort (Worst Case) O(nยฒ)
Quick Sort (Average Case) O(n log n)

๐Ÿ”— Singly Linked List

A Singly Linked List implementation in Java covering core linked list operations like insertion, deletion, searching, reversing, cycle detection, and merging sorted lists.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • Insertion
    • At beginning
    • At end
    • At specific position
    • After a given node
  • Deletion
    • From beginning
    • From end
    • At specific position
    • By value
  • Reversing
    • Iterative reverse
    • Recursive reverse
  • Searching
    • Search by value
    • Get element at a given position
    • Get nth node from end
  • Advanced
    • Detect cycle (Floyd's Cycle Detection)
    • Remove cycle
    • Find middle node
    • Merge two sorted linked lists

๐Ÿงฎ Time Complexity

Operation Complexity
Insert at beginning/end O(1)
Insert at specific position O(n)
Delete from beginning O(1)
Delete from end/position/value O(n)
Search O(n)
Reverse (iterative/recursive) O(n)
Detect cycle O(n)
Merge sorted lists O(n+m)

๐Ÿ“š Doubly Linked List

A clean and fully functional implementation of a Doubly Linked List in Java, featuring operations such as insertion, deletion, search, size calculation, and bidirectional traversal.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • Insertion

    • At the front (head)
    • At the end (tail)
    • At a specific position
  • Deletion

    • From the front
    • From the end
    • By value (first occurrence)
  • Traversal

    • Forward (iterative & recursive)
    • Backward (iterative & recursive)
  • Size Calculation

    • Iterative
    • Recursive
  • Search for a specific value


๐Ÿงฎ Time Complexity

Operation Complexity
Insert at front/end O(1)
Insert at position O(n)
Delete at front/end O(1)
Delete by value O(n)
Search O(n)
Traversal O(n)

๐Ÿ“ฆ Stack (Array-Based Implementation)

This project implements a Stack data structure using a fixed-size array in Java.
It provides essential stack operations such as push, pop, peek, search, and traversal.
The implementation ensures efficient performance with constant time complexity for core operations and straightforward management of stack capacity.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • push(int data) โ€” Add an element to the top of the stack
  • pop() โ€” Remove and return the top element
  • peek() โ€” Return the top element without removing it
  • search(int data) โ€” Find the 1-based position of an element from the top; returns -1 if not found
  • traverse() โ€” Display all elements from bottom to top
  • isEmpty() โ€” Check if the stack is empty
  • isFull() โ€” Check if the stack is full
  • size() โ€” Get the current number of elements in the stack
  • clear() โ€” Remove all elements from the stack

๐Ÿงฎ Time Complexity

Operation Time Complexity
push O(1)
pop O(1)
peek O(1)
search O(n)
traverse O(n)

๐Ÿ“ฆ Stack with Linked List

This project implements a Stack data structure using a singly linked list in Java.
It supports core stack operations like push, pop, peek, and traversal.
The linked list approach enables dynamic stack size without a fixed capacity limit.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • push(int data) โ€” Insert an element at the top of the stack
  • pop() โ€” Remove and return the top element; returns -1 if the stack is empty
  • peek() โ€” View the top element without removing it; returns -1 if empty
  • traverse() โ€” Display all elements from top to bottom
  • Dynamic Size โ€” No fixed capacity limit (unlike array-based stack)

๐Ÿงฎ Time Complexity

Operation Time Complexity
push O(1)
pop O(1)
peek O(1)
traverse O(n)

๐Ÿ“ฆ Stack Using Queues

This project demonstrates how to implement a Stack data structure using two Queues in Java.
It simulates the Last-In-First-Out (LIFO) behavior of stacks with First-In-First-Out (FIFO) queue operations.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • push(int data) โ€” Add element to the top of the stack (O(1))
  • pop() โ€” Remove and return the top element of the stack (O(n))
  • peek() โ€” View the top element without removing it (O(n))
  • traverse() โ€” Display all stack elements from top to bottom
  • Uses two Queue instances internally to simulate stack behavior

๐Ÿงฎ Time Complexity

Operation Time Complexity
push O(1)
pop O(n)
peek O(n)
traverse O(n)

๐Ÿ“ฆ Circular Queue Using Array

This project implements a Circular Queue data structure using a fixed-size array in Java.
The circular approach optimizes space utilization by reusing emptied slots efficiently.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • enqueue(int data) โ€” Adds an element to the rear of the queue
  • dequeue() โ€” Removes and returns the front element
  • peek() โ€” Retrieves the front element without removing it
  • size() โ€” Returns the current number of elements in the queue
  • clear() โ€” Resets the queue to an empty state
  • traverse() โ€” Prints all elements from front to rear in order

๐Ÿงฎ Time Complexity

Operation Time Complexity
enqueue O(1)
dequeue O(1)
peek O(1)
traverse O(n)

๐Ÿ“ฆ Queue Using Linked List

This project implements a Queue data structure using a singly linked list in Java.
It supports efficient enqueue and dequeue operations in constant time.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • enqueue(int data) โ€” Add element at the rear of the queue
  • dequeue() โ€” Remove element from the front of the queue
  • peek() โ€” View the front element without removing it
  • traverse() โ€” Print all queue elements from front to rear

๐Ÿงฎ Time Complexity

Operation Time Complexity
enqueue O(1)
dequeue O(1)
peek O(1)
traverse O(n)

๐Ÿ“ฆ Queue Using Two Stacks

This project demonstrates how to implement a Queue data structure using two stacks in Java.
It simulates FIFO behavior using LIFO data structures.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • enqueue(int data) โ€” Add element to the queue in O(1) time
  • dequeue() โ€” Remove and return the front element in amortized O(n) time
  • peek() โ€” Return the front element without removing it, O(n) worst case
  • traversal() โ€” Print all elements in queue order

๐Ÿงฎ Time Complexity

Operation Time Complexity
enqueue O(1)
dequeue Amortized O(1) to O(n)
peek Amortized O(1) to O(n)
traversal O(n)

๐Ÿ“ฆ Binary Search Tree (BST)

A simple and efficient implementation of a Binary Search Tree (BST) supporting common operations and traversals.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • Insert, search, and delete nodes
  • In-order, pre-order, post-order, and level-order traversals
  • Calculate tree height
  • Count total nodes and leaf nodes
  • Find minimum and maximum values
  • Check if the tree is:
    • A valid BST
    • Balanced
    • Complete
    • Perfect
    • Full

๐Ÿงฎ Time Complexity

Operation Average Case Worst Case
Insert/Search/Delete O(log n) O(n)
Traversals O(n) O(n)
Height Calculation O(n) O(n)
Tree Property Checks O(n) O(n)

๐Ÿ“ฆ AVL Tree Implementation in Java

A robust AVL Tree (self-balancing Binary Search Tree) implementation in Java that supports efficient insertions, deletions, searches, and tree traversals while maintaining balance through rotations.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ›  Features

  • Self-balancing binary search tree (AVL Tree)
  • Supports insertion, deletion, and search operations โ€” all in O(log n) time
  • Performs rotations (LL, RR, LR, RL) to maintain balance
  • In-order traversal for sorted output
  • ASCII visualization of the tree structure
  • Handles edge cases gracefully (e.g., deleting nodes with zero, one, or two children)

๐Ÿงฎ Time Complexity

Operation Time Complexity
Insert O(log n)
Delete O(log n)
Search O(log n)
Rotation O(1)
Traversal O(n)

๐Ÿ“ฆ QuickSort

A straightforward and efficient implementation of the QuickSort algorithm for sorting integer arrays.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ“Œ Description

QuickSort is a divide-and-conquer sorting algorithm that partitions the array around a pivot element and recursively sorts the sub-arrays. It generally performs faster than simple sorts like bubble sort or insertion sort, especially on large datasets.


๐Ÿงฎ Time Complexity

Case Time Complexity
Best / Avg O(n log n)
Worst O(nยฒ)

๐Ÿ“ฆ BubbleSort

A simple implementation of the Bubble Sort algorithm to sort integer arrays in ascending order.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ“Œ Description

Bubble Sort repeatedly swaps adjacent elements if they are in the wrong order. It continues passes through the list until no swaps are needed, making it a straightforward but less efficient sorting method for large datasets.


๐Ÿงฎ Time Complexity

Case Time Complexity
Best O(n)
Average O(nยฒ)
Worst O(nยฒ)

๐Ÿ“ฆ BinarySearch

A Java class implementing both iterative and recursive versions of the Binary Search algorithm on sorted arrays.

๐Ÿš€ Crafted with Logic & Love by Masum | Keep coding, keep learning โค๏ธ


๐Ÿ“Œ Description

Binary Search efficiently locates a target element in a sorted array by repeatedly dividing the search interval in half, drastically reducing the search time compared to linear search.


๐Ÿงฎ Time Complexity

Case Time Complexity
Best O(1)
Average O(log n)
Worst O(log n)

โœจ Author

Masum
Crafted with Logic & Love | Keep coding, keep learning ๐Ÿš€

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages