UNIT I - Data Structures: Introduction and Overview
1. Definition of Data Structures:
A data structure is a way of organizing and storing data in a computer so that it can be accessed and
modified efficiently.
Types: Primitive (int, char), Non-primitive (Arrays, Lists, Stacks, Queues, Trees, Graphs)
2. Elementary Data Organization:
Basic ways of storing and organizing data: Variables, Constants, Pointers, Arrays.
Example:
int a = 10;
int arr[5] = {1, 2, 3, 4, 5};
3. Data Structures and Operations:
Operations: Insertion, Deletion, Traversal, Searching, Sorting.
Example:
for (int i = 0; i < 5; i++) { printf("%d ", arr[i]); }
4. Abstract Data Types (ADT):
ADT is a model that defines a data type by its behavior (operations), not implementation.
Example: Stack ADT (push, pop), Queue ADT (enqueue, dequeue)
5. Algorithms:
A finite set of instructions to solve a problem.
Example (Linear Search):
int linearSearch(int arr[], int size, int key) {
for(int i = 0; i < size; i++) {
if(arr[i] == key) return i;
}
return -1;
6. Complexity of Algorithms:
Time Complexity - Time taken with input size
Space Complexity - Memory used
Linear Search: O(n)
7. Time-Space Trade-Off:
Improving time may use more space and vice versa.
Example: Hash tables - more memory, faster search.
8. Preliminaries: Mathematical Notations and Functions:
Used to express algorithm behavior: O(1), O(log n), O(n), O(n^2)
Example:
int sum(int n) { return (n * (n + 1)) / 2; }
9. Algorithmic Notations:
Standard representations like pseudocode or flowcharts.
Pseudocode (Factorial):
function factorial(n):
if n == 0 then return 1
else return n * factorial(n - 1)
10. Control Structures:
Flow control in code: Sequential, Conditional (if, else), Looping (for, while)
Example:
if (a > b) { printf("A is greater"); }
11. Asymptotic Notations:
Used to describe efficiency: Big O (O), Omega (Omega), Theta (Theta)
Examples:
Linear Search - O(n), Binary Search - O(log n), Bubble Sort - O(n^2)