Java & DSA – Interview■Focused Short Notes
CORE JAVA (CRISP)
• Java follows WORA – Write Once Run Anywhere.
• JVM converts bytecode to machine code.
• Heap stores objects, Stack stores method calls & local variables.
• String is immutable; use StringBuilder for changes.
• final: constant / no override / no inheritance.
• static members belong to class, not object.
OOP CONCEPTS
• Encapsulation: private variables + public methods.
• Inheritance: IS■A relationship using extends.
• Polymorphism: method overloading & overriding.
• Abstraction: abstract class or interface.
COLLECTIONS FRAMEWORK
• ArrayList: fast access, slow insert/delete.
• LinkedList: fast insert/delete.
• HashSet: unique elements, unordered.
• HashMap: key■value, O(1) average lookup.
• TreeMap: sorted keys, O(log n).
TIME COMPLEXITY
• O(1): Constant time.
• O(log n): Binary search.
• O(n): Linear traversal.
• O(n log n): Merge sort.
• O(n²): Nested loops.
SEARCHING & SORTING
• Linear Search: O(n).
• Binary Search: O(log n), sorted array required.
• Bubble Sort: O(n²), stable.
• Selection Sort: O(n²), not stable.
• Merge Sort: O(n log n), extra space.
• Quick Sort: O(n log n) avg, O(n²) worst.
STACK & QUEUE
• Stack: LIFO (push, pop, peek).
• Queue: FIFO (enqueue, dequeue).
• Applications: undo, recursion, BFS.
LINKED LIST
• Singly, Doubly, Circular types.
• Insertion/Deletion: O(1).
• Traversal/Search: O(n).
TREES
• Binary Tree: max 2 children.
• BST: left < root < right.
• Inorder traversal gives sorted order in BST.
• Traversal: Inorder, Preorder, Postorder.
GRAPHS
• Represented using adjacency list or matrix.
• BFS uses Queue.
• DFS uses Stack/Recursion.
• Used in shortest path, networks.
RECURSION & DP
• Recursion: function calls itself.
• Base case prevents infinite calls.
• DP = recursion + memoization.
• Optimizes overlapping subproblems.
INTERVIEW QUICK TIPS
• Always explain time & space complexity.
• Prefer collections over arrays.
• Handle edge cases (null, empty).
• Write clean and readable code.