The document provides an overview of different data structures and their types. It discusses linear data structures like arrays, linked lists, stacks and queues as well as non-linear structures like trees and graphs. Common operations on different data structures are also mentioned. The document further describes abstract data types and how they define the operations that can be performed on data without specifying implementation details.
1. OVERVIEW OF
DATA STRUCTURE AND ITS
TYPES
2/21/2018 BY MS. SHAISTA QADIR 1
PRESENTED BY
Shaista Qadir
Lecturer king khalid university
2. CONTENTS
DEFINITION OF DATA STRUCTURES & ALGORITHM
OVERVIEW OF DATA STRUCTURES
TYPES OF DATA STRUCTURE
LINEAR DATA STRUCTURE
NON-LINEAR DATA STRUCTURE
ABSTRACT DATA TYPE.
2/21/2018 BY MS. SHAISTA QADIR 2
3. DATA STRUCTURES & algorithm
2/21/2018 BY MS. SHAISTA QADIR 3
A data structure is an arrangement of data in a computer’s memory .
Data structures include arrays, linked lists, stacks, binary trees, and
hash tables, among others.
Algorithms manipulate the data in these structures in various ways,
such as searching for a particular data item and sorting the data.
It is a frame-work for storing, retrieving and manipulating data as
per the programming requirements.
It is a logical way of storing data and it also define mechanism of
retrieve data.
Thus, A Data Structure chosen specially for an algorithm, shall make
the algorithm more efficient.
4. Overview of Data Structures
Another way to look at data structures is to focus on their
strengths and weaknesses.
The following Table 1 shows the advantages and disadvantages of
the various data structures.
2/21/2018 BY MS. SHAISTA QADIR 4
5. Types of data structure
2/21/2018 BY MS. SHAISTA QADIR 5
6. Primitive data structures
These are data structures that can be manipulated directly
by machine instructions. In java programming language,
the different primitive data structures are
byte 1 byte
short 2 bytes
int 4 bytes
long 8 bytes
2/21/2018 BY MS. SHAISTA QADIR 6
float 4 bytes
double 8 bytes
boolean 1 bit
char 16 bits = 2 bytes
7. NON Primitive data structures
These are data structures that cannot be manipulated
directly by machine instructions.
They are classified into
◦ linear data structures
◦ non-linear data structures.
2/21/2018 BY MS. SHAISTA QADIR 7
8. LINEAR DATA STRUCTURE
The data structures that show the relationship of logical
adjacency between the elements are called linear data
structures.
A linear data structure traverses the data elements
sequentially, in which one data element can be linearly
reached.
Example: Array, Linked list, Stack & Queue linear data
structures.
2/21/2018 BY MS. SHAISTA QADIR 8
9. NON LINEAR DATA STRUCTURE
The data structures that do not show the relationship of
logical adjacency between the elements are called non-
linear data structures.
We cannot linearly reach a data item.
Every data item is attached to several other data items.
Example: Trees, Graphs and Files are non-linear data
structures.
2/21/2018 BY MS. SHAISTA QADIR 9
10. ARRAY
An array is a collection of homogeneous(same) type of
data elements.
An array data structure has a collection of elements and
each element is identified by at least one index.
An array elements are stored in contiguous or adjacent
memory locations
An array Index always start with Zero.
Operations performed on arrays are: Traversing,
Searching, Insertion, Deletion, Sorting & Merging
Representation of array in memory .
2/21/2018 BY MS. SHAISTA QADIR 10
11. ARRAY in java
Arrays in Java use syntax similar to that in C and C++ and not that
different from other languages, but there are nevertheless some
unique aspects to the Java approach.
In many programming languages even object-oriented ones such as
C++, arrays are primitive types, but in Java they’re treated as
objects.
Accordingly, we must use the new operator to create an array:
◦ int[] intArray; // defines a reference to an array
◦ intArray = new int[100]; // creates the array, and
◦ // sets intArray to refer to it
Or we can use the equivalent single-statement approach:
◦ int[] intArray = new int[100];
◦ int intArray[] = new int[100]; // alternative syntax
Arrays have a length field, which can be used to find the size (the
number of elements) of an array:
int arrayLength = intArray.length; // find array size
2/21/2018 BY MS. SHAISTA QADIR 11
12. Vectors in java
A vector is a data structure with a contiguous block of
memory, just like an array.
Storage is managed automatically so that on an attempt
to insert an element into a full vector, a larger memory
block is allocated for the vector, the vector elements are
copied to the new block, and the old block is released.
Vector is thus a flexible array; that is, an array whose size
can be dynamically changed.
Vectors may work when the amount of data isn’t known
in advance.
2/21/2018 BY MS. SHAISTA QADIR 12
13. Vectors in java
Vector implements a dynamic array.
Vector proves to be very useful if you don't know the size
of the array in advance or you just need one that can
change sizes over the lifetime of a program.
The key difference between Arrays and Vectors in Java is
that Vectors are dynamically-allocated.
They aren't declared to contain a type of variable;
instead, each Vector contains a dynamic list of references
to other objects.
The Vector class is found in the java.util package.
2/21/2018 BY MS. SHAISTA QADIR 13
14. CONSTRUCTION OF VECTORS
import java.util package to make the vectors working in
your program.
SYNTAX
◦ Vector vectorname = new Vector(vector capacity, capacity
increment);
Example:
◦ Vector list = new Vector(3,4);
Capacity of the vector list is 3 and capacity increment is 4
We cannot directly store simple data type in a vector.
2/21/2018 BY MS. SHAISTA QADIR 14
15. METHODS IN VECTOR
1- list.addElement(item) : add item to list at the end.
2- list.elementAt(n) : return name of object at n position.
3- list.size() : returns the number of objects in list.
4- list.removeElementAt(n) : removes object at nth position.
5- list.removeElement(item) : removes item from list.
6- list.removeAllElements() : removes all objects from list.
7- list.copyinto(Array) : copy all elements to array.
8- list.insertElementAt(item, n) : inserts item to nth position.
9- list.isEmpty() : returns true if empty otherwise returns false.
10- list.lastElement(Array) : gives last object from the list.
11- list.firstElement(Array) : gives first object from the list.
12- list.clear(Array) : it will removes all elements from list.
2/21/2018 BY MS. SHAISTA QADIR 15
16. METHODS IN VECTOR
An Example code to insert elements, APPLE and ORANGE in
the vector fruits
import java.util.*;
class VectorExample
{
public static void main(String args[])
{
Vector fruits = new Vector(5,4);
fruits.insertElementAt(“APPLE",0);
fruits.insertElementAt(“ORANGE",1);
}
}
2/21/2018 BY MS. SHAISTA QADIR 16
17. LINKED LIST
A Linked list is a linear collection of data elements .It
has two part one is info and other is link part.
info part stores information/Data and link part stores
address of next node.
Operations Performed: Traversing, Searching, Insertion
& Deletion
2/21/2018 BY MS. SHAISTA QADIR 17
18. stack (lifo)
A Stack is a list of elements in which an element may be
inserted or deleted at one end which is known as TOP
of the stack.
A Stack also called last in first out (LIFO) system.
Operations Performed:
Push: add an element in stack
Pop: remove an element in stack
2/21/2018 BY MS. SHAISTA QADIR 18
EEE TOP
DDD
CCC
BBB
AAA
19. queue (fifo)
A Queue also called first in first out (FIFO) system.
A queue is a linear list of element in which insertion can
be done at one end which is known as rear and deletion
can be done at other end which is known as front.
Operations Performed:
Insertion : add a new element in queue.
Deletion: Removing an element in queue.
2/21/2018 BY MS. SHAISTA QADIR 19
21. TREE
A Tree data structure has a collection of nodes starting
at the root node.
Each node has a value and a list of child nodes.
Data in a particular node can be reached non-linearly.
Operations Performed: Traversing, Searching, Insertion
& Deletion
2/21/2018 BY MS. SHAISTA QADIR 21
22. graph
Data sometimes contain a relationship between pairs of
elements which is not necessarily hierarchical in nature.
For example, an airline flies only between cities
connected by lines.
Operations Performed: Traversing, Searching, Insertion
& Deletion
2/21/2018 BY MS. SHAISTA QADIR 22
23. abstract data type
(ADT)
2/21/2018 BY MS. SHAISTA QADIR 23
An abstract data type (ADT) is defined as a mathematical
model of the data objects that make up a data type as well
as the functions that operate on these objects.
An item specified in terms of operations is called an
abstract data type.
Roughly speaking, it’s a way of looking at a data structure:
focusing on what it does and ignoring how it does its job.
Examples: Stack, Queue, etc
24. abstract data type
(ADT)
2/21/2018 BY MS. SHAISTA QADIR 24
• To write a program, a programmer should
•first specify each task in terms of input, output,
operations performed on input, the rules associated
with the operations.
•After this the implementation of the program may
start.
• Abstract Data Type is defined in terms of data items and
the associated operations and not its implementation.
• In Java it is in the form of an ‘Interface’
• Interfaces are similar to classes and contain abstract
method or signatures.
• Methods in an Interface are defined by the class which
implements the Interface.
25. abstract data type
(ADT)
2/21/2018 BY MS. SHAISTA QADIR 25
• EXAMPLE
public interface Valuable
{
public boolean isValuable ();
}
public class Gold implements Valuable
{
public boolean isValuable ()
{
return true;
}
}
Interface Class Valuable
Has Abstract method
isValuable
Implementation Class Gold.
The method isValuable() is
implemented here.