Data Structures and Algorithms Tutorials | IT Developer
Data Structures & Algorithms - Data Structures Basics
π 1. Basic Concepts in Data Structures
1.1 Data
- Raw facts, figures, or symbols that can be processed to generate meaningful information.
- Example:
- Numbers: 1, 2, 3, 4
- Characters: ‘A’, ‘B’, ‘C’
1.2 Data Structure
- A way of organizing and storing data efficiently.
- Example: Arrays, Linked Lists, Trees, Graphs.
1.3 Data Type
- Classification of data into predefined types.
- Types:
- Primitive Data Types:
int, char, float, bool.
- Derived Data Types:
array, pointer, structure, union.
1.4 Abstract Data Type (ADT)
- A mathematical model for a data structure that defines operations but hides implementation details.
- Example: Stack, Queue, List.
π 2. Operations on Data Structures
2.1 Insertion
- Adding a new element to a data structure.
- Example: Inserting an element in an array at index 2.
2.2 Deletion
- Removing an element from a data structure.
- Example: Deleting an element from a linked list.
2.3 Traversal
- Visiting and processing each element in a data structure.
- Example: Printing all elements in a linked list.
2.4 Searching
- Finding an element in a data structure.
- Example: Binary Search, Linear Search.
2.5 Sorting
- Arranging elements in a particular order (ascending or descending).
- Example: Quick Sort, Merge Sort.
π 3. Complexity Analysis
3.1 Time Complexity
- The time taken by an algorithm as a function of input size.
- Example: O(n), O(log n), O(n²).
3.2 Space Complexity
- The amount of memory used by an algorithm.
- Example: O(1) for constant space, O(n) for linear space.
3.3 Big O Notation (O)
- Represents the worst-case scenario of an algorithm.
- Example: O(n²) for Bubble Sort.
3.4 Omega Notation (Ω)
- Represents the best-case scenario of an algorithm.
3.5 Theta Notation (Θ)
- Represents the average-case scenario of an algorithm.
π 4. Types of Data Structures
4.1 Linear Data Structures
- Elements are arranged sequentially.
- Example: Arrays, Linked Lists, Stacks, Queues.
4.2 Non-Linear Data Structures
- Elements are connected in a hierarchical manner.
- Example: Trees, Graphs.
4.3 Static Data Structures
- Size is fixed during compilation.
- Example: Arrays.
4.4 Dynamic Data Structures
- Size changes during execution.
- Example: Linked Lists.
π 5. Terms Related to Arrays
5.1 Index
- Position of an element in an array, starting from 0.
5.2 One-Dimensional Array
- Elements stored in a single row.
5.3 Multi-Dimensional Array
- Arrays with more than one row/column.
π 6. Terms Related to Linked Lists
6.1 Node
- A unit containing data and a pointer to the next node.
6.2 Head
- The first node in a linked list.
6.3 Tail
- The last node in a linked list (points to NULL).
6.4 Singly Linked List
- Each node has a pointer to the next node.
6.5 Doubly Linked List
- Each node has pointers to both previous and next nodes.
6.6 Circular Linked List
- The last node connects back to the first node.
π 7. Terms Related to Stack
7.1 LIFO (Last In, First Out)
- The last inserted element is removed first.
7.2 Push
- Adds an element to the stack.
7.3 Pop
- Removes the top element from the stack.
7.4 Peek (Top Element)
- Retrieves the top element without removing it.
π 8. Terms Related to Queue
8.1 FIFO (First In, First Out)
- The first inserted element is removed first.
8.2 Enqueue
- Adds an element to the queue.
8.3 Dequeue
- Removes an element from the queue.
8.4 Circular Queue
- The last position connects to the first position.
8.5 Priority Queue
- Elements are dequeued based on priority.
π 9. Terms Related to Trees
9.1 Root
- The topmost node in a tree.
9.2 Parent and Child Nodes
- A node that has sub-nodes is a parent, and sub-nodes are children.
9.3 Leaf Node
9.4 Depth
- Distance from the root node to a specific node.
9.5 Height
9.6 Binary Tree
- Each node has at most two children.
9.7 Binary Search Tree (BST)
- A binary tree where left child < parent < right child.
9.8 AVL Tree
9.9 Heap (Min-Heap, Max-Heap)
- A complete binary tree with heap properties.
π 10. Terms Related to Graphs
10.1 Vertex (Node)
- A fundamental unit of a graph.
10.2 Edge
- A connection between two vertices.
10.3 Degree of a Vertex
- The number of edges connected to a vertex.
10.4 Adjacency Matrix
- Matrix representation of a graph.
10.5 Adjacency List
- List representation of a graph.
10.6 Directed vs Undirected Graph
- Directed Graph: Edges have directions.
- Undirected Graph: Edges do not have directions.
10.7 Weighted Graph
- Edges have weights/costs.
10.8 DFS (Depth-First Search)
- A graph traversal algorithm using a stack.
10.9 BFS (Breadth-First Search)
- A graph traversal algorithm using a queue.
π 11. Hashing and Hash Tables
11.1 Hash Function
- A function that maps data to a fixed-size value.
11.2 Collision
- When two inputs produce the same hash value.
11.3 Chaining
- A technique to handle collisions using linked lists.
11.4 Open Addressing
- A collision handling method where another empty slot is found.