Data Structure Using C
Data Structure Using C
Memory Allocation:
Fixed or Dynamic
Sequential Order: Arrays use contiguous
Size: Some structures,
Elements are arranged in memory allocation,
like arrays, have a fixed
a specific sequence, while linked lists utilize
size, while others, like
allowing for a clear non-contiguous
linked lists, can grow or
beginning and end. memory, with nodes
shrink dynamically.
pointing to each other.
TYPE OF LINEAR DATA STRUCTURE
Stacks:
•Arrays: Definition: A collection that follows the Last
•Definition: A collection of elements stored in In, First Out (LIFO) principle.
contiguous memory locations.
Queues:
•Linked Lists: Definition: A collection that follows the First
• Definition: A series of nodes, where each node In, First Out (FIFO) principle.
contains data and a reference to the next node. Types:
•Types: Simple Queue: Elements are added at
•Singly Linked List: Each node points to the the rear and removed from the front.
next node only. Circular Queue: The end of the queue
•Doubly Linked List: Each node points to both wraps around to the front when there’s
the next and the previous nodes. space.
•Circular Linked List: The last node points back Priority Queue: Elements are removed
to the first node, forming a circle. based on priority rather than the order
they were added.
Characteristics of
Array
These characteristics make arrays
How it works:
2 Contiguous Memory
Allocation: Elements are
stored in contiguous
memory locations, allowing
for efficient access and
manipulation.
Arr[0][0],arr[0][1],arr[0]
[2],arr[1][0],arr[1][1],arr[1][2]
Column-Major Order:
3
• In some languages like Fortran, arrays are
stored in column-major order, where all
elements of the first column are stored
first, followed by the elements of the
second column, and so on.
1. Traversal Operations on Arrays
Definition: Traversal means visiting each element of the array
at least once to perform a specific operation (like printing the
elements). Arrays are one of the simplest and
1 most commonly used data structures.
Let's explore the key
2. Search
operations: Search, Traverse, Insert
Definition: Search involves finding a specific ion, and Deletion.
element in the array. Two common types of
searches are linear search and binary
search.
3. Insertion
2
4. Deletion
decrement, comparison
2D Arrays:
- Declare: int arr[3][4]; or int **arr;
- Initialize:
- Fixed: int arr[3][4] = {{1, 2}, {3, 4},
{5, 6}};
- Dynamic: arr = (int **)malloc(3 *
sizeof(int *));
- Access: arr[i][j] or *(arr + i * cols + j)
POINTERS
• ADVANTAGES • DISADVANTAGES
1. Pointers let you work 1. Using pointers makes
directly with memory, the code more difficult
allowing you to manage to understand and work
data more efficiently. with.
2. Instead of copying big 2. Mistakes with pointers
data like arrays, pointers are often tricky to find
allow you to reference and fix because they
them directly, saving affect low-level memory.
time and memory.
ARRAYS