Introduction To Data Structure
Introduction To Data Structure
Algorithm
Chapter Four
Introduction to Data
Structures
Introduction
• The first thing that we need to consider when writing programs is the
problem.
• However, the problems that we asked to solve in real life are often
nebulous or complicated. Thus we need to distill such as system down
to its most fundamental parts and describe these parts in a simple,
precise language.
• This process is called abstraction. Problem
• Abstraction is a process of classifying characteristics
as relevant and irrelevant for the particular purpose
at hand and ignoring the irrelevant ones. Abstraction
Model
Cont.
Model
Cont.
• As an example, consider a program that manages the student
records, a program which allows to administer the students in
a class.
• Well, this is too vague a problem. We need to think about, for
example, what student information is needed for the record?
What tasks should be allowed?
• There are many properties we could think of about a student,
such as name, ID, major, email, mailing address, transcripts,
hair color, hobbies, etc.
• Not all these properties are necessary to solve the problem.
Cont.
• To keep it simple, we assume that a student's record includes
the following fields: (1) the student's name and (2) ID.
• The three simplest operations performed by this program
include
• (1) adding a new student to the class,
• (2) searching the class for a student, given some
information of the student, and
• (3) deleting a student who has dropped the class.
These three operations can be furthermore defined as below:
Cont.
• ADD (stu_record): This operation adds the given student record to
the collection of student records.
• SEARCH (stu_record_id): This operation searches the collection
of student records for the student whose ID has been given.
• DELETE (stu_record_id): This operation deletes the student
record with the given ID from the collection.
Cont.
• Now, we have modeled the problem in its most abstract form:
listing the types of data we are interested in and
the operations that we would like to perform on the data.
• We have not discussed anything about how these student
records will be stored in memory and how these operations
will be implemented.
• Data structures can be classified into two categories: Linear and non-
linear data structures.
• A data structure that maintains a linear relationship between its
elements, it is called linear data structure. For example, an array
holds the linear relationship between its elements , it is linear data
structure.
• In case of non-linear data structure, they maintain hierarchical
relationship between their elements. Consider a tree structure, you can
not define linear relationship between the elements.
Primitive Data Structure Data Structure
Arrays
Tree
Linked List
Graphs
Stacks
Queue
Linear Data Structures
In linear data structure the elements are stored in sequential order.