Study Material
Study Material
Array :
- a linear data Structure
- storing a fixed size of homogeneous data Types.
- easy to access a random element
- insert : from at specified position, need to shift all the elements to right
side and inserting that element at specified position
- delete : need to shift all the elements to left side after removing an element
limitations:
> cant store heterogenious elements
> size is fixed,once declared cant change
> insertion & deletion operations consume more memory as shifting of elements
> shiftingof elemets sometimes may lead to loss of data
> elemets are stored in continuous memory location.
> if required no of elemets / size is not declared then, array will not be
created.
LinkedList:
- it eliminates the disadvanteags of array
- it is a linear data structure used to store collections of objects
- linkedlist is made up of individual nodes which may present in diff locations.
they need not to be contiguous unlike arrays.
- Linked List : connecting of nodes
- nodes are connected to each other. each node containing two parts, one stores
data, another stores data/address of next connected node.
- the first element in linked list is Head,
- last element in linkedlist is tail
- the link of tail node always points to null. it indicating end of the linked
list
Node :
- can be created by class
- dataMember of datatype variable ;
- nextNodeAddress of Node variable;
LinkedList Syntax:
class LinkedList{
Node head;
Node tail;
}
class Node{
datatype data;
Node next;
}
Stack:
- a linear data structure
- follows LIFO principle ( Last In First Out)
- DSA structure by class:
--> initial top = -1
--> full means : top==maxSize-1
--> empty means : top<0
- push() : to add an element at top/last of the stack
- pop() : to remove most recent added element
- peek() : to see the most recent added element
- isempty() : to check a stack have elements or not
- isFull() : to check a stack have max elements or not
- storing :
int instack = {1,5,8,23,5}
|___5__|
|__23__|
|___8__|
|___5__|
|___1__|
Queue :
- a linear data structure
- follows FIFO principle(First In First Out)
- DSA structure by class:
--> front initial =0;
--> rear initial = -1;
--> full means : rear>=maxSize-1
--> empty means : rear<front
- enqueue() : to add an element at last
- dequeue() : to remove the first most element
- isempty() : to check weather the queue is empty or not
- isfull() : to check weather the queue is full or not
- display() : display elememts from front to rear range
-storing
queue = {1,5,7,3,7};
__________________
front 1 | 5 | 7 | 3 | 7 rear
_________________
Java Collections :
- java has collection framework which provides build in implementations for many
data structures
- a collection is an object that groups multiple elements in single unit.
- collections are used to store, retrieve and manipulate data.
- it's a collection of interfaces & processing data efficiently.
- collection framework standardize the way we store and access the data from
collection and it is part of java.util.packages.
Collecteions
|
|___ Set---> (HashSet,LinkedHashSet,TreeSet)
|
|___List---> (ArrayList,LinkedList,Vector(stack))
|
|___Queue---> (Queue,Dequeue)
--Benefits:
> ready to use classes and algorithms
> reduce programming effort
> increases program speed and quality
> encourages reusability
Generics :
declaration of Collection :
> public interface Collection <E> ....{}
<E> represents this interface is generic....
- E : Element
- K : Key
- N : Number
- T : Type
ArrayList:
Collection---> List ----> ArrayList
| | |
| | |
interface interface Class
LinkedList :
Collection---> List ----> LinkedList
| | |
| | |
interface interface Class
LinkedHashSet :
- arrangement is in order & stores unique elements
- uses combination of hashTables & linkedLists for storing elements
- depends on equals(), hashCode() methods to detect duplicates
- null values are allowed
TreeSet:
- arrangement is in natural order(numerical, alphabetical) & stores unique
elements
- depends on compareTo() methods to detect duplicates
- null values are not allowed
HashMap :
- hashmap is implement of the Map. it doesn't extends collections
- arrangement is not in insertion order
- Key, value pair data
- uses hashTable to store data
- only unoque key data is stored. new key,value is considered
- allows null <key,values>
- some methods are:
-> put(key,value) : to add
-> get(key) : retrieve value of key, returns null if key not present
-> replace(key,oldvalue,newvalue)
-> remove(key) : can remove value by key only , can't remove by value directly
-> isEmpty()
-> size()
-> clear()
-> to traverse : like for loop
---- will use Map.Entry implementation
syntax : for(Map.Entry<Integer,Integer> item : list.entrySet())
--> getKey()
--> getValue()
-> keyset() : returns all key data
syntax: for(Integer i : list.keySet())
-> values() : returns all values data
syntax: for(Integer i : list.values())
Queue Interface: