SlideShare a Scribd company logo
1 of 9
Download to read offline
Sekolah Tinggi Teknologi Telematika Telkom
Laporan Praktikum
Kecerdasan Buatan
Modul 2 (Implementasi DFS dan BFS)
Dosen Pengampu: Muhammad Zidny Naf’an,S.Kom., M.Kom.
Nama Mahasiswa
NIM
Kelas
: Deprilana Ego Prakasa
: 14102055
: S1 IF B 2014
VERTEX
Vertex.java
package graph;
public class Vertex {
public char label;
public boolean wasVisited;
public Vertex(char label){
this.label = label;
wasVisited = false;
}
}
GRAPH
Graph.java
package graph;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class Graph {
private char search;
private final int MAX_VERTS =20;
private Vertex vertexList[];
private int adjMat[][];
private int nVertexs;
private Queue openQueue;
private Stack openStack;
public Graph(){
vertexList = new Vertex[MAX_VERTS];
adjMat = new int [MAX_VERTS][MAX_VERTS];
adjMat = new int [MAX_VERTS][MAX_VERTS];
nVertexs = 0;
openQueue = new LinkedList();
openStack = new Stack<String>();
}
public Graph(char search){
this.search = search;
vertexList = new Vertex[MAX_VERTS];
adjMat = new int[MAX_VERTS][MAX_VERTS];
nVertexs = 0;
openQueue = new LinkedList();
openStack = new Stack<String>();
}
public void addVertex(char label){
vertexList[nVertexs++] = new Vertex(label);
}
public void addEdge(int from, int to){
adjMat[from][to]=1;
adjMat[to][to]=1;
}
public void displayVertex(int v){
System.out.print(vertexList[v].label);
}
public void depthFirstSearch(){
vertexList[0].wasVisited = true;
openStack.push(0);
int v2 = 0;
while(!openStack.isEmpty()){
Integer v1 = (Integer) openStack.pop();
displayVertex(v1);
if(vertexList[v1].label == search)
break;
while((v2 = getAdjUnvisitedVertexDFS(v1)) != -1){
vertexList[v2].wasVisited = true;
openStack.add(v2);
}
}
for (int j=0; j<nVertexs; j++){
vertexList[j].wasVisited = false;
}
}
public void breadthFirstSearch(){
vertexList[0].wasVisited = true;
openQueue.add(0);
int v2;
while(!openQueue.isEmpty()){
Integer v1 = (Integer) openQueue.remove();
displayVertex(v1);
if(vertexList[v1].label == search)
break;
while((v2 = getAdjUnvisitedVertexBFS(v1)) !=-1){
vertexList[v2].wasVisited = true;
openQueue.add(v2);
}
}
for(int j=0; j<nVertexs; j++){
vertexList[j].wasVisited = false;
}
}
public int getAdjUnvisitedVertexBFS(int v){
for(int j = 0;j<nVertexs; j++){
if(adjMat[v][j]==1 && vertexList[j].wasVisited == false){
return j;
}
}
return -1;
}
public int getAdjUnvisitedVertexDFS(int v){
for(int j = nVertexs-1;j>=0; j--){
if(adjMat[v][j]==1 && vertexList[j].wasVisited == false){
return j;
}
}
return -1;
}
}
MAIN
Main.java
package graph;
public class Main {
public static void main(String[] args) {
Graph theGraph = new Graph();
theGraph.addVertex('A'); //0
theGraph.addVertex('B'); //1
theGraph.addVertex('C'); //2
theGraph.addVertex('D'); //3
theGraph.addVertex('E'); //4
theGraph.addEdge(0, 1); //AB
theGraph.addEdge(1, 2); //BC
theGraph.addEdge(0, 3); //AD
theGraph.addEdge(3, 4); //DE
System.out.println("Breadth First Search:");
System.out.println("Visits: ");
theGraph.breadthFirstSearch();
System.out.println();
System.out.println("Depth First Search:");
System.out.println("Visits: ");
theGraph.depthFirstSearch();
System.out.println();
// TODO code application logic here
}
}
SOAL LATIHAN
1.1
MAIN
Main.java
package graph;
public class Main {
public static void main(String[] args) {
Graph theGraph = new Graph();
theGraph.addVertex('A'); //0
theGraph.addVertex('B'); //1
theGraph.addVertex('C'); //2
theGraph.addVertex('D'); //3
theGraph.addVertex('E'); //4
theGraph.addVertex('F'); //5
theGraph.addVertex('G'); //6
theGraph.addVertex('H'); //7
theGraph.addVertex('I'); //8
theGraph.addVertex('J'); //9
theGraph.addEdge(0, 1); //AB
theGraph.addEdge(0, 2); //AC
theGraph.addEdge(0, 3); //AD
theGraph.addEdge(1, 6); //BG
theGraph.addEdge(1, 7); //BH
theGraph.addEdge(3, 4); //DE
theGraph.addEdge(3, 5); //DF
theGraph.addEdge(4, 8); //EI
theGraph.addEdge(4, 9); //EJ
System.out.println("Breadth First Search:");
System.out.println("Visits: ");
theGraph.breadthFirstSearch();
System.out.println();
System.out.println("Depth First Search:");
System.out.println("Visits: ");
theGraph.depthFirstSearch();
System.out.println();
// TODO code application logic here
}
}
2.1 Gambar Vertex dan Edge dari bentuk Graph pada Main Pertama
3.1 Bentuk adjacency matrix-nya
A B C D E
A 0 1 0 1 0
B 0 0 1 0 0
C 0 0 0 0 0
D 0 0 0 0 1
E 0 0 0 0 0
4.1 Apakah output dari Breadth First Search berdasarkan Graph tersebut,
Ya sesuai dengan Grapnya
5.1 Apakah output dari Depth First Search berdasarkan Graph tersebut,
Ya sesuai dengan Grapnya
A
B D
C
E
6.1 Implementasi Graph berikut pada kode yang anda buat
Main.java
package graph;
public class Main {
public static void main(String[] args) {
Graph theGraph = new Graph();
theGraph.addVertex('A'); //0
theGraph.addVertex('B'); //1
theGraph.addVertex('C'); //2
theGraph.addVertex('D'); //3
theGraph.addVertex('E'); //4
theGraph.addVertex('F'); //5
theGraph.addVertex('G'); //6
theGraph.addVertex('H'); //7
theGraph.addVertex('I'); //8
theGraph.addVertex('J'); //9
theGraph.addEdge(0, 1); //AB
theGraph.addEdge(0, 2); //AC
theGraph.addEdge(0, 3); //AD
theGraph.addEdge(1, 6); //BG
theGraph.addEdge(1, 7); //BH
theGraph.addEdge(3, 4); //DE
theGraph.addEdge(3, 5); //DF
theGraph.addEdge(4, 8); //EI
theGraph.addEdge(4, 9); //EJ
System.out.println("Breadth First Search:");
System.out.println("Visits: ");
theGraph.breadthFirstSearch();
System.out.println();
System.out.println("Depth First Search:");
System.out.println("Visits: ");
theGraph.depthFirstSearch();
System.out.println();
// TODO code application logic here
}
}
7.1. Output Breadth First Search untuk Graph No 6
8.1. Output Depth First Search untuk Graph No 6

