Data_Structures_All_Units_Java_Notes_jntuk
Data_Structures_All_Units_Java_Notes_jntuk
Abstract Data Types (ADTs) define data models and the allowed operations without specifying the
implementation.
class Stack {
int top = -1;
int[] stack = new int[100];
void push(int x) {
if (top < 99) stack[++top] = x;
}
int pop() {
if (top >= 0) return stack[top--];
return -1;
}
int peek() {
return top >= 0 ? stack[top] : -1;
}
}
Searching:
Sorting:
Hashing:
Binary Trees:
class Node {
DATA STRUCTURES - Notes for All Units
int data;
Node left, right;
Node(int value) {
data = value;
left = right = null;
}
}
AVL Trees:
B-Trees:
Concept: If balance > 1 or < -1, use rotations (LL, RR, LR, RL)
class AVLNode {
int key, height;
AVLNode left, right;
AVLNode(int d) {
DATA STRUCTURES - Notes for All Units
key = d;
height = 1;
}
}
Red-Black Trees:
Splay Trees:
Priority Queue:
import java.util.*;
class Example {
public static void main(String[] args) {
PriorityQueue<Integer> pq = new PriorityQueue<>();
pq.add(10);
pq.add(20);
pq.add(5);
while (!pq.isEmpty()) {
System.out.println(pq.poll());
}
}
}