SlideShare a Scribd company logo
1 of 78
Lists, Stacks, Queues, Trees, Hash Tables Basic Data Structures
Contents ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Abstract Data Types ,[object Object],[object Object],[object Object],[object Object]
Basic Data Structures ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What Is a List?
The List ADT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static and Linked Lists
Static List ,[object Object],[object Object],[object Object],[object Object],[object Object],0 1 2 3 4 5 6 7 8 11 7 18 14 L 5 2 33 47 3
Linked List ,[object Object],[object Object],[object Object],[object Object],[object Object],11 next 7 next 18 next 14 next head null
Linked List (2) ,[object Object],11 next prev head tail 7 next prev 18 next prev 14 next prev null null
Using the ArrayList   class
The  java.util.ArrayList  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  ArrayList  Class ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  ArrayList  Class(2) ,[object Object],[object Object],[object Object],[object Object],List list = new ArrayList(); list. a dd(5); // Add integer value list. a dd("some string"); // Add string value int firstElement = ((Integer)(list.get(0))).intValue(); String secondElement = (String)list.get(1);  Integer[] arr = list.toArray(new Integer[list.size()]);
What are Generics ,[object Object],[object Object],[object Object],List<String> list = new ArrayList<String>(); String s = new String(&quot; li1 &quot;); list.add(s); list.add(5); // This will cause compile time error Specifies that String is actual type of this  List 5 is not a String
Primes[n..m] – Example ,[object Object],public static ArrayList<Integer>   getPrimes(int start, int end) { List<Integer> primesList =    new ArrayList<Integer>(); for (int num = start; num <= end; num++) { boolean prime = true; for (int div = 2; div <= Math.sqrt(num); div++) { if (num % div == 0) { prime = false; break; } } if (prime) { primesList.add(num); } } return primesList; }
Primes[n..m] Live Demo
Union and Intersection of Lists – Example public static Integer[] union(Integer[] firstArr, Integer[] secondArr) { List<Integer> union = new ArrayList<Integer>(); for (Integer item : firstArr) { union.add(item); } for (Integer item : secondArr) { if (!union.contains(item)) { union.add(item); } } return union.toArray(new Integer[union.size()]); } //Example continues...
Union and Intersection of Lists – Example(2) public static Integer[] intersect(Integer[] firstArr, Integer[] secondArr) { List<Integer> intersect = new ArrayList<Integer>(); for (Integer item : firstArr) { if (Arrays.binarySearch(secondArr, item) >= 0) { intersect.add(item); } } return intersect.toArray( new Integer[intersect.size()]); }
Union and Intersection Live Demo
What is a Stack?
The Stack ADT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static Stack ,[object Object],[object Object],[object Object],[object Object],[object Object],0 1 2 3 4 5 6 7 8 11 7 18 14 S top
Linked Stack ,[object Object],[object Object],[object Object],11 next 7 next 18 next 14 next top null
Using the  Stack  class
The  Stack  Class – Overview ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  Stack  Class – More Methods ,[object Object],[object Object],[object Object],[object Object],[object Object]
Examples Using the  Stack  class
Stack  – Example ,[object Object],public static void main(String[] args) { Stack<String> stack = new Stack<String>(); stack.push(&quot;1. Ivan&quot;); stack.push(&quot;2. Nikolay&quot;); stack.push(&quot;3. Maria&quot;); stack.push(&quot;4. George&quot;); System.out.println(&quot;Top = &quot; + stack.peek()); while (stack.size() > 0)   { String personName = stack.pop(); System.out.println(personName); } }
Live Demo Using the  Stack  class
Matching Brackets – Example ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Matching Brackets – Solution with a Stack String expression = &quot;1 + (3 + 2 - (2+3) * 4 - ((3+1)*(4-2)))&quot;; Stack<Integer> stack = new Stack<Integer>(); for (int i = 0; i < expression.length(); i++) { char ch = expression.charAt(i); if (ch == '(') { stack.push(i); } else if (ch == ')') { int startIndex = (int) stack.pop(); String contents =  expression.substring(startIndex, i + 1); System.out.println(contents); } }
Live Demo Matching Brackets
What is a Queue?
The Queue ADT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Static Queue ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],0 1 2 3 4 5 6 7 8 11 7 18 14 Q head tail
Linked Queue ,[object Object],[object Object],[object Object],11 next 7 next 18 next 14 next head tail null
Using the  LinkedList  class
The  LinkedList  Class – Overview ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  LinkedList  Class – More Methods ,[object Object],[object Object],[object Object],[object Object],[object Object]
Examples Using the  LinkedList   class
Queue –   Example ,[object Object],public static void main(String[] args) { Queue<String> queue = new LinkedList<String>(); queue.offer(&quot;Message One&quot;); queue.offer(&quot;Message Two&quot;); queue.offer(&quot;Message Three&quot;); queue.offer(&quot;Message Four&quot;); queue.offer(&quot;Message Five&quot;); while (queue.size() > 0) { String msg = queue.poll(); System.out.println(msg); } }
Live Demo Using the  LinkedList   class
Sequence N, N+1, 2*N ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],+1 *2 +1 *2 +1 *2
Sequence – Solution int n = 3; int p = 16; Queue<Integer> queue = new LinkedList<Integer>(); queue.offer(n); int index = 0; while (queue.size() > 0) { index++; int current = queue.poll(); if (current == p) { System.out.println(&quot;Index = &quot; + index); return; } queue.offer(current + 1); queue.offer(2 * current); }
Live Demo Sequence N, N+1, 2*N
Definition, Types of Trees What is Tree?
Trees ,[object Object],[object Object],17 15 14 9 6 5 8 Height = 2 Depth 0 Depth 1 Depth 2
Binary Trees ,[object Object],[object Object],10 17 15 9 6 5 8 “ right child” “ left subtree” “ root” “ left child”
Binary Trees   Traversals ,[object Object],[object Object],[object Object],[object Object],17 19 9 6 12 25
Binary Search Trees ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Binary Search Trees ,[object Object],[object Object],17 19 9 6 12 25
What is a Dictionary (Map)?
The Dictionary (Map) ADT ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is a Hash Table?
Hash Table ,[object Object],[object Object],0 1 2 3 4 5 m-1 ... ... ... ... T h( k ) ... ... ...
Hash Functions and Hashing ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],0 1 2 3 4 5 m-1 ... ... ... ... T h( k ) ... ... ...
Mapping Functions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Collisions in Hash Tables ,[object Object],[object Object],[object Object],[object Object],[object Object]
Collision Resolution - Chaining ,[object Object],h( &quot;Pesho&quot; ) =  4 h( &quot;Lili&quot; ) =  n-1 h( &quot;Kiro&quot; ) =  2   h(&quot;Mimi&quot;) = 1 h(&quot;Ivan&quot;) = 2    null T 0 1 2 3 4 5 n-1 null ... null chaining Kiro Ivan collision null Mimi null Lili null Pesho null
Using the Hash Map  class
The  Hash Map  Class – Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
The  Hash Map  Class – Major Operations ,[object Object],[object Object],[object Object],[object Object],[object Object]
The  Hash Map  Class – More Operations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Examples Using the  HashMap  Class
Hashtable - Example Map<String, Integer> studentsMarks = new HashMap<String, Integer>(); studentsMarks.put(&quot;Ivan&quot;, 4); studentsMarks.put(&quot;Peter&quot;, 6); studentsMarks.put(&quot;Maria&quot;, 6); studentsMarks.put(&quot;George&quot;, 5); int peterMark = studentsMarks.get(&quot;Peter&quot;); studentsMarks.remove(&quot;Peter&quot;); System.out.println(&quot;Is Peter in the hash table: &quot; + studentsMarks.containsKey(&quot;Peter&quot;)); for (Map.Entry<String, Integer> studentMark : studentsMarks.entrySet()) { System.out.printf(&quot;%s --> %d%n&quot;, studentMark.getKey(), studentMark.getValue()); }
Live Demo Using the  HashMap  Class
Counting Words in a Text String s = &quot;Welcome to our Java course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in Java&quot;; String[] words = s.split(&quot;[ ,.]&quot;); Map<String, Integer> wordsCount = new HashMap<String, Integer>(); for (String word : words)  if (!&quot;&quot;.equalsIgnoreCase(word)) { int count = 1; if (wordsCount.containsKey(word))  count += wordsCount.get(word); wordsCount.put(word, count); } for (String word : wordsCount.keySet()) System.out.printf(&quot;%s --> %d%n&quot;, word, wordsCount.get(word));
Live Demo Counting Words in a Text
Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Basic Data Structures Questions?
Exercises ,[object Object],[object Object],[object Object]
Exercises (2) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises (3) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises (4) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises (7) ,[object Object],[object Object],[object Object],[object Object],[object Object],This is the TEXT. Text, text, text – THIS TEXT! Is this the text?
Exercises (5) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Exercises (6) ,[object Object],0 0 0 x 0 x 0 x 0 x 0 x 0 * x 0 x 0 0 x 0 0 0 0 0 0 0 x x 0 0 0 0 x 0 x 3 4 5 x u x 2 x 6 x u x 1 * x 8 x 10 2 x 6 7 8 9 3 4 5 x x 10 4 5 6 x u x

More Related Content

What's hot

Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures BasicsDurgaDeviCbit
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using Ccpjcollege
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1Kumar
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureRai University
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)swajahatr
 
ADT STACK and Queues
ADT STACK and QueuesADT STACK and Queues
ADT STACK and QueuesBHARATH KUMAR
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructuresNguync91368
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)Elavarasi K
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structuresKuber Chandra
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in Onejehan1987
 

What's hot (20)

Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Data structures
Data structuresData structures
Data structures
 
Datastructure
DatastructureDatastructure
Datastructure
 
Data structures
Data structuresData structures
Data structures
 
Data structures Basics
Data structures BasicsData structures Basics
Data structures Basics
 
Data Structure Using C
Data Structure Using CData Structure Using C
Data Structure Using C
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
 
Data structure lecture 1
Data structure lecture 1Data structure lecture 1
Data structure lecture 1
 
Bca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structureBca ii dfs u-1 introduction to data structure
Bca ii dfs u-1 introduction to data structure
 
linked list (c#)
 linked list (c#) linked list (c#)
linked list (c#)
 
Data structures
Data structuresData structures
Data structures
 
Data structures using c
Data structures using cData structures using c
Data structures using c
 
LectureNotes-06-DSA
LectureNotes-06-DSALectureNotes-06-DSA
LectureNotes-06-DSA
 
ADT STACK and Queues
ADT STACK and QueuesADT STACK and Queues
ADT STACK and Queues
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
2 a stacks
2 a stacks2 a stacks
2 a stacks
 
Data Structures (CS8391)
Data Structures (CS8391)Data Structures (CS8391)
Data Structures (CS8391)
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Data structure and algorithm All in One
Data structure and algorithm All in OneData structure and algorithm All in One
Data structure and algorithm All in One
 

Viewers also liked

7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its typesNavtar Sidhu Brar
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and AlgorithmDhaval Kaneria
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
linked list
linked listlinked list
linked listAbbott
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil duttAnil Dutt
 
5 Array List, data structure course
5 Array List, data structure course5 Array List, data structure course
5 Array List, data structure courseMahmoud Alfarra
 
Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)Adam Mukharil Bachtiar
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)raj upadhyay
 
data structure and algorithms
data structure and algorithmsdata structure and algorithms
data structure and algorithmsibrar ahmad
 
‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism‫‫Chapter4 Polymorphism
‫‫Chapter4 PolymorphismMahmoud Alfarra
 

Viewers also liked (20)

7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil7. Tree - Data Structures using C++ by Varsha Patil
7. Tree - Data Structures using C++ by Varsha Patil
 
Data structure and its types
Data structure and its typesData structure and its types
Data structure and its types
 
Introduction to data structures and Algorithm
Introduction to data structures and AlgorithmIntroduction to data structures and Algorithm
Introduction to data structures and Algorithm
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
L6 structure
L6 structureL6 structure
L6 structure
 
01 05 - introduction xml
01  05 - introduction xml01  05 - introduction xml
01 05 - introduction xml
 
linked list
linked listlinked list
linked list
 
Introduction to data structure by anil dutt
Introduction to data structure by anil duttIntroduction to data structure by anil dutt
Introduction to data structure by anil dutt
 
‫Chapter3 inheritance
‫Chapter3 inheritance‫Chapter3 inheritance
‫Chapter3 inheritance
 
Method overloading
Method overloadingMethod overloading
Method overloading
 
5 Array List, data structure course
5 Array List, data structure course5 Array List, data structure course
5 Array List, data structure course
 
3 Array operations
3   Array operations3   Array operations
3 Array operations
 
Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)Data Structure (Introduction to Data Structure)
Data Structure (Introduction to Data Structure)
 