More Related Content

What's hot

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
 
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification Syntax
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification SyntaxNagios Conference 2013 - BOF Nagios Plugins New Threshold Specification Syntax
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification SyntaxNagios
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Abu Saleh
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Sameer Rathoud
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentMaty Fedak
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Anton Arhipov
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019Gebreigziabher Ab
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMMario Fusco
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3hasi071
 

What's hot (20)

Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Java Generics
Java GenericsJava Generics
Java Generics
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
Java programs
Java programsJava programs
Java programs
 
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
 
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification Syntax
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification SyntaxNagios Conference 2013 - BOF Nagios Plugins New Threshold Specification Syntax
Nagios Conference 2013 - BOF Nagios Plugins New Threshold Specification Syntax
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
TechTalk - Dotnet
TechTalk - DotnetTechTalk - Dotnet
TechTalk - Dotnet
 
Memory Management In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
 
Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())Memory Management C++ (Peeling operator new() and delete())
Memory Management C++ (Peeling operator new() and delete())
 
Learn basics of Clojure/script and Reagent
Learn basics of Clojure/script and ReagentLearn basics of Clojure/script and Reagent
Learn basics of Clojure/script and Reagent
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012Binary patching for fun and profit @ JUG.ru, 25.02.2012
Binary patching for fun and profit @ JUG.ru, 25.02.2012
 
RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019RMI Java Programming Lab Manual 2019
RMI Java Programming Lab Manual 2019
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Lecture no 3
Lecture no 3Lecture no 3
Lecture no 3
 
Java lab 2
Java lab 2Java lab 2
Java lab 2
 

Viewers also liked

Bab 1 pengenalan kecerdasan buatan
Bab 1 pengenalan kecerdasan buatanBab 1 pengenalan kecerdasan buatan
Bab 1 pengenalan kecerdasan buatanMuhammad Delta
 
01 analisa dan perancangan sistem informasi(1)
01 analisa dan perancangan sistem informasi(1)01 analisa dan perancangan sistem informasi(1)
01 analisa dan perancangan sistem informasi(1)Noval Opay
 
Merancang UX di Sale Stock Indonesia
Merancang UX di Sale Stock IndonesiaMerancang UX di Sale Stock Indonesia
Merancang UX di Sale Stock IndonesiaAlvi Syahrina
 
Tugas review jurnal
Tugas review jurnalTugas review jurnal
Tugas review jurnalAndik Irawan
 
Cara Mereview Jurnal
Cara Mereview JurnalCara Mereview Jurnal
Cara Mereview JurnalRumah Studio
 
Makalah fix
Makalah fixMakalah fix
Makalah fixzhu ma
 
Kecerdasan buatan
Kecerdasan buatanKecerdasan buatan
Kecerdasan buatanzhu ma
 

Viewers also liked (10)

Bab 1 pengenalan kecerdasan buatan
Bab 1 pengenalan kecerdasan buatanBab 1 pengenalan kecerdasan buatan
Bab 1 pengenalan kecerdasan buatan
 
01 analisa dan perancangan sistem informasi(1)
01 analisa dan perancangan sistem informasi(1)01 analisa dan perancangan sistem informasi(1)
01 analisa dan perancangan sistem informasi(1)
 
Merancang UX di Sale Stock Indonesia
Merancang UX di Sale Stock IndonesiaMerancang UX di Sale Stock Indonesia
Merancang UX di Sale Stock Indonesia
 
Tugas Kecerdasan Buatan
Tugas Kecerdasan BuatanTugas Kecerdasan Buatan
Tugas Kecerdasan Buatan
 
Tugas review jurnal
Tugas review jurnalTugas review jurnal
Tugas review jurnal
 
Ai 7
Ai 7Ai 7
Ai 7
 
Cara Mereview Jurnal
Cara Mereview JurnalCara Mereview Jurnal
Cara Mereview Jurnal
 
Contoh Review Jurnal
Contoh Review JurnalContoh Review Jurnal
Contoh Review Jurnal
 
Makalah fix
Makalah fixMakalah fix
Makalah fix
 
Kecerdasan buatan
Kecerdasan buatanKecerdasan buatan
Kecerdasan buatan
 

Similar to Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa

Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docxajoy21
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfdbrienmhompsonkath75
 
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?Henri Tremblay
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfMAYANKBANSAL1981
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeDaniel Wellman
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeletonIram Ramrajkar
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleChristopher Curtin
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab FileKandarp Tiwari
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfJUSTSTYLISH3B2MOHALI
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbroncymbron
 
Java Generics
Java GenericsJava Generics
Java Genericsjeslie
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 

Similar to Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa (20)

Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Java oops features
Java oops featuresJava oops features
Java oops features
 
Write a program that reads a graph from a file and determines whether.docx
 Write a program that reads a graph from a file and determines whether.docx Write a program that reads a graph from a file and determines whether.docx
Write a program that reads a graph from a file and determines whether.docx
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
 
Can some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdfCan some one redo this code without the try-catch and an alternative.pdf
Can some one redo this code without the try-catch and an alternative.pdf
 
