Skip to content

Repository files navigation

Data Structures and Algorithms in Java

This repository provides a comprehensive guide to Data Structures and Algorithms (DSA) implemented in Java. It covers foundational Java concepts, core data structures, sorting and searching algorithms, recursion, backtracking, problem-solving patterns, and LeetCode practice — all organized with theory notes and code implementations.

Table of Contents

  1. Java Basics
  2. Methods (Functions)
  3. Object-Oriented Programming (OOPs)
  4. Data Structures
  5. Sorting Algorithms
  6. Searching Algorithms
  7. Recursion & Backtracking
  8. Key Concepts & Problem Solving Patterns
  9. Dynamic Programming
  10. Time & Space Complexity
  11. Collections Framework
  12. Predefined Classes in Java
  13. Roadmap
  14. Resources

Java Basics

Fundamental Java syntax and constructs for getting started.

Topic Description
Datatype and Variables Primitive types, variable declaration, naming conventions
Operators Arithmetic, relational, logical, bitwise, assignment operators
Conditional Statements If-else, else-if ladder, ternary operator
Switch-Case Statements Switch-case syntax, fall-through, default case
Iterative Statements For, while, do-while, foreach, nested loops, break/continue
Patterns Star patterns and number patterns (Patterns 1–11)

Methods (Functions)

Introduction to methods in Java — definition, parameters, return types, overloading, and recursion.

File / Folder Concepts
CalculatorUsingFunction.java Static methods, Scanner I/O, basic arithmetic
MethodWithParameters.java Methods accepting parameters
MethodWithReturnValue.java Methods returning values
OverloadedMethod.java Method overloading
RecursiveMethod.java Recursive factorial
Basics/ Parameterless methods, factorial, multiplication

Object-Oriented Programming (OOPs)

Core OOP principles and their practical implementations in Java.

Topic Concepts
Basics Classes, objects, fields, methods, getters/setters, encapsulation
Constructors Constructor definition, super(), constructor overloading
Inheritance Single, multilevel, hierarchical inheritance, super keyword
Polymorphism Method overloading (compile-time), method overriding (runtime)
Abstract Classes Abstract classes, abstract methods
Interfaces Interface definition, implementation, default methods, multiple inheritance
Key Concepts Dynamic method dispatch, this vs super, access modifiers
Assessment Number guessing game, Rock-Paper-Scissors game using OOPs

Data Structures

Custom implementations and practical usage of fundamental data structures using Java Collections and from scratch.

Linear Data Structures

Structure Topics Covered
Arrays 1D and 2D arrays, reversal, max subarray sum, diagonal sum, spiral matrix
ArrayList Dynamic arrays, sorting, multi-dimensional lists, subList, synchronization
Linked List Singly linked list, iterative & recursive reversal, middle element, LeetCode top questions
Stack Stack using ArrayList, LinkedList, Collections; applications (parenthesis checker, encoder)
Queue Queue using Array, LinkedList, Collections; circular queue, dynamic queue
String String comparison, manipulation, StringBuilder operations, LeetCode string problems

Non-Linear Data Structures

Structure Topics Covered
HashMap Hashing, load factor, rehashing, iteration, operations (Group Anagrams, Subarray Sum)
HashSet Set basics, iteration, duplicate removal
Heap (PriorityQueue) Min/Max heap, custom heap implementation, heap sort
Trees Tree building, DFS/BFS traversals, BST, AVL trees, segment tree, diameter, height, node count
Graphs Adjacency list & matrix, BFS/DFS, Dijkstra, Bellman-Ford, Kosaraju, Prim, Tarjan, topological sort

Sorting Algorithms

Implementation and analysis of major sorting algorithms.

Algorithm Complexity Description
Bubble Sort O(n²) Repeatedly swaps adjacent elements
Selection Sort O(n²) Selects minimum element and places it
Insertion Sort O(n²) Builds sorted array one element at a time
Merge Sort O(n log n) Divide and conquer, stable sort
Quick Sort O(n log n) avg Partition-based recursive sort
Heap Sort O(n log n) Uses heap/priority queue
Counting Sort O(n+k) Non-comparison sort for integers
Bucket Sort O(n+k) Distributes elements into buckets

Searching Algorithms

Searching techniques with varying time complexities.

Algorithm Complexity Description
Linear Search O(n) Scans each element sequentially
Binary Search O(log n) Divide and conquer on sorted arrays
Order Agnostic Binary Search O(log n) Works on ascending or descending sorted arrays

Recursion & Backtracking

Recursion fundamentals, recursive sorting, and backtracking problems.

Recursion Concepts

  • Base cases, recursion stack visualization, tail recursion

Recursive Sorting

  • Recursive Bubble Sort, Selection Sort, Merge Sort, Quick Sort

Recursion Problems

  • Sum of digits, reverse number, product of digits, count zeros
  • Patterns using recursion

Subsets, Subsequences & Permutations

  • Subsets of array (with/without duplicates)
  • String subsequences
  • String permutations

Backtracking

  • Maze problems (2-direction, 3-direction, 4-direction, path restrictions)
  • N-Queens problem
  • N-Knights problem
  • Sudoku solver

Key Concepts & Problem Solving Patterns

Essential algorithmic techniques and patterns used in competitive programming and interviews.

Concept Topics Covered
BIT Manipulation Get/Set/Clear/Update bits, fast exponentiation, odd/even optimization
Sliding Window Max sum of subarray of size k
Two Pointer Approach Move zeros, remove duplicates (I & II), find middle of list, palindrome check
Kadane's Algorithm Maximum subarray sum (1D)
Prefix Sum Placeholder for upcoming content
Divide and Conquer Merge sort, quick sort, rotated binary search
Important Algorithms Variable swapping, frequency counter using HashMap, ASCII code lookup

Dynamic Programming

Coming Soon

This section is under development and will cover DP patterns, tabulation, memoization, and common DP problems.

Time & Space Complexity

Detailed theory and reference material for complexity analysis.

  • Best, worst, and average case analysis
  • Complexity classes: O(1), O(log n), O(n), O(n²), O(2ⁿ), O(n!)
  • Time complexity of arrays, linked lists, stacks, queues, hash tables, BSTs, AVL trees
  • Reference PDFs: TimeComplexityAnalysis.pdf, Space Complexity Analysis.pdf

Collections Framework

Practical usage of Java's Collections Framework for data structures.

Component Methods & Usage
List Collections.sort(), reverse(), shuffle(), swap(), fill(), copy(), frequency(), addAll(), nCopies(), synchronizedList()
Stack Stack using java.util.Stack
Queue Queue using LinkedList / PriorityQueue
LinkedList LinkedList operations, reversal using Collections
Set / Map HashMap and HashSet operations with Collections

Predefined Classes in Java

Reference notes for Java wrapper and utility classes.

Class Methods Covered
Arrays sort(), equals(), toString(), binarySearch(), asList(), fill()
Integer parseInt(), valueOf(), toString(), compareTo(), bitCount(), reverse()
Character isLetter(), isDigit(), toUpperCase(), toLowerCase(), charValue()

Roadmap

A visual DSA learning roadmap is available in the Roadmap/ directory (roadmap.pdf) to guide your study progression.

Resources

Contact Information

For questions or support, please contact:

About

Data Structures and Algorithms. A Complete DSA Course For Coding Interviews in Java and C++

Topics

Resources

Stars

22 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages