Professional Documents
Culture Documents
Activity 1 - DataStructures
Activity 1 - DataStructures
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:
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:
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.
Output:
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.
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