SlideShare a Scribd company logo
3
Most read
4
Most read
12
Most read
DSA
Datastructure and algorithms for coding interviews
By
Saran Kumar R
Apply appropriate datastructure for efficiency
• ArrayList
• LinkedList
• HashSet
• TreeSet
• LinkedHashSet
• PriorityQueue(heap)
• HashMap
• TreeMap
• LinkedHashMap
• Stack
• Queue
ArrayList
ArrayList<Integer> a=new ArrayList<>();
when to use?
• unknown size.
• Accessing and retrieving elements
LinkedList
LinkedList<Integer> a=new LinkedList<>();
When to use?
• modifications in an list
• unknown size
Hash Set
HashSet<Integer> a=new HashSet<>();
When to use?
• To check if an element exist or not.
• To eliminate duplicates.
Tree Set
TreeSet<Integer> a=new TreeSet<>();
When to use?
• you want elements to be sorted.
LinkedHashSet
LinkedHashSet<String> a=new LinkedHashSet<>();
When to use?
• you want to access elements in the inserted order.
PriorityQueue(heap)
PriorityQueue<Integer> a=new PriorityQueue<>();
When to use?
• To find kth largest,smallest or most frequent,less frequent elements faster.
• Quick sort -> O(nlogn) heap-> O(n)
Hash Map
HashMap<String,Integer> a=new HashMap<>();
When to use?
• To store in key:value pairs.
• Store frequency of elements.
TreeMap
TreeMap<Integer,String> a=new TreeMap<>();
When to use?
• When you want keyset to be sorted.
a.put(3,”sk”); output: {1=D3, 2=yj, 3=sk, 7=yk}
a.put(2,”yj”);
a.put(7,”yk”);
a.put(1,”D3);
LinkedHashMap
LinkedHashMap<Integer,String> a=new LinkedHashMap<>();
When to use?
When you want keyset to be in inserted order.
a.put(3,”sk”); output: {3=sk, 2=yj, 7=yk, 1=D3}
a.put(2,”yj”);
a.put(7,”yk”);
a.put(1,”D3);
Stack
Stack<Integer> a=new Stack<>();
When to use?
• DFS
• Backtracking
Queue
Queue<Integer> a=new Queue<>();
When to use?
• BFS
• Level order traversal in tree

More Related Content

PPTX
Data structure and algorithm using java
PPT
Java 8 Streams
PPTX
core java
PPTX
Strings in Java
PPTX
Data Structures in Python
PDF
Rest API Automation with REST Assured
PPT
Assembler
Data structure and algorithm using java
Java 8 Streams
core java
Strings in Java
Data Structures in Python
Rest API Automation with REST Assured
Assembler

What's hot (20)

PDF
Android Programming Basics
PDF
Python Basics | Python Tutorial | Edureka
PPT
JQuery introduction
PPTX
Introduction to the basics of Python programming (part 1)
PPTX
Loops PHP 04
PPT
Collection Framework in java
PPTX
List in python
PPTX
PDF
Présentation de PHP
PPTX
Ajax and Jquery
PDF
Learn 90% of Python in 90 Minutes
PDF
Introduction to Web Services
PDF
MEAN Stack
PDF
Java Collections API
PDF
Free django
PDF
jQuery -Chapter 2 - Selectors and Events
PDF
Get started python programming part 1
PDF
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
Android Programming Basics
Python Basics | Python Tutorial | Edureka
JQuery introduction
Introduction to the basics of Python programming (part 1)
Loops PHP 04
Collection Framework in java
List in python
Présentation de PHP
Ajax and Jquery
Learn 90% of Python in 90 Minutes
Introduction to Web Services
MEAN Stack
Java Collections API
Free django
jQuery -Chapter 2 - Selectors and Events
Get started python programming part 1
LetSwift 2017 - 토스 iOS 앱의 개발/배포 환경
Ad

Similar to DSA in java (20)

PPT
Java Collection slide ppt presentation..
PPTX
Javasession7
PPTX
Collections framework in java
PPT
Java Collections Framework
PPTX
collectionsframework210616084411 (1).pptx
PPT
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
PPT
Data structures
PPTX
Hash based inventory system
PPTX
Ts project Hash based inventory system
PPT
sets and maps
PPTX
Java collections
PPTX
Java Collections.pptx
PPTX
Collections in .net technology (2160711)
PPT
description of Collections, seaching & Sorting
PDF
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
PPTX
Hashing Introduction , hash functions and techniques
PPTX
Java 103 intro to java data structures
Java Collection slide ppt presentation..
Javasession7
Collections framework in java
Java Collections Framework
collectionsframework210616084411 (1).pptx
tutorial 10 Exploring Arrays, Loops, and conditional statements.ppt
Data structures
Hash based inventory system
Ts project Hash based inventory system
sets and maps
Java collections
Java Collections.pptx
Collections in .net technology (2160711)
description of Collections, seaching & Sorting
Lecture 8_٠٨٣٣٣٦taiz unvercity object oreinted programming.pdf
Hashing Introduction , hash functions and techniques
Java 103 intro to java data structures
Ad

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Spectroscopy.pptx food analysis technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
Big Data Technologies - Introduction.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Spectroscopy.pptx food analysis technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Mobile App Security Testing_ A Comprehensive Guide.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Programs and apps: productivity, graphics, security and other tools
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Understanding_Digital_Forensics_Presentation.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
Spectral efficient network and resource selection model in 5G networks
Advanced methodologies resolving dimensionality complications for autism neur...

DSA in java