Concept explainers
Weighted Graph:
A graph is termed as weighted graph if each edge of the graph is assigned a weight. The weighted edges stored in the weighted graphs can be stored in adjacency lists.
Weighted edges can be represented using a two-dimensional array. An weighted edge can be represented as “WeightedEdge(u,v,w)”, where “u” and “v” are edges and “w” represents the weight between them.
Example of storing edge in a weighted graph:
Object[][] edges =
{ new Integer(0), new Integer(1), new SomeTypeForWeight(8) };
Program:
List<WeightedEdge> list = new ArrayList<>();
list.add(new WeightedEdge(1, 2, 3.5));
list.add(new WeightedEdge(2, 3, 4.5));
WeightedEdge e = java.util.Collections.max(list);
System.out.println(e.u);
System.out.println(e.v);
System.out.println(e.weight)
Want to see the full answer?
Check out a sample textbook solutionChapter 29 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- Answer for.Write a Python Code for the given constructor and conditions: Given Constructor: def __init__ (self, a) Pre-condition: Array cannot be empty. Post-condition: This is the default constructor of MyList class. This constructor creates a list from an array..arrow_forwardB1. Answer the following: a. Create an ArrayList named Employee of type String. b. Add Ahmed, Mohammed, and Amal to the list? c. Remove Mohammed from the list? d. Write a for loop to print the elements of array list?arrow_forwardThis is using Data Structures in Javaarrow_forward
- The below code declares a new Vector named 'vec'. What is the size of the vector at the end of the execution? Vector vec = new Vector(); for(int i=1;i<=10; i++) { vec.addElement(i); } vec.removeElement(9); vec.removeElement(10); vec.removeElement(11);arrow_forwardPlease use C++, send screenshot of code running. Because this is the 2nd time I upload this photo, last answer I got, the code wasn’t compiled and run.arrow_forward· Write a method to insert an element at index in a Doubly Linked List data structure and test it. The method receives this list by parameters. * in javaarrow_forward
- Doctor -signature:String -doctorID:int - medicine:Arraylist +Doctor(signature:String,doctorID:int) +PrescribeMedicine():void + salary () +checkRecords():void Medicine Pharmacist -medName:String -startTime:int -dosage :int -endTime:int -date_prescribed:int - medicine:Arraylist +Medicine(medName:String,-dosage :int,date_prescribed:int) +Pharmacist (startTime:int,endTime:int) +checkForConflict():double +confirm_prescription():String +getStartTime():int +getEndTime():int +setStartTime(time:int):void +setEndTime(time1:int).voidarrow_forwardExercise 1• Create a class that sorts a list in ascending order. Make use of the Collections method sort• The list should be a list of Strings.• Test your code with {“Hearts”, “Diamonds”, “Clubs”, “Spades”}• Before and after the sort, use the implicit call to the list’s toString method to output the list contents. Exercise 2• Create a class with the same requirement as in Exercise 1, but the sort should be in descending order• Make use of the Comparator interface• Make use of the static collection method reverseOrder javaarrow_forwardIf a list is defined as follows dogNames = ["Ginger", "Gidget", "Dustie", "Monica"] what is the index of the element "Dustie"? 1, 2, 3 or 4?arrow_forward
- Question 5 Assume that the following method is in a class called DLL (not same as KWLinkedList). What does this method do? public void method_LI( ) { KWLinkedList<Integer> list = new KWLinkedList<Integer>( ); list.add(2); list.add(-1); list.add(0); list.add(1); list.add(0); ListIterator<integer> iter = list.listIterator(); while(iter.hasNext()) { if (iter.next() == 0) iter.remove(); } if( iter.hasPrevious() ) System.out.println("END"); else while(iter.hasNext()) System.out.print(iter.next() + " "); } Removes the nodes having 0 as its data and prints END. Removes the nodes having 0 as its data and prints 2 -1 1 Removes the nodes having 0 as its data and prints 1 -1 2 Prints 2 -1 0 1 0 without removing anything.arrow_forwardQ1: Write a complete project to apply the Doubly Linked List data structures with all functions and then test it. In Javaarrow_forwardQuestion 7 Which of the following class implements the List interface? Collection AbstractList Listlterator ArrayList«E>arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education