Data Structures & Algorithms β Quick Revision Sheet
Data Structures and Algorithms (DSA) is the study of organizing data efficiently and solving problems using step-by-step procedures.
Common complexities:
Collection of elements stored in continuous memory locations.
Elements stored in nodes, each pointing to the next node.
Last In First Out. Example: Undo operation.
First In First Out. Example: Ticket counter.
Stores key-value pairs for fast access.
Definition: Arrays are collections of elements stored in contiguous (continuous) memory locations.
int[] arr = {10, 20, 30};
System.out.println(arr[0]); // Output: 10
arr = [10, 20, 30]
print(arr[0])
Definition: A collection of nodes where each node contains data and a reference (pointer) to the next node.
[10] β [20] β [30] β NULL
class Node:
def __init__(self, data):
self.data = data
self.next = None
Definition: Stack follows Last In First Out (LIFO) principle.
Stack stack = new Stack<>();
stack.push(10);
stack.push(20);
stack.pop(); // removes 20
stack = []
stack.append(10)
stack.append(20)
stack.pop()
Definition: Queue follows First In First Out (FIFO) principle.
Queue queue = new LinkedList<>();
queue.add(10);
queue.add(20);
queue.remove(); // removes 10
from collections import deque
queue = deque()
queue.append(10)
queue.append(20)
queue.popleft()
Definition: A data structure that stores key-value pairs and provides fast access using hashing.
HashMap map = new HashMap<>();
map.put("A", 1);
map.put("B", 2);
System.out.println(map.get("A"));
data = {"A": 1, "B": 2}
print(data["A"])
π Keep learning. Keep building. Keep improving.