DSA
Introduction

What is a Data Structure?

A data structure is a way to organize and store data in a computer so it can be used efficiently. It helps in storing, processing, and retrieving data easily.

Uses of Data Structures

Data structures are used in many areas, such as:

  • Databases: Organizing and storing data for quick access.
  • Operating Systems: Managing memory and files.
  • Computer Graphics: Storing and displaying shapes and images.
  • Artificial Intelligence: Representing knowledge and information.

Benefits of Using Data Structures

  • Faster Processing: Helps in quick data storage and retrieval.
  • Easy Modification: Data can be easily changed when needed.
  • Reusable: Can be used in multiple programs.
  • Better Maintenance: Makes programs easier to understand and update.

Types of Data Structures

1. Primitive Data Structures

These are the basic types provided by programming languages:

  • Integer: Whole numbers.
  • Float: Decimal numbers.
  • Character: Single letter or symbol.
  • Boolean: True or false values.
  • String: Sequence of characters.

2. Non-Primitive Data Structures

These store multiple values and can be complex:

Linear Data Structures

Data is arranged in a sequence.

  • Array: A fixed-size collection of elements of the same type.

  • Stack: Follows Last In, First Out (LIFO) order.

  • Queue: Follows First In, First Out (FIFO) order.

  • Linked List: A collection of connected elements using pointers.

    • Static Data Structure: Fixed memory size (e.g., Array).
    • Dynamic Data Structure: Memory size changes during runtime (e.g., Queue, Stack).

Non-Linear Data Structures

Data is arranged in a non-sequential way.

  • Tree: A structure with a parent-child relationship.
  • Graph: A set of nodes (vertices) connected by edges.

Common Data Structures Explained

  1. Array: Stores multiple values in continuous memory locations.
  2. Linked List: Stores data elements connected by pointers.
  3. Stack: A collection where the last added item is removed first (LIFO).
    • Operations: push(), pop(), top(), size(), isEmpty().
  4. Queue: A collection where the first added item is removed first (FIFO).
    • Operations: Enqueue(), Dequeue(), front(), rear(), isFull(), isNull().
  5. Binary Tree: A tree where each node has up to two children.
  6. Binary Search Tree (BST): A tree where the left child contains smaller values and the right child contains larger values.
  7. Heap: A complete binary tree used for fast access to the largest or smallest value.
  8. Hash Table: Uses a special function (hash function) to map keys to values for fast access.
  9. Matrix: A table of numbers arranged in rows and columns.
  10. Trie: A tree-based structure used for fast searching.
  11. Graph: Represents relationships between objects using nodes and edges.