Chapter 1 Introduction To Data Structure
Chapter 1 Introduction To Data Structure
Chapter 1 Introduction To Data Structure
Traversing
Accessing each record exactly once so that certain items in the record may be
processed.(This accessing or processing is sometimes called 'visiting" the
records.)
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.
Inserting
Adding new records to the structure.
Deleting
Removing a record from the structure.
Types of data structures
Linear Data Structure Non- Linear Data
data structure is said to Structure
be linear if its elements A non-linear structure is
form a sequence, or in mainly used to represent
other words a linear list. data containing a
hierarchical relationship
between elements.
• Array
• Tree
• Stack
• Graph
• Queue
• Linked List
Characteristic of Data Structure
Data Advantages Disadvantages
Structure
Arrays Quick insertion, very fast access if Slow search, Slow deletion,
index is known Fixed size
Ordered Quicker search than unsorted array. Slow insertion and deletion,
Array Fixed size
Stack Provides last-in first-out access Slow access to other items
Queue Provides first-in first-out access Slow access to other items
Linked List Quick insertion and quick deletion Slow search
Binary Trees Quick search, insertion and deletion if Deletion algorithm is complex.
tree remains balance
Hash Table Very fast access if key known, Fast Slow deletion, access slow if
insertion. key not known, inefficient
memory usage
Heap Fast insertion ,deletion. Access to Slow access to other items
largest item
Graph Models' real-world situation Some algorithms are slow and
Data Structure and Algorithms
• Algorithm: An algorithm is a finite set of instructions that
takes some raw data as input and transforms it into
refined data.
• An algorithm is a well-defined list of steps for solving
computational problem.
• Program: Program is an implementation of an algorithm in
some programming language.
• Data Structure: Organization of data needed to solve the
problem.
Algorithmic Problem
Specification of output
Specification of input
as a function of input
Input instance,
Output related to the
adhering to the Algorithm
input as required
specification
• Algorithm prefixAverages2(X):
• Input: An n-element array X of number
• Output: An n-element array A of numbers such that A[i] is
the average of elements x[0],……x[i].
S=0
for i=0 to n
s=s+X[i]
A[i]=s/(i+1)
return array A
Analysis: Running time is O(n)
Asymptotic Notation(terminology)
• Special classes of algorithms:
• Logarithmic: O(log n)
• Linear: O(n)
• Quadratic: O (n2)