How to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy CodeHow to Start Test-Driven Development in Legacy Code
How to Start Test-Driven Development in Legacy Code
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
 
My java file
My java fileMy java file
My java file
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
 
Map struct
Map structMap struct
Map struct
 
Map struct
Map structMap struct
Map struct
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Please help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdfPlease help!!I wanted to know how to add a high score to this prog.pdf
Please help!!I wanted to know how to add a high score to this prog.pdf
 
Exercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera CymbronExercícios Netbeans - Vera Cymbron
Exercícios Netbeans - Vera Cymbron
 
Java Generics
Java GenericsJava Generics
Java Generics
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 

More from Deprilana Ego Prakasa

Modul5 deprilana ego-prakasa-14102055_IF-B
Modul5 deprilana ego-prakasa-14102055_IF-BModul5 deprilana ego-prakasa-14102055_IF-B
Modul5 deprilana ego-prakasa-14102055_IF-BDeprilana Ego Prakasa
 
Modul4 deprilana ego-prakasa-14102055_IF-B
Modul4 deprilana ego-prakasa-14102055_IF-BModul4 deprilana ego-prakasa-14102055_IF-B
Modul4 deprilana ego-prakasa-14102055_IF-BDeprilana Ego Prakasa
 
Modul3 deprilana ego-prakasa-14102055_IF-b
Modul3 deprilana ego-prakasa-14102055_IF-bModul3 deprilana ego-prakasa-14102055_IF-b
Modul3 deprilana ego-prakasa-14102055_IF-bDeprilana Ego Prakasa
 
14102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-414102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-4Deprilana Ego Prakasa
 
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasaDeprilana Ego Prakasa
 
Modul2 deprilana ego-prakasa-14102055_if-b
Modul2 deprilana ego-prakasa-14102055_if-bModul2 deprilana ego-prakasa-14102055_if-b
Modul2 deprilana ego-prakasa-14102055_if-bDeprilana Ego Prakasa
 
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4Deprilana Ego Prakasa
 

More from Deprilana Ego Prakasa (20)

Dokumentasi rpl
Dokumentasi rplDokumentasi rpl
Dokumentasi rpl
 
Proposal multimedia-bab-i-ii-iii
Proposal multimedia-bab-i-ii-iiiProposal multimedia-bab-i-ii-iii
Proposal multimedia-bab-i-ii-iii
 
Tugas dsm kelompok11
Tugas dsm kelompok11Tugas dsm kelompok11
Tugas dsm kelompok11
 
Modul5 deprilana ego-prakasa-14102055_IF-B
Modul5 deprilana ego-prakasa-14102055_IF-BModul5 deprilana ego-prakasa-14102055_IF-B
Modul5 deprilana ego-prakasa-14102055_IF-B
 
Modul4 deprilana ego-prakasa-14102055_IF-B
Modul4 deprilana ego-prakasa-14102055_IF-BModul4 deprilana ego-prakasa-14102055_IF-B
Modul4 deprilana ego-prakasa-14102055_IF-B
 
Modul3 deprilana ego-prakasa-14102055_IF-b
Modul3 deprilana ego-prakasa-14102055_IF-bModul3 deprilana ego-prakasa-14102055_IF-b
Modul3 deprilana ego-prakasa-14102055_IF-b
 
14102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-414102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-4
 
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 3-if b 2014-14102055-deprilana ego prakasa
 
Modul2 deprilana ego-prakasa-14102055_if-b
Modul2 deprilana ego-prakasa-14102055_if-bModul2 deprilana ego-prakasa-14102055_if-b
Modul2 deprilana ego-prakasa-14102055_if-b
 
14102055
1410205514102055
14102055
 
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4
[Laporan ai kelas b] 14102055 deprilana ego prakasa_modul 4
 
Laporan praktikum multimedia 5 5
Laporan praktikum multimedia 5 5Laporan praktikum multimedia 5 5
Laporan praktikum multimedia 5 5
 
Laporan praktikum jarkom_4
Laporan praktikum jarkom_4Laporan praktikum jarkom_4
Laporan praktikum jarkom_4
 
Laporan praktikum jarkom_3
Laporan praktikum jarkom_3Laporan praktikum jarkom_3
Laporan praktikum jarkom_3
 
Laporan praktikum jarkom_2
Laporan praktikum jarkom_2Laporan praktikum jarkom_2
Laporan praktikum jarkom_2
 
Laporan praktikum jarkom
Laporan praktikum jarkomLaporan praktikum jarkom
Laporan praktikum jarkom
 
Laporan praktikum multimedia_4-4
Laporan praktikum multimedia_4-4Laporan praktikum multimedia_4-4
Laporan praktikum multimedia_4-4
 
Laporan praktikum multimedia_3-3
Laporan praktikum multimedia_3-3Laporan praktikum multimedia_3-3
Laporan praktikum multimedia_3-3
 
Resume praktikum 7__queue
Resume praktikum 7__queueResume praktikum 7__queue
Resume praktikum 7__queue
 
Resume praktikum 5__linked_list
Resume praktikum 5__linked_listResume praktikum 5__linked_list
Resume praktikum 5__linked_list
 

Recently uploaded

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Recently uploaded (20)

Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa

  • 1. Sekolah Tinggi Teknologi Telematika Telkom Laporan Praktikum Kecerdasan Buatan Modul 2 (Implementasi DFS dan BFS) Dosen Pengampu: Muhammad Zidny Naf’an,S.Kom., M.Kom. Nama Mahasiswa NIM Kelas : Deprilana Ego Prakasa : 14102055 : S1 IF B 2014
  • 2. VERTEX Vertex.java package graph; public class Vertex { public char label; public boolean wasVisited; public Vertex(char label){ this.label = label; wasVisited = false; } } GRAPH Graph.java package graph; import java.util.LinkedList; import java.util.Queue; import java.util.Stack; public class Graph { private char search; private final int MAX_VERTS =20; private Vertex vertexList[]; private int adjMat[][]; private int nVertexs; private Queue openQueue; private Stack openStack; public Graph(){ vertexList = new Vertex[MAX_VERTS]; adjMat = new int [MAX_VERTS][MAX_VERTS]; adjMat = new int [MAX_VERTS][MAX_VERTS]; nVertexs = 0; openQueue = new LinkedList(); openStack = new Stack<String>(); } public Graph(char search){ this.search = search;
  • 3. vertexList = new Vertex[MAX_VERTS]; adjMat = new int[MAX_VERTS][MAX_VERTS]; nVertexs = 0; openQueue = new LinkedList(); openStack = new Stack<String>(); } public void addVertex(char label){ vertexList[nVertexs++] = new Vertex(label); } public void addEdge(int from, int to){ adjMat[from][to]=1; adjMat[to][to]=1; } public void displayVertex(int v){ System.out.print(vertexList[v].label); } public void depthFirstSearch(){ vertexList[0].wasVisited = true; openStack.push(0); int v2 = 0; while(!openStack.isEmpty()){ Integer v1 = (Integer) openStack.pop(); displayVertex(v1); if(vertexList[v1].label == search) break; while((v2 = getAdjUnvisitedVertexDFS(v1)) != -1){ vertexList[v2].wasVisited = true; openStack.add(v2); } } for (int j=0; j<nVertexs; j++){ vertexList[j].wasVisited = false; } } public void breadthFirstSearch(){ vertexList[0].wasVisited = true; openQueue.add(0); int v2; while(!openQueue.isEmpty()){ Integer v1 = (Integer) openQueue.remove(); displayVertex(v1); if(vertexList[v1].label == search)
  • 4. break; while((v2 = getAdjUnvisitedVertexBFS(v1)) !=-1){ vertexList[v2].wasVisited = true; openQueue.add(v2); } } for(int j=0; j<nVertexs; j++){ vertexList[j].wasVisited = false; } } public int getAdjUnvisitedVertexBFS(int v){ for(int j = 0;j<nVertexs; j++){ if(adjMat[v][j]==1 && vertexList[j].wasVisited == false){ return j; } } return -1; } public int getAdjUnvisitedVertexDFS(int v){ for(int j = nVertexs-1;j>=0; j--){ if(adjMat[v][j]==1 && vertexList[j].wasVisited == false){ return j; } } return -1; } } MAIN Main.java package graph; public class Main { public static void main(String[] args) { Graph theGraph = new Graph(); theGraph.addVertex('A'); //0 theGraph.addVertex('B'); //1 theGraph.addVertex('C'); //2 theGraph.addVertex('D'); //3 theGraph.addVertex('E'); //4 theGraph.addEdge(0, 1); //AB theGraph.addEdge(1, 2); //BC theGraph.addEdge(0, 3); //AD theGraph.addEdge(3, 4); //DE
  • 5. System.out.println("Breadth First Search:"); System.out.println("Visits: "); theGraph.breadthFirstSearch(); System.out.println(); System.out.println("Depth First Search:"); System.out.println("Visits: "); theGraph.depthFirstSearch(); System.out.println(); // TODO code application logic here } } SOAL LATIHAN 1.1 MAIN Main.java package graph; public class Main { public static void main(String[] args) { Graph theGraph = new Graph(); theGraph.addVertex('A'); //0 theGraph.addVertex('B'); //1 theGraph.addVertex('C'); //2 theGraph.addVertex('D'); //3 theGraph.addVertex('E'); //4
  • 6. theGraph.addVertex('F'); //5 theGraph.addVertex('G'); //6 theGraph.addVertex('H'); //7 theGraph.addVertex('I'); //8 theGraph.addVertex('J'); //9 theGraph.addEdge(0, 1); //AB theGraph.addEdge(0, 2); //AC theGraph.addEdge(0, 3); //AD theGraph.addEdge(1, 6); //BG theGraph.addEdge(1, 7); //BH theGraph.addEdge(3, 4); //DE theGraph.addEdge(3, 5); //DF theGraph.addEdge(4, 8); //EI theGraph.addEdge(4, 9); //EJ System.out.println("Breadth First Search:"); System.out.println("Visits: "); theGraph.breadthFirstSearch(); System.out.println(); System.out.println("Depth First Search:"); System.out.println("Visits: "); theGraph.depthFirstSearch(); System.out.println(); // TODO code application logic here } }
  • 7. 2.1 Gambar Vertex dan Edge dari bentuk Graph pada Main Pertama 3.1 Bentuk adjacency matrix-nya A B C D E A 0 1 0 1 0 B 0 0 1 0 0 C 0 0 0 0 0 D 0 0 0 0 1 E 0 0 0 0 0 4.1 Apakah output dari Breadth First Search berdasarkan Graph tersebut, Ya sesuai dengan Grapnya 5.1 Apakah output dari Depth First Search berdasarkan Graph tersebut, Ya sesuai dengan Grapnya A B D C E
  • 8. 6.1 Implementasi Graph berikut pada kode yang anda buat Main.java package graph; public class Main { public static void main(String[] args) { Graph theGraph = new Graph(); theGraph.addVertex('A'); //0 theGraph.addVertex('B'); //1 theGraph.addVertex('C'); //2 theGraph.addVertex('D'); //3 theGraph.addVertex('E'); //4 theGraph.addVertex('F'); //5 theGraph.addVertex('G'); //6 theGraph.addVertex('H'); //7 theGraph.addVertex('I'); //8 theGraph.addVertex('J'); //9 theGraph.addEdge(0, 1); //AB theGraph.addEdge(0, 2); //AC theGraph.addEdge(0, 3); //AD theGraph.addEdge(1, 6); //BG theGraph.addEdge(1, 7); //BH theGraph.addEdge(3, 4); //DE theGraph.addEdge(3, 5); //DF theGraph.addEdge(4, 8); //EI theGraph.addEdge(4, 9); //EJ System.out.println("Breadth First Search:"); System.out.println("Visits: ");
  • 9. theGraph.breadthFirstSearch(); System.out.println(); System.out.println("Depth First Search:"); System.out.println("Visits: "); theGraph.depthFirstSearch(); System.out.println(); // TODO code application logic here } } 7.1. Output Breadth First Search untuk Graph No 6 8.1. Output Depth First Search untuk Graph No 6