Land the job you want — prepare
with Real interviews Q&A
Curated interview questions, company-wise guides and coding rounds. Practice mock interviews, improve with feedback, and track your progress.
A Data Structure is a way of organizing and storing data so that it can be accessed and modified efficiently.
Different data structures are used for different purposes depending on the type of operations required.
Data structures help improve performance, memory management, and problem-solving in software applications.
Main Types of Data Structures- Linear Data Structures
- Non-Linear Data Structures
- Static Data Structures
- Dynamic Data Structures
An Array is a linear data structure used to store multiple values in a single variable.
Array elements are stored in contiguous memory locations and accessed using indexes.
Advantages- Fast access using index
- Easy traversal
- Efficient memory usage
const numbers = [10, 20, 30, 40];
console.log(numbers[0]);
numbers.push(50);
console.log(numbers);A Linked List is a linear data structure where each element is called a node.
Each node contains data and a pointer to the next node in the sequence.
Advantages- Dynamic size
- Efficient insertion
- Efficient deletion
- No memory wastage
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
const first = new Node(10);
const second = new Node(20);
first.next = second;
console.log(first);Stack is a linear data structure that follows the LIFO principle.
LIFO means Last In First Out.
Real-Life Examples- Undo functionality
- Browser history
- Function call stack
- Expression evaluation
const stack = [];
stack.push(10);
stack.push(20);
stack.push(30);
console.log(stack.pop());
console.log(stack);Queue is a linear data structure that follows the FIFO principle.
FIFO means First In First Out.
Use Cases- Task scheduling
- Printer queue
- Call center systems
- CPU scheduling
const queue = [];
queue.push("A");
queue.push("B");
queue.push("C");
console.log(queue.shift());
console.log(queue);A Hash Table is a data structure that stores data in key-value pairs.
It uses a hash function to calculate the index where data is stored.
Advantages- Fast searching
- Fast insertion
- Fast deletion
- Efficient data lookup
const user = {
id: 1,
name: "AK",
city: "Delhi"
};
console.log(user.name);
console.log(user.city);A Tree is a hierarchical non-linear data structure consisting of nodes.
The top node is called the root node and child nodes are connected below it.
Applications- File systems
- Databases
- HTML DOM
- Search algorithms
class TreeNode {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
}
const root = new TreeNode(10);
root.left = new TreeNode(5);
root.right = new TreeNode(20);
console.log(root);Binary Search is an efficient searching algorithm used on sorted arrays.
It repeatedly divides the search space into two halves.
Advantages- Fast searching
- Efficient for large datasets
- Reduces comparisons
- Time Complexity O(log n)
function binarySearch(arr, target) {
let left = 0;
let right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) {
return mid;
}
if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
}
}
return -1;
}
console.log(binarySearch([1,2,3,4,5], 4));A Graph is a non-linear data structure consisting of nodes and edges.
Graphs are used to represent relationships between different objects.
Real-Life Examples- Social networks
- Google Maps
- Flight routes
- Recommendation systems
const graph = {
A: ["B", "C"],
B: ["D"],
C: [],
D: []
};
console.log(graph["A"]);