Data structures
Data structuresData structures
Data structures
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
Trees data structure
Trees data structureTrees data structure
Trees data structure
 
Graphs data Structure
Graphs data StructureGraphs data Structure
Graphs data Structure
 
Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)Tree Traversals (In-order, Pre-order and Post-order)
Tree Traversals (In-order, Pre-order and Post-order)
 
data structure and algorithms
data structure and algorithmsdata structure and algorithms
data structure and algorithms
 
‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism‫‫Chapter4 Polymorphism
‫‫Chapter4 Polymorphism
 

Similar to Basic data-structures-v.1.1

16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structuresmaznabili
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.pptsoniya555961
 
Collections generic
Collections genericCollections generic
Collections genericsandhish
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks QueuesIntro C# Book
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresArthik Daniel
 
Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Aijaz Ali Abro
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdffreddysarabia1
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 

Similar to Basic data-structures-v.1.1 (20)

16 Linear data structures
16 Linear data structures16 Linear data structures
16 Linear data structures
 
01-intro_stacks.ppt
01-intro_stacks.ppt01-intro_stacks.ppt
01-intro_stacks.ppt
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 
Collections generic
Collections genericCollections generic
Collections generic
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
Java Collections Framework
Java Collections FrameworkJava Collections Framework
Java Collections Framework
 
Lec2
Lec2Lec2
Lec2
 
Array properties
Array propertiesArray properties
Array properties
 
Aj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructuresAj unit2 notesjavadatastructures
Aj unit2 notesjavadatastructures
 
Stack linked list
Stack linked listStack linked list
Stack linked list
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Collections and its types in C# (with examples)
Collections and its types in C# (with examples)Collections and its types in C# (with examples)
Collections and its types in C# (with examples)
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1DATASTRUCTURES UNIT-1
DATASTRUCTURES UNIT-1
 
C++ STL 概觀
C++ STL 概觀C++ STL 概觀
C++ STL 概觀
 
stack.ppt
stack.pptstack.ppt
stack.ppt
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
Lec3
Lec3Lec3
Lec3
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 

More from BG Java EE Course (20)

Rich faces
Rich facesRich faces
Rich faces
 
JSP Custom Tags
JSP Custom TagsJSP Custom Tags
JSP Custom Tags
 
Java Server Faces (JSF) - advanced
Java Server Faces (JSF) - advancedJava Server Faces (JSF) - advanced
Java Server Faces (JSF) - advanced
 
Java Server Faces (JSF) - Basics
Java Server Faces (JSF) - BasicsJava Server Faces (JSF) - Basics
Java Server Faces (JSF) - Basics
 
JSTL
JSTLJSTL
JSTL
 
Unified Expression Language
Unified Expression LanguageUnified Expression Language
Unified Expression Language
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Web Applications and Deployment
Web Applications and DeploymentWeb Applications and Deployment
Web Applications and Deployment
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
CSS
CSSCSS
CSS
 
HTML: Tables and Forms
HTML: Tables and FormsHTML: Tables and Forms
HTML: Tables and Forms
 
HTML Fundamentals
HTML FundamentalsHTML Fundamentals
HTML Fundamentals
 
WWW and HTTP
WWW and HTTPWWW and HTTP
WWW and HTTP
 
JavaScript and jQuery Fundamentals
JavaScript and jQuery FundamentalsJavaScript and jQuery Fundamentals
JavaScript and jQuery Fundamentals
 
Creating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSSCreating Web Sites with HTML and CSS
Creating Web Sites with HTML and CSS
 
Processing XML with Java
Processing XML with JavaProcessing XML with Java
Processing XML with Java
 
Introduction to XML
Introduction to XMLIntroduction to XML
Introduction to XML
 
Data Access with JDBC
Data Access with JDBCData Access with JDBC
Data Access with JDBC
 
Introduction to-sql
Introduction to-sqlIntroduction to-sql
Introduction to-sql
 
Introduction to-RDBMS-systems
Introduction to-RDBMS-systemsIntroduction to-RDBMS-systems
Introduction to-RDBMS-systems
 

Recently uploaded

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Recently uploaded (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Basic data-structures-v.1.1

  • 1. Lists, Stacks, Queues, Trees, Hash Tables Basic Data Structures
  • 2.
  • 3.
  • 4.
  • 5. What Is a List?
  • 6.
  • 8.
  • 9.
  • 10.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 18. Union and Intersection of Lists – Example public static Integer[] union(Integer[] firstArr, Integer[] secondArr) { List<Integer> union = new ArrayList<Integer>(); for (Integer item : firstArr) { union.add(item); } for (Integer item : secondArr) { if (!union.contains(item)) { union.add(item); } } return union.toArray(new Integer[union.size()]); } //Example continues...
  • 19. Union and Intersection of Lists – Example(2) public static Integer[] intersect(Integer[] firstArr, Integer[] secondArr) { List<Integer> intersect = new ArrayList<Integer>(); for (Integer item : firstArr) { if (Arrays.binarySearch(secondArr, item) >= 0) { intersect.add(item); } } return intersect.toArray( new Integer[intersect.size()]); }
  • 21. What is a Stack?
  • 22.
  • 23.
  • 24.
  • 25. Using the Stack class
  • 26.
  • 27.
  • 28. Examples Using the Stack class
  • 29.
  • 30. Live Demo Using the Stack class
  • 31.
  • 32. Matching Brackets – Solution with a Stack String expression = &quot;1 + (3 + 2 - (2+3) * 4 - ((3+1)*(4-2)))&quot;; Stack<Integer> stack = new Stack<Integer>(); for (int i = 0; i < expression.length(); i++) { char ch = expression.charAt(i); if (ch == '(') { stack.push(i); } else if (ch == ')') { int startIndex = (int) stack.pop(); String contents = expression.substring(startIndex, i + 1); System.out.println(contents); } }
  • 33. Live Demo Matching Brackets
  • 34. What is a Queue?
  • 35.
  • 36.
  • 37.
  • 38. Using the LinkedList class
  • 39.
  • 40.
  • 41. Examples Using the LinkedList class
  • 42.
  • 43. Live Demo Using the LinkedList class
  • 44.
  • 45. Sequence – Solution int n = 3; int p = 16; Queue<Integer> queue = new LinkedList<Integer>(); queue.offer(n); int index = 0; while (queue.size() > 0) { index++; int current = queue.poll(); if (current == p) { System.out.println(&quot;Index = &quot; + index); return; } queue.offer(current + 1); queue.offer(2 * current); }
  • 46. Live Demo Sequence N, N+1, 2*N
  • 47. Definition, Types of Trees What is Tree?
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53. What is a Dictionary (Map)?
  • 54.
  • 55. What is a Hash Table?
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61. Using the Hash Map class
  • 62.
  • 63.
  • 64.
  • 65. Examples Using the HashMap Class
  • 66. Hashtable - Example Map<String, Integer> studentsMarks = new HashMap<String, Integer>(); studentsMarks.put(&quot;Ivan&quot;, 4); studentsMarks.put(&quot;Peter&quot;, 6); studentsMarks.put(&quot;Maria&quot;, 6); studentsMarks.put(&quot;George&quot;, 5); int peterMark = studentsMarks.get(&quot;Peter&quot;); studentsMarks.remove(&quot;Peter&quot;); System.out.println(&quot;Is Peter in the hash table: &quot; + studentsMarks.containsKey(&quot;Peter&quot;)); for (Map.Entry<String, Integer> studentMark : studentsMarks.entrySet()) { System.out.printf(&quot;%s --> %d%n&quot;, studentMark.getKey(), studentMark.getValue()); }
  • 67. Live Demo Using the HashMap Class
  • 68. Counting Words in a Text String s = &quot;Welcome to our Java course. In this &quot; + &quot;course you will learn how to write simple &quot; + &quot;programs in Java&quot;; String[] words = s.split(&quot;[ ,.]&quot;); Map<String, Integer> wordsCount = new HashMap<String, Integer>(); for (String word : words) if (!&quot;&quot;.equalsIgnoreCase(word)) { int count = 1; if (wordsCount.containsKey(word)) count += wordsCount.get(word); wordsCount.put(word, count); } for (String word : wordsCount.keySet()) System.out.printf(&quot;%s --> %d%n&quot;, word, wordsCount.get(word));
  • 69. Live Demo Counting Words in a Text
  • 70.
  • 71. Basic Data Structures Questions?
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.

Editor's Notes

  1. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  2. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  3. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  4. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  5. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  6. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  7. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  8. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  9. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  10. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  11. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  12. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  13. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  14. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  15. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  16. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  17. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  18. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  19. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  20. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  21. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  22. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  23. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  24. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  25. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  26. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  27. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  28. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  29. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  30. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  31. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  32. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  33. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##
  34. * 12/04/10 07/16/96 (c) 2005 National Academy for Software Development - http://academy.devbg.org. All rights reserved. Unauthorized copying or re-distribution is strictly prohibited.* ##