Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 13

PRIMITIVE DATA STRUCTURE

 It stores the data of only one type.


 Primitive data structure will contain some value, i.e., it cannot be NULL.
 The size depends on the type of the data structure.
 It starts with a lowercase character.
 It can be used to call the methods.
Basic Types of Primitive Data Structure:

 Integer: The integer data type contains the numeric values. It contains the whole
numbers that can be either negative or positive. When the range of integer data
type is not large enough then in that case, we can use long.

Output:

 Float: The float is a data type that can hold decimal values. When the precision of
decimal value increases then the Double data type is used.

It stores a decimal value with 6-7 total digits of precision. So, for example,
12.12345 can be saved as a float, but 12.123456789 can't be saved as a float.
When representing a float data type in Java, we should append the letter f to the
end of the data type; otherwise, it will save as double.
The default value of a float in Java is 0.0f. Float data type is used when you want
to save memory and when calculations don't require more than 6 or 7 digits of
precision.

Output:

 Character: is a single character,


that is a letter, a digit, a punctuation mark, a tab, a space or something similar.
A char literal is a single one character enclosed in single quote marks like this
char myCharacter = 'g';
Output:

 Boolean: It is used to store only two possible values, either true or false. It
specifies 1-bit of information and its "size" can't be defined precisely.

The boolean keyword is used with variables and methods. Its default value is false.
It is generally associated with conditional statements.

Output:

NON-PRIMITIVE DATA STRUCTURE


 It is a type of data structure that can store the data of more than one type.
 Can consist of a NULL value.
 size is not fixed.
 It starts with an uppercase character.
 Cannot be used to call the methods.

The non-primitive data structure is further classified into two categories, i.e., linear and
non-linear data structure.

Linear data structure is a sequential type of data structure, and here sequential means
that all the elements in the memory are stored in a sequential manner; for example,
element stored after the second element would be the third element, the element stored
after the third element would be the fourth element and so on. We have different linear
data structures holding the sequential values such as Array, Linked List, Stack, Queue.
Types of linear data structure:
 Array:  a data structure that can hold the elements of same type. It cannot contain
the elements of different types like integer with character. The commonly used
operation in an array is insertion, deletion, traversing, searching.

Output:
 Linked List: A linked list is a data structure where the objects are arranged in a
linear order. Unlike an array, however, in which the linear order is determined by
the array indices, the order in a linked list is determined by a pointer in each object.

Output:
 Stack: a linear data structure that follows the principle of Last In First Out
(LIFO). This means the last element inserted inside the stack is removed first.

In programming terms, putting an item on top of the stack is called push and


removing an item is called pop.

Output:

 Queues: a linear data structure or a collection in Java that stores elements in a


First In, First Out (FIFO) order.
The queue collection has two ends i.e., front & rear. The elements are added at the
rear and removed from the front.

Output:
Non-Linear Data Structure is a form of data structure where the data elements don’t
stay arranged linearly or sequentially. Since the data structure is non-linear, it does not
involve a single level. Therefore, a user can’t traverse all of its elements in a single run.

The non-linear data structure is not very easy to implement as compared to the linear data
structure. The utilization of computer memory is more efficient in this case, for example,
graphs, trees and Hash table.

Types of Non-Linear Data Structure:


 Trees:

 It is defined as a collection of objects or entities known as nodes that are linked


together to represent or simulate hierarchy.
 A non-linear data structure because it does not store in a sequential manner. It
is a hierarchical structure as elements in a Tree are arranged in multiple levels.
 The topmost node is known as a root node. Each node contains some data, and
data can be of any type. In the above tree structure, the node contains the name
of the employee, so the type of data would be a string.
 Each node contains some data and the link or reference of other nodes that can
be called children.
 One of the famous tree data structures is the Binary tree.
Examples here below is a Binary Tree Traversal In order, Preorder and Post order.
Output:

 Graphs: a data structure that stores


connected data. In other words, a graph G (or g) is defined as a set of vertices (V)
and edges (E) that connects vertices. The examples of graph are a social media
network, computer network, Google Maps, etc.

Each graph consists of edges and vertices (also called nodes). Each vertex and


edge have a relation. Where vertex represents the data and edge represents the
relation between them. Vertex is denoted by a circle with a label on them. Edges
are denoted by a line that connects nodes (vertices).
Output:

 Hash Table: a data structure which stores data in an associative manner. In a hash
table, data is stored in an array format, where each data value has its own unique
index value. Access of data becomes very fast if we know the index of the desired
data.
Thus, it becomes a data structure in which insertion and search operations are very
fast irrespective of the size of the data. Hash Table uses an array as a storage
medium and uses hash technique to generate an index where an element is to be
inserted or is to be located from.
Example here below is a Java Hash Table Example: remove()

Output:
Primitive vs non-primitive data structure - javatpoint. (n.d.). www.javatpoint.com. Retrieved
October 1, 2022, from https://www.javatpoint.com/primitive-vs-non-primitive-data-
structure

Java Graph - Javatpoint. (n.d.). www.javatpoint.com. Retrieved October 20, 2022, from
https://www.javatpoint.com/java-graph

Data Structure and Algorithms - Hash Table. (n.d.). Retrieved October 15, 2022, from
https://www.tutorialspoint.com/data_structures_algorithms/hash_data_structure.htm

You might also like