+ All Categories
Home > Documents > Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of...

Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of...

Date post: 05-Jan-2016
Category:
Upload: ezra-johnson
View: 215 times
Download: 0 times
Share this document with a friend
20
Computer Science: A Structured Programming Approach Using C 1 15-6 Graphs A graph is a collection of nodes, called vertices, A graph is a collection of nodes, called vertices, and a collection of segments, called lines, and a collection of segments, called lines, connecting pairs of vertices. In other words, a connecting pairs of vertices. In other words, a graph consists of two sets, a set of vertices and graph consists of two sets, a set of vertices and a set of lines. a set of lines. Graph Traversal Topics discussed in this section: Topics discussed in this section:
Transcript
Page 1: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 1

15-6 Graphs

A graph is a collection of nodes, called vertices, and a A graph is a collection of nodes, called vertices, and a collection of segments, called lines, connecting pairs collection of segments, called lines, connecting pairs of vertices. In other words, a graph consists of two of vertices. In other words, a graph consists of two sets, a set of vertices and a set of lines.sets, a set of vertices and a set of lines.

Graph TraversalTopics discussed in this section:Topics discussed in this section:

Page 2: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 2

FIGURE 15-45 Directed and Undirected Graphs

Page 3: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 3

Graphs may be directed or undirected. In a directed graph, each line, called an arc, has a direction indicatinghow it may be traversed. In an undirected graph,

the line is known as an edge, and it may be traversed in either direction.

NoteNote

Page 4: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 4

A file is an external collection of related data treated as a unit.

NoteNote

Page 5: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 5

FIGURE 15-46 Cycles and Loops

Page 6: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 6

FIGURE 15-47 Connected and Disjoint Graphs

Page 7: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 7

FIGURE 15-48 Depth-first Traversal of a Tree

Page 8: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 8

In the depth-first traversal, all of a node’s descendents are processed before moving to an adjacent node.

NoteNote

Page 9: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 9

FIGURE 15-49 Depth-first Traversal of a Graph

Page 10: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 10

FIGURE 15-50 Breadth-first Traversal of a Tree

Page 11: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 11

FIGURE 15-51 Breadth-first Traversal of a Graph

Page 12: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 12

In the breadth-first traversal, all adjacentvertices are processed before processing

the descendents of a vertex.

NoteNote

Page 13: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 13

15-7 Software Engineering

Because lists are useful structures, programmers use Because lists are useful structures, programmers use them in many applications. Rather than rewrite their them in many applications. Rather than rewrite their functions each time we need them, we can write functions each time we need them, we can write functions once and put them in a library. The name functions once and put them in a library. The name given to a complete set of these functions is abstract given to a complete set of these functions is abstract data type (ADT). data type (ADT).

Atomic and Composite DataData Structure and Abstract Data TypeA Model for an Abstract Data TypeADT Data Structure

Topics discussed in this section:Topics discussed in this section:

Page 14: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 14

Atomic Data Type1. A set of values.2. A set of operations on the values.

NoteNote

Page 15: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 15

Data Structure1. A combination of elements, each of which is either a data type or another data structure.2. A set of associations or relationships (structure) involving the combined elements.

NoteNote

Page 16: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 16

Table 15-2 Two Structures

Page 17: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 17

In the concept of abstractionWe know what a data type can do.How it is done is hidden.

NoteNote

Page 18: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 18

FIGURE 15-52 Structures for Holding a List

Page 19: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 19

Abstract Data Type1. Declaration of data.2. Declaration of operations.

NoteNote

Page 20: Computer Science: A Structured Programming Approach Using C1 15-6 Graphs A graph is a collection of nodes, called vertices, and a collection of segments,

Computer Science: A Structured Programming Approach Using C 20

FIGURE 15-53 Abstract Data Type Model


Recommended