Skip to main content

Command Palette

Search for a command to run...

Learning DSA with Java

Updated
6 min readView as Markdown

A focused 15-day plan can give you a fast, practical start in data structures and algorithms (DSA) using Java. The goal of this plan is not to make you an expert in two weeks, but to give you a solid foundation, hands-on practice on common problem patterns, and a repeatable study routine so you can continue improving confidently after day 15.

Prerequisites

  • Comfortable with Java basics: classes, methods, arrays, loops, conditionals.

  • Basic knowledge of OOP and common libraries (java.util).

  • A coding environment (IDE or editor) and access to a problem site (LeetCode/HackerRank/GeeksforGeeks/etc.).

Study approach (daily routine)

  • 90–120 minutes/day if possible: 30–40 min study of concepts, 40–60 min solving 2–4 problems, 10–20 min review.

  • Focus on problem patterns, not memorizing solutions. After solving, analyze time/space complexity and alternative approaches.

  • Write clean Java: use appropriate collections, avoid unnecessary boxing/unboxing, and test edge cases.

15-day plan (high-level) Day 1 — Getting set up + Arrays & Strings

  • Concepts: arrays, 2D arrays, basic string operations.

  • Practice: reverse array, two-sum variant, rotate array, string palindrome, substring search.

  • Java tips: use char[] for heavy string manipulation; Arrays utility methods.

Day 2 — Two-pointer & Sliding window patterns

  • Concepts: two pointers, sliding window for subarray problems.

  • Practice: pair-sum variants, longest substring without repeating chars, max subarray with constraint.

  • Java tips: HashMap/HashSet for window counting.

Day 3 — Sorting & Searching basics

  • Concepts: common sorts (Arrays.sort uses Dual-Pivot QuickSort/TimSort for objects), binary search pattern.

  • Practice: implement binary search, search in sorted rotated array, merge sorted arrays.

  • Java tips: Arrays.sort for primitives/objects; Collections.sort for lists.

Day 4 — Linked Lists

  • Concepts: singly/doubly lists, pointers, cycle detection, reversing a list.

  • Practice: reverse linked list, detect/remove cycle, merge two sorted lists.

  • Java tips: implement node class; avoid excessive object creation in tight loops.

Day 5 — Stacks & Queues

  • Concepts: LIFO/FIFO uses, monotonic stacks, queue operations, deque.

  • Practice: valid parentheses, next greater element, sliding-window max (deque).

  • Java tips: use ArrayDeque for stack/queue (better than Stack/LinkedList for performance).

Day 6 — Recursion fundamentals

  • Concepts: recursion, recursion vs iteration, base cases, recursion depth.

  • Practice: factorial-like problems, backtracking introduction (subset generation).

  • Java tips: watch recursion depth and prefer iterative approaches if depth is large.

Day 7 — Trees (binary trees)

  • Concepts: tree traversals (inorder, preorder, postorder), recursion on trees, BFS.

  • Practice: max depth, level order traversal, invert binary tree.

  • Java tips: use Queue for BFS (LinkedList or ArrayDeque).

Day 8 — Binary Search Trees & tree problems

  • Concepts: BST properties, insertion/search, common patterns (LCA).

  • Practice: validate BST, kth smallest element, serialize/deserialize basics.

Day 9 — Heaps & PriorityQueue

  • Concepts: min/max heaps, top-k problems, merging sorted streams.

  • Practice: kth largest element, merge k sorted lists (use PQ).

  • Java tips: PriorityQueue default is min-heap; provide comparator for max-heap.

Day 10 — Hashing & Hash Tables

  • Concepts: HashMap/HashSet usage, collision intuition, frequency maps.

  • Practice: group anagrams, longest consecutive sequence, two-sum variants.

  • Java tips: prefer primitive arrays when keys are small-range integers; use computeIfAbsent for grouping.

Day 11 — Graph basics (representations) + BFS/DFS

  • Concepts: adjacency list/matrix, directed/undirected graphs, BFS, DFS.

  • Practice: connected components, shortest path (unweighted), detect cycle in directed graph.

  • Java tips: represent graph as List or Map<Integer, List>.

Day 12 — Graph algorithms continued (topological sort, Dijkstra)

  • Concepts: topological sort (Kahn/DFS), Dijkstra for weighted shortest path basics.

  • Practice: topological ordering, shortest path using PQ.

  • Java tips: use long for distances if weights can sum large.

Day 13 — Dynamic Programming (intro)

  • Concepts: memoization vs tabulation, overlapping subproblems, optimal substructure.

  • Practice: Fibonacci w/ memo, climb stairs, knapsack simple version.

  • Java tips: use arrays for DP table; avoid recursion for large states to prevent stack overflow.

Day 14 — Advanced DP patterns

  • Concepts: subsequences, intervals, DP on strings, state design.

  • Practice: longest increasing subsequence (n log n), longest common subsequence, edit distance (if time).

  • Java tips: use binary-search based LIS approach for optimal complexity.

Day 15 — Mock contest + review + next steps

  • Do a timed set of 3 problems from easy/medium/hard (choose problems that cover studied topics).

  • Review mistakes, refactor solutions, write clean explanations and complexity analysis.

  • Plan next 30/90 day learning: deeper graph algorithms, advanced DP, system design, competitive practice.

Daily problem targets and difficulty

  • Days 1–3: mostly easy; aim 3–5 problems/day.

  • Days 4–10: mix easy/medium; 2–4 problems/day focusing on pattern mastery.

  • Days 11–14: medium problems, 2–3/day, with one longer DP/graph problem.

  • Day 15: 1-3 problems in timed mode as a mock contest.

Java practical tips and templates

  • Fast input for contest-style problems: Use BufferedReader + StringTokenizer or Scanner for simplicity (BufferedReader faster).

  • Common template structure: public class Solution { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader)); // parse input // call solver methods } // helper methods and DS implementations }

  • Collections note: prefer primitive arrays when possible (int[]); use ArrayList when dynamic sizing required, but watch boxing costs in tight loops.

  • Avoid java.util.Stack; prefer ArrayDeque for stack/queue use.

  • When using recursion, consider converting to iterative or increasing JVM stack size only if necessary.

How to practice effectively

  • Read problem statement carefully; write examples and edge cases before coding.

  • After solving, write a short explanation (1–3 sentences) of approach and complexity.

  • Re-solve problems you struggled with after 3–7 days to reinforce patterns.

  • Keep a notebook (digital or paper) of patterns and key idioms in Java.

Suggested resources

  • Algorithm textbooks: (e.g., Sedgewick’s Algorithms in Java) for in-depth study.

  • Problem sites: LeetCode, HackerRank, Codeforces, GeeksforGeeks for practice and tutorials.

  • Java docs: Oracle/Java API docs for collections and concurrency basics.

Measuring progress

  • Track problems solved per topic and accuracy.

  • Time yourself occasionally on 2–3 problems to measure speed improvements.

  • After 15 days, aim to consistently solve medium problems in 45–60 minutes and easy problems in 10–25 minutes.

Next steps after day 15

  • Keep a 30/60/90 day plan: increase problem difficulty, participate in contests, implement data structures from scratch, and study advanced topics (segment trees, tries, suffix arrays, flow algorithms).

  • Contribute solutions with explanations (blog posts or GitHub repo) to solidify learning.

Final note Consistency matters more than cramming. Use these 15 days to build reliable habits: learn a concept, apply it to problems, analyze mistakes, and repeat. With disciplined practice and focused review, Java + DSA skills will grow quickly beyond this starter plan.

DSA in Java

Part 1 of 1