DATA STRUCTURES

A data structure is a special way of arranging information in a computer so that we can use it easily and quickly.
Think of it like a cupboard — you could throw things in randomly, but if you arrange them in shelves, drawers, and boxes, you’ll find and use them much faster.

They are of two types:
1. Linear Data Structure
2. Non – Linear Data Structure

In linear data structures, elements are placed one after another in a sequence.
Each element is connected to the one before and after it.

Features:

  • Easy to set up because memory is arranged in order.
  • Can waste memory if not managed well.

(a) Stack

A stack works like a stack of plates in the kitchen:

  • LIFO (Last In, First Out) → The last plate you put on top is the first one you take off.

Operations:

  • Push → Add an item on top.
  • Pop → Remove the item from the top.

Conditions:

  • Overflow → Stack is full, can’t add more.
  • Underflow → Stack is empty, can’t remove anything.

(b) Queue

A queue works like a line of people waiting for tickets:

  • FIFO (First In, First Out) → The first person in line is served first.

Operations:

  • Enqueue → Add an item at the end (rear) of the line.
  • Dequeue → Remove an item from the front of the line.

Rule:

  • You can’t remove items out of order.

(c) Array

An array is like a row of lockers, each with its own number (index).

  • Stores a fixed number of items of the same type (like only numbers or only words).
  • Items are stored in consecutive memory slots.

Operations:

  • Traversal → Visit each element.
  • Search → Find an element.
  • Insertion → Add a new element.
  • Deletion → Remove an element.
  • Sorting → Arrange elements in order.

In non-linear data structures, elements are not in a straight line.
They can connect in many directions, forming shapes like trees or networks.

Features:

  • More complex to create but use memory well.
  • Can’t go through all elements in just one straight pass.

(a) Tree

A tree is a way to arrange data in levels — like turning a real tree upside down:

  • Root → The top starting point.
  • Parent → A node that has branches.
  • Child → A node that comes from a parent.

Example: Your computer’s folders:

  • Main folder → Subfolder → Files.

Binary Tree → Each parent can have at most two children.

(b) Graph

A graph is a set of points (nodes/vertices) connected by lines (edges).

Example: Social networks:

  • People = nodes.
  • Friendships = edges.

Types of Graphs:

  1. Undirected Graph → Lines have no direction (friendship goes both ways).
  2. Directed Graph → Lines have arrows (one-way connections, like “follow” on Instagram).

Cycles:

  • A path that loops back to the start.
  • Example: A → B → C → A.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top