Start with foundational topics and move to advanced concepts, learning how each data structure and algorithm works with examples and code snippets.
Arrays are a fundamental data structure where elements are stored in contiguous memory locations. Each element can be accessed directly by using its index.
// Python Example - Arrays
arr = [10, 20, 30, 40, 50]
print("Original array:", arr)
# Access element at index 2
print("Element at index 2:", arr[2])
# Modify element at index 1
arr[1] = 25
print("Updated array:", arr)
A Linked List is a linear data structure where elements are not stored in contiguous memory locations. Each element points to the next one.
// Python Example - Linked List
class Node:
def __init__(self, data):
self.data = data
self.next = None
# Create nodes
node1 = Node(10)
node2 = Node(20)
node3 = Node(30)
# Link nodes
node1.next = node2
node2.next = node3
# Traverse linked list
current = node1
while current:
print(current.data, end=" -> ")
current = current.next
A Stack is a linear data structure that follows the Last In First Out (LIFO) principle. It supports operations such as push, pop, and peek.
A Queue is a linear data structure that follows the First In First Out (FIFO) principle. It supports operations such as enqueue, dequeue, and front.
A Tree is a hierarchical data structure where each node has zero or more children nodes. The root node is the topmost node of the tree.
A Graph is a collection of nodes (vertices) and edges that connect pairs of nodes. It can be used to model various real-world scenarios like networks.
Sorting algorithms arrange elements of a list in a specific order (ascending or descending). Common sorting algorithms include Bubble Sort, Merge Sort, and Quick Sort.