Introduction
• Data structuresare methods of organizing and
storing data in a computer so that it can be used
efficiently.
• How the data is represented means data structure.
Data can be logically and Mathematically model of
a particular organization of data.
• (We are going to store the data into the memory in
some order that is called the data structure).
1. Primitive DataStructures:
Definition:
• These are basic data types provided by programming
languages. They are typically used for storing single values.
• The data structures that can be manipulated directly by machine
instructions are called primitive data structures.
• Examples:
– Integer: Whole numbers (e.g., -5, 0, 10).
– Float: Numbers with decimal points (e.g., 3.14, -2.5).
– Character: Single letters, numbers, or symbols (e.g., 'a', '7', '$').
– Boolean: Represents true or false values.
• Pointer: Stores the memory address of another variable.
5.
2. Non-Primitive DataStructures:
Definition:
• These are more complex structures created by combining primitive data
types. They are used to store collections of data and enable more advanced
operations.
• The data structures that cannot be manipulated directly by machine instructions
are called non-primitive data
Examples:
– Array: A collection of elements of the same data type stored in contiguous memory
locations.
– Linked List: A sequence of nodes, where each node contains data and a pointer to the
next node.
– Stack: A LIFO (Last-In, First-Out) structure where elements are added and removed from
the same end.
– Queue: A FIFO (First-In, First-Out) structure where elements are added at one end and
removed from the other.
– Tree: A hierarchical data structure with nodes connected in a parent-child relationship.
– Graph: A collection of nodes (vertices) connected by edges, representing relationships
between data items.
– Hash Table: A data structure that uses a hash function to map keys to their corresponding
values.
6.
3. Linear vs.Non-Linear:
Non-primitive data structures can be further
classified as linear or non-linear.
• Linear: Elements are arranged in a sequential
order, like in an array, linked list, stack, or
queue.
• Non-linear: Elements are not arranged in a
sequence, like in a tree or graph.
7.
What are theoperations that can be performed on data structures?
The various operations performed on data
structures are:
• Traversing
• Inserting
• Deleting
• Searching
• Sorting
8.
• Insertion: Addinga new element to the data structure.
• Deletion: Removing an existing element from the data
structure.
• Traversal: Visiting each element in the data structure, often
for processing.
• Searching: Locating a specific element within the data
structure.
• Sorting: Arranging the elements in a specific order (e.g.,
ascending or descending).
• Merging: Combining two or more data structures of the same
type into a single structure.
9.
What is traversing?
•The process of accessing each item exactly once
so that it can be processed and manipulated is
called traversal.
• Example,
– Print array elements // Output 10 20 30 40 50
– Display each item in the list // Output 10 20 30 40 50