Introduction to DataStructures
• Data Structure: Way to organize and store
data efficiently.
• Types: Linear (Arrays, Linked List), Non-linear
(Trees, Graphs).
• Importance: Efficient data handling, faster
algorithms.
3.
Complexity Analysis
• Measuresefficiency of algorithms.
• Time Complexity: Growth of execution time
with input size.
• Space Complexity: Growth of memory usage
with input size.
Arrays & Operations
•Array: Collection of elements stored in
contiguous memory locations.
• Operations: Traversal, Insertion, Deletion,
Updating.
• Applications: Storing lists, matrices,
implementing other DS.
6.
Linear Search
• Checkseach element one by one until target is
found.
• Best Case: Ω(1) → element found at first
position.
• Worst Case: O(n) → element at last or not
found.
• C Program Example:
7.
Binary Search
• Efficientsearching on sorted arrays.
• Divide the array into half, check middle
element.
• Best Case: Ω(1), Worst Case: O(log n).
• C Program Example:
8.
Bubble Sort
• Repeatedlyswaps adjacent elements if they
are in wrong order.
• Complexity: Best O(n), Worst O(n^2).
• C Program Example included.
9.
Selection Sort
• Findsthe minimum element and places it at
correct position.
• Complexity: Always O(n^2).
• Simple but inefficient for large datasets.
10.
Insertion Sort
• Buildssorted array one element at a time.
• Best: O(n), Worst: O(n^2).
• Efficient for small datasets.
11.
Heap Sort
• Usesbinary heap data structure.
• Complexity: O(n log n) for all cases.
• Efficient and widely used.
12.
Shell Sort
• Improvedversion of Insertion Sort using gaps.
• Average complexity: O(n^1.5), Worst: O(n^2).
• Not stable but efficient for medium-sized data.
13.
Comparison of SortingAlgorithms
• Bubble Sort: O(n^2), simple but slow.
• Selection Sort: O(n^2), better for small
datasets.
• Insertion Sort: O(n^2), good for nearly sorted
data.
• Heap Sort: O(n log n), efficient and consistent.
• Shell Sort: O(n^1.5), practical improvement
over insertion sort.
14.
Summary
• Data Structuresform the base of efficient
algorithms.
• Complexity Analysis helps to compare
performance.
• Searching: Linear vs Binary Search.
• Sorting: Bubble, Selection, Insertion, Heap,
Shell.
• Choice depends on input size, dataset nature
& application.