This document discusses different data structures used in computer programming including arrays, pointers, trees, stacks, queues, and graphs. It provides examples of each structure and describes their basic operations like traversing, searching, inserting, and deleting. Key data structures covered are linear arrays, two-dimensional arrays, trees for maintaining employee records and representing algebraic expressions, stacks using push and pop operations, queues as first-in first-out lists, and graphs for non-hierarchical relationships.
2. Data Structures
• The logical or mathematical model of a
particular organization of data is called a data
structure.
• The model must be rich enough in structure
to mirror the actual relationships of the data
in the real world.
• The structure should be simple enough that
one can effectively process the data when
necessary.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
2
3. Data Structures
• The simplest type of data structure is a linear
(or one-dimensional) array.
A[1], A[2], A[3], . . . . . , A[N]
• A two-dimensional array is a collection of
similar data called matrices in mathematics,
and tables in business applications.
A[1, 1], A[1, 2], A[1, 3], . . . . . , A[28, 4]
• Another way is to have a separate array for
salespeople and an entry (called a pointer) in
the customer file.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
3
6. Data Structures: Trees
• Data frequently contain a hierarchical
relationship between various elements. The
data structure which reflects the relationship
is called a rooted tree graph or, simply, a tree.
• Examples –
1. Maintaining an employee personnel record
with SSN, Name, Address, Age, Salary,
Dependents.
2. Algebraic expression (2x + y)(a – 7b)3
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
6
7. Data Structures: Trees
Maintaining an employee personnel record with
SSN, Name, Address, Age, Salary, Dependents.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
7
10. Data Structures: Trees
• Data frequently contain a hierarchical
relationship between various elements. The
data structure which reflects the relationship
is called a rooted tree graph or, simply, a tree.
• Examples –
1. Maintaining an employee personnel record
with SSN, Name, Address, Age, Salary,
Dependents.
2. Algebraic expression (2x + y)(a – 7b)3
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
10
11. Data Structures: Stack
• A stack, also called a last-in-first-out (LIFO)
system, is a linear list in which insertions and
deletions can take place only at one end,
called the top.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
11
12. Data Structures: Stack
• Special terminology is used for two basic
operations associated with stacks:
• “Push” is the term used to insert an element
into a stack.
• “Pop” is the term used to delete an element
from a stack.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
12
15. Data Structures: Queue
• A queue, also called a first-in-first-out (FIFO)
system, is a linear list in which deletions can
take place only at one end of the list (front)
and insertion at other end (rear).
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
15
16. Data Structures: Graph
• The data structure which can reflects non-
hierarchical relationship is called a graph.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
16
17. Data Structure Operations
1. Traversing: Accessing each record exactly
once so that certain items in the record may
be processed.
2. Searching: Finding the location of the record
with a given key value, or finding the
locations of all records which satisfy one or
more conditions.
3. Inserting: Adding a new record to the
structure.
4. Deleting: Removing a record from the
structure.
Computer Programming - Pankaj
Debbarma, TIT, Narsingarh
17