Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 28.3, Problem 28.3.1CP

Explanation of Solution

Representing vertices:

The vertices in a graph can be stored in an “array” or a “list”.

Example:

Consider the below graph:

The vertices from above graph has been stored in an array as follows:

String[] Ver={“A”, “B”, “C”, “”D”};

Representing edges using an “array”:

The edges in a graph can be stored in a “two-dimensional array”. This representation is called an “edge array”.

Example:

Consider the edges in an above graph can be stored using following two- dimensional array initialization:

int[][]={{0,1}, {0,2},{1,0},{1,2},{2,0},{2,1},{2,3},{1,3},{3,1},{3,2}};

Representing edges using an “edge object”:

Edges can also be stored as edge object by defining the edges as “objects” and store the edges in an “ArrayList”.

Example:

Consider the following “Edge” class object declaration:

Java,util.ArrayList<Edge>edges=new java.util.ArrayList<>();

Edges...

Blurred answer
Students have asked these similar questions
Why is it better to use an adjacency matrix to represent a graph rather than an adjacency list?
Consider the graph depicted below. Answer the following questions: What is the degree of vertex a?  What is the sum of degrees of all vertices?    Who are the neighbors of vertex f? [Please, give the list in alphabetical order, separating letters with only a comma. Do not insert blank spaces]  How many zeros does the adjacency matrix of the graph above contain?  What is the value on row g and column d of the adjacency matrix?
Represent the following graph using an edge array, a list of edge objects, an adjacency matrix, an adjacency vertex list, and an adjacency edge list, respectively.

Chapter 28 Solutions

Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE 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