Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
100%

How to change this Java code to accept character value instead of integer for edges u and v:

 

import java.util.*;
public class Main {
 
privateintV;// number of vertices
 
privateArrayList<ArrayList<Edge>> adj;// adjacency list
 
 
 
privateclassEdge{
 
int v;// vertex
 
int bandwidth;// bandwidth
 
 
 
publicEdge(int v,int bandwidth){
 
this.v = v;
 
this.bandwidth = bandwidth;
 
}
 
}
 
 
 
publicMain(intV){
 
this.V=V;
 
adj = new ArrayList<ArrayList<Edge>>(V);
 
for(int i =0; i <V; i++){
 
adj.add(new ArrayList<Edge>());
 
}
 
}
 
 
 
publicvoidaddEdge(int u,int v,int bandwidth){
 
adj.get(u).add(new Edge(v, bandwidth));
 
adj.get(v).add(new Edge(u, bandwidth));
 
}
 
 
 
publicintmaxBandwidth(int a,int b){
 
PriorityQueue<Integer> pq =newPriorityQueue<Integer>(V,Collections.reverseOrder());
 
HashMap<Integer, Integer> visited =newHashMap<Integer, Integer>();
 
HashMap<Integer, Integer> parent =newHashMap<Integer, Integer>();
 
pq.add(a);
 
visited.put(a, Integer.MAX_VALUE);
 
parent.put(a, -1);
 
while(!pq.isEmpty()){
 
int u = pq.poll();
 
if(u == b){
 
break;
 
}
 
for(Edge e : adj.get(u)){
 
int v = e.v;
 
int bandwidth = e.bandwidth;
 
if(!visited.containsKey(v)){
 
int minBandwidth =Math.min(visited.get(u), bandwidth);
 
visited.put(v, minBandwidth);
 
parent.put(v, u);
 
pq.add(v);
 
}
 
}
 
}
 
int maxBandwidth = visited.get(b);
 
int curr = b;
 
ArrayList<Integer> path =newArrayList<Integer>();
 
while(curr !=-1){
 
path.add(0, curr);
 
curr = parent.get(curr);
 
}
 
System.out.println("Maximum bandwidth path from "+ a +" to "+ b +": "+ path);
 
return maxBandwidth;
 
}
 
 
 
public static void main(String[] args){
 
Main g = new Main(5);
g.addEdge(0, 1, 10);
g.addEdge(0, 2, 5);
g.addEdge(1, 2, 7);
g.addEdge(1, 3, 3);
g.addEdge(2, 3, 2);
g.addEdge(2, 4, 6);

System.out.println("Maximum bandwidth from 0 to 4: " + g.maxBandwidth(0, 4));
 
}
 
}
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education