II. Data Structure Basic Concepts
II. Data Structure Basic Concepts
Foundational Tools
Data structures are the foundational tools used to store, organize,
and manage data in a computer system.
Performance Impact
They determine how data is arranged in memory and how Data Structures as Containers
efficiently it can be accessed, modified, or processed.
Folder for Box for Tools Shelf for Books
Efficiency Matters Documents
What is it?
A collection of interfaces and classes that helps in storing and
processing data efficiently.
Framework Structure
Organized hierarchy with interfaces at the top and concrete
implementations below, providing a unified architecture.
List Interface Overview
LinkedList
Uses nodes linked together, efficient for frequent insertions or
Maintains Order Allows Duplicates deletions.
size. complexity).
+ Add Update Remove Get Sort
A B C
→ →
Singly Linked List Doubly Linked List →B →C → null
Each node stores data and a Each node stores data and two
pointer to the next node only. pointers: prev and next. Allows
Traversal is forward only. two-way traversal.
Node Structure
Item 2
push() pop()
+ Add to top
Remove from top
Performance Inheritance
Slower than alternatives in single- Extends Vector class, inheriting all peek() empty()
View top without removing
? Check if stack is empty
threaded cases due to its properties and methods.
synchronization overhead.
Set Interface Overview
Performance Trade-offs
Each implementation offers different performance characteristics for
TreeSet
add, remove, and contains operations.
Sorted in natural order. Uses Red-Black Tree for
automatic sorting.
Elements always sorted
O(log n) time complexity
Does not allow null values
HashSet
B
No Duplicates Unordered A D
C
If you try to add a duplicate, it is The order of elements is not
ignored. Each element must be guaranteed to be the same as
unique. insertion order.
One Null Allowed Efficient Operations = Check with .equals() Handle collisions
Only a single null element can be Average O(1) time complexity for
stored in a HashSet. add, remove, and contains
operations.
LinkedHashSet
A B C D
Maintains Order Unique Elements
Elements are stored in the exact Like all Set implementations, it First Second Third Fourth
order they were added, unlike does not allow duplicate values.
HashSet which is unordered.
HashSet LinkedHashSet
Unordered, slightly faster Ordered, maintains insertion
sequence
TreeMap
Duplicate Values Allowed Sorted by key. Stores key-value pairs in a red-black tree.
Multiple keys can map to the same value without restriction. Keys sorted in ascending order
Does not allow null keys
Efficient Lookups
Designed for fast retrieval of values based on their keys. LinkedHashMap
Maintains insertion order. Stores key-value pairs in the
order they were added.
Key1 → ValueA Key2 → ValueB Key3 → ValueA Preserves insertion order
Allows one null key and multiple null values
HashMap
tailMap()
LinkedHashMap
Add element at the rear of the Remove element from the front of
queue. New elements join at the the queue. The first element in LinkedList PriorityQueue
end of the line. line is processed first. Simple FIFO implementation. Elements ordered by priority
Preserves strict insertion instead of insertion time.
order.
Key
Data
Common Java Order Allows Thread- Features /
Section Structure
Implementations Maintained Duplicates Safe Best Use
Type
Case
Java Collections: HashMap, HashSet, TreeSet and More
1
Neesri
Medium
View Article
View Tutorials