You are on page 1of 20

PRIMITIVE VS.

NON PRIMITIVE

The main difference between primitive and non-


primitive data types are: Primitive types are predefined
(already defined) in Java. ... A primitive type has
always a value, while non-primitive types can be
null . A primitive type starts with a lowercase letter,
while non-primitive types starts with an uppercase
letter.

Linear vs. Non-Linear

In a linear data structure, data elements are arranged in a


linear order where each and every elements are attached
to its previous and next adjacent. In a non-linear data
structure, data elements are attached in hierarchically
manner. ... In linear data structure, data elements can be
traversed in a single run only.

Linear Data Structure: Linked List, Stack, Queue,


Array

Linear data structures


 Data structure whose element(objects) are sequential and
ordered in a way so that:

 there is only one first element and has only one next element,

 there is only one last element and has only one previous


element, while

 all other elements have a next and a previous element

Linear data structures


(examples)
 Arrays

 Strings

 Stack

 Queue

 Lists

LINKED LIST

A linked list is a sequence of data structures, which are


connected together via links.
Linked List is a sequence of links which contains
items. Each link contains a connection to another link.
Linked list is the second most-used data structure after
array. Following are the important terms to understand
the concept of Linked List.
 Link − Each link of a linked list can store a data
called an element.
 Next − Each link of a linked list contains a link to
the next link called Next.
 LinkedList − A Linked List contains the
connection link to the first link called First.

Linked List Representation


Linked list can be visualized as a chain of nodes,
where every node points to the next node.

As per the above illustration, following are the


important points to be considered.
 Linked List contains a link element called first.
 Each link carries a data field(s) and a link field
called next.
 Each link is linked with its next link using its next
link.
 Last link carries a link as null to mark the end of
the list.
Types of Linked List
Following are the various types of linked list.
 Simple Linked List − Item navigation is forward
only.
 Doubly Linked List − Items can be navigated
forward and backward.
 Circular Linked List − Last item contains link of
the first element as next and the first element has
a link to the last element as previous.

Basic Operations
Following are the basic operations supported by a list.
 Insertion − Adds an element at the beginning of
the list.
 Deletion − Deletes an element at the beginning of
the list.
 Display − Displays the complete list.
 Search − Searches an element using the given
key.
 Delete − Deletes an element using the given key.
Stack
- is a container of objects that are inserted and
removed according to the last-in-first-out (LIFO)

principle.

• Objects can be inserted at any time, but only the last

(the most-recently inserted) object can be removed.

• Inserting an item is known as “pushing” onto the

stack. “Popping” off the stack is synonymous with

removing an item.

public int size();

Queue Datastructure Using Array

A queue data structure can be implemented


using one dimensional array. The queue
implemented using array stores only fixed
number of data values. The implementation of
queue data structure using array is very
simple. Just define a one dimensional array of
specific size and insert or delete the values
into that array by using FIFO (First In First
Out) principle with the help of
variables 'front' and 'rear'. Initially both 'front'
and 'rear' are set to -1. Whenever, we want to
insert a new value into the queue, increment
'rear' value by one and then insert at that
position. Whenever we want to delete a value
from the queue, then delete the element
which is at 'front' position and increment 'front'
value by one.

Queue Operations using Array


Queue data structure using array can be
implemented as follows...

Before we implement actual operations, first


follow the below steps to create an empty
queue.
 Step 1 - Include all the header files which
are used in the program and define a
constant 'SIZE' with specific value.
 Step 2 - Declare all the user defined
functions which are used in queue
implementation.
 Step 3 - Create a one dimensional array
with above defined SIZE (int
queue[SIZE])
 Step 4 - Define two integer
variables 'front' and 'rear' and initialize
both with '-1'. (int front = -1, rear = -1)
 Step 5 - Then implement main method by
displaying menu of operations list and
make suitable function calls to perform
operation selected by the user on queue.
Arrays
 A sequential group of objects of the same type

 Predefined (static) size

 Can access/modify any element of the array


 Array examples:

 double[] array = new double[10];

 char[] word = {'h', 'e', 'l', 'l', 'o'};

int[][] 2darray = new int[3][3];


Hierarchical data
structures: Tree, Heap,
Trie

Hierarchical data is a data structure


when items are linked to each other
in parent-child relationships in an
overall tree structure. Think of data
like a family tree, with grandparents,
parents, children, and grandchildren
forming a hierarchy of connected data.
TREE
A tree structure is an algorithm for placing and
locating files (called records or keys) in a database.
The algorithm finds data by repeatedly making choices
at decision points called nodes. A node can have as
few as two branches (also called children), or as many
as several dozen.
HEAP
a heap is a specialized tree-based data
structure which is essentially an almost
complete[1] tree that satisfies the heap
property: in a max heap, for any
given node C, if P is a parent node of C, then
the key (the value) of P is greater than or
equal to the key of C. In a min heap, the key
of P is less than or equal to the key of C.
[2]
 The node at the "top" of the heap (with no
parents) is called the root node.

The heap is one maximally efficient


implementation of an abstract data
type called a priority queue, and in fact,
priority queues are often referred to as
"heaps", regardless of how they may be
implemented. In a heap, the highest (or
lowest) priority element is always stored at
the root. However, a heap is not a sorted
structure; it can be regarded as being partially
ordered. A heap is a useful data structure
when it is necessary to repeatedly remove the
object with the highest (or lowest) priority.

A common implementation of a heap is


the binary heap, in which the tree is a binary
tree (see figure). The heap data structure,
specifically the binary heap, was introduced
by J. W. J. Williams in 1964, as a data structure
for the heapsort sorting algorithm.[3] Heaps are
also crucial in several efficient graph
algorithms such as Dijkstra's algorithm. When a
heap is a complete binary tree, it has a smallest
possible height—a heap with N nodes and for
each node a branches always has
loga N height.

TRIE
A Trie is a special data structure used
to store strings that can be visualized
like a graph. It consists of nodes and
edges. Each node consists of at max 26
children and edges connect each parent
node to its children. ... Actually, Tries
are generally used on groups of strings,
rather than a single string.
Other Data Structures:
HashMap, Graph, Matrix

A HashMap (or hash table) is a data structure that


maps keys to values for highly efficient lookup.
There are a number of ways to implement this data
structure. This post is about the simple implementation
of HashMaps in Java using an array of a linked list.
GRAPH
A Graph in the data structure can be
termed as a data structure consisting
of data that is stored among many
groups of edges(paths) and vertices
(nodes), which are interconnected.
Graph data structure (N, E) is structured
with a collection of Nodes and Edges.
Both nodes and vertices need to be
finite.
Matrix
A matrix is a two-dimensional data
structure and all of its elements are of
the same type. A data frame is two-
dimensional and different columns may
contain different data types, though all
values within a column must be of the
same data type and all columns must
have the same length.

You might also like