SlideShare a Scribd company logo
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 manual
sameer 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 8
Chaitanya Ganoo
 
Java programs
Java programsJava programs
3433 Ch10 Ppt
3433 Ch10 Ppt3433 Ch10 Ppt
3433 Ch10 Ppt
martha leon
 
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
Nagios
 
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 In C++
Memory Management In C++Memory Management In C++
Memory Management In C++
ShriKant Vashishtha
 
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 Reagent
Maty 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 2019
Gebreigziabher 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 3
hasi071
 
Java lab 2
Java lab 2Java lab 2

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 buatan
Muhammad 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 Indonesia
Alvi Syahrina
 
Tugas Kecerdasan Buatan
Tugas Kecerdasan BuatanTugas Kecerdasan Buatan
Tugas Kecerdasan Buatan
Yohanes Sibarani
 
Tugas review jurnal
Tugas review jurnalTugas review jurnal
Tugas review jurnalAndik Irawan
 
Cara Mereview Jurnal
Cara Mereview JurnalCara Mereview Jurnal
Cara Mereview Jurnal
Rumah Studio
 
Contoh Review Jurnal
Contoh Review JurnalContoh Review Jurnal
Contoh Review Jurnal
Trisnadi Wijaya
 
Makalah fix
Makalah fixMakalah fix
Makalah fix
zhu ma
 
Kecerdasan buatan
Kecerdasan buatanKecerdasan buatan
Kecerdasan buatan
zhu 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

Java oops features
Java oops featuresJava oops features
Java oops features
VigneshManikandan11
 
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
ajoy21
 
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
dbrienmhompsonkath75
 
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.pdf
MAYANKBANSAL1981
 
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGEPROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
yash production
 
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
Daniel Wellman
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
Domenico Briganti
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
Iram Ramrajkar
 
ScalaFlavor4J
ScalaFlavor4JScalaFlavor4J
ScalaFlavor4J
Kazuhiro Sera
 
AJUG April 2011 Cascading example
AJUG April 2011 Cascading exampleAJUG April 2011 Cascading example
AJUG April 2011 Cascading example
Christopher Curtin
 
Map struct
Map structMap struct
Map struct
Hyosang Hong
 
Map struct
Map structMap struct
Map struct
Hyosang Hong
 
Java Programs Lab File
Java Programs Lab FileJava Programs Lab File
Java Programs Lab File
Kandarp Tiwari
 
JUnit 5
JUnit 5JUnit 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
JUSTSTYLISH3B2MOHALI
 
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 Generics
jeslie
 

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
 
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGEPROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
PROGRAMING IN JAVA 4TH SEM DIGVIJAY COLLAGE
 
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
 

More from Deprilana Ego Prakasa

Dokumentasi rpl
Dokumentasi rplDokumentasi rpl
Dokumentasi rpl
Deprilana Ego Prakasa
 
Proposal multimedia-bab-i-ii-iii
Proposal multimedia-bab-i-ii-iiiProposal multimedia-bab-i-ii-iii
Proposal multimedia-bab-i-ii-iii
Deprilana Ego Prakasa
 
Tugas dsm kelompok11
Tugas dsm kelompok11Tugas dsm kelompok11
Tugas dsm kelompok11
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-B
Deprilana 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-B
Deprilana 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-b
Deprilana Ego Prakasa
 
14102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-414102055 deprilana ego prakasa-modul-4
14102055 deprilana ego prakasa-modul-4
Deprilana 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 prakasa
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
Deprilana Ego Prakasa
 
14102055
1410205514102055
[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
Deprilana Ego Prakasa
 
Laporan praktikum multimedia 5 5
Laporan praktikum multimedia 5 5Laporan praktikum multimedia 5 5
Laporan praktikum multimedia 5 5
Deprilana Ego Prakasa
 
Laporan praktikum jarkom_4
Laporan praktikum jarkom_4Laporan praktikum jarkom_4
Laporan praktikum jarkom_4
Deprilana Ego Prakasa
 
Laporan praktikum jarkom_3
Laporan praktikum jarkom_3Laporan praktikum jarkom_3
Laporan praktikum jarkom_3
Deprilana Ego Prakasa
 
Laporan praktikum jarkom_2
Laporan praktikum jarkom_2Laporan praktikum jarkom_2
Laporan praktikum jarkom_2
Deprilana Ego Prakasa
 
Laporan praktikum jarkom
Laporan praktikum jarkomLaporan praktikum jarkom
Laporan praktikum jarkom
Deprilana Ego Prakasa
 
Laporan praktikum multimedia_4-4
Laporan praktikum multimedia_4-4Laporan praktikum multimedia_4-4
Laporan praktikum multimedia_4-4
Deprilana Ego Prakasa
 
Laporan praktikum multimedia_3-3
Laporan praktikum multimedia_3-3Laporan praktikum multimedia_3-3
Laporan praktikum multimedia_3-3
Deprilana Ego Prakasa
 
Resume praktikum 7__queue
Resume praktikum 7__queueResume praktikum 7__queue
Resume praktikum 7__queue
Deprilana Ego Prakasa
 
Resume praktikum 5__linked_list
Resume praktikum 5__linked_listResume praktikum 5__linked_list
Resume praktikum 5__linked_list
Deprilana 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

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 

Recently uploaded (20)

The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 

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