# Chapter17 - CHAPTER 17 Searching Graphs Chapter Objectives...

This preview shows pages 1–3. Sign up to view the full content.

Chapter Objectives This chapter demonstrates algorithms for finding good paths through a graph. However, first we need to understand the following: ± How to construct and use two special forms of data collection: queues and priority queue ± How to build a model of a graph ± How to traverse and search a graph Introduction The collections we have considered so far—vectors, arrays, structures, and cell arrays—have essentially been collections of fixed size. In practice, of course, many MATLAB operations disguise the fixed character of the collections by performing complex operations that are invisible to the user to change the size of the collection. The ultimate goal of this chapter is to discuss the most general form of dynamic data structure: the graph. In computer science, a graph is a collection of nodes connected by edges , as opposed to the engineering view of a graph that is produced by plotting, for example, f ( x ) against . To process graphs effectively, we must first consider two simpler concepts: a queue and a priority queue . Searching Graphs CHAPTER 17 17.1 Queues and Priority Queues 17.1.1 The Nature of a Queue 17.1.2 Implementing Normal Queues 17.1.3 Priority Queues 17.1.4 Testing Queues 17.2 Graphs 17.2.1 Graph Examples 17.2.2 Processing Graphs 17.2.3 Building Graphs 17.2.4 Traversing Graphs 17.2.5 Searching Graphs 17.2.6 Breadth-First Search (BFS) 17.2.7 Dijkstra’s Algorithm 17.2.8 Testing Graph Search Algorithms 17.3 Engineering Application— Route Planning 445

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
446 Chapter 17 Searching Graphs 17.1 Queues and Priority Queues We first consider the nature and implementation of queues, special collections that enable us to process graphs efficiently. We experience the concept of a queue every day of our lives. A line of cars waiting for the light to turn green is a queue; when we stand in line at a store or send a print job to a printer, we experience typical queue behavior. In general, the first object entering a queue is the first one to exit the other end. 17.1.1 The Nature of a Queue Formally, we refer to a queue as a first in/first out (FIFO) collection, as illustrated in Figure 17.1. The most general form of a queue is permitted to contain any kind of object, that is, an instance of any data type or class. Typically, operations on a queue are restricted to the following: ± enqueue puts an object into the queue ± dequeue removes an object from the queue ± peek copies the first object out of the queue without removing it ± isempty determines that there are no items in the queue 17.1.2 Implementing Normal Queues Although there are many ways to implement a queue, a cell array is a good choice because it is a linear collection of objects that may be of any type. If we establish a queue using a cell array, the mechanizations are trivial as follows: ± qEnq concatenates data at the end of the cell array ± qDeq removes the item from the front of the cell array and returns that item to the user ± peek merely accesses the first item in the cell array ± isempty is the standard MATLAB test for the empty vector
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/21/2011 for the course CS 1371 taught by Professor Stallworth during the Fall '08 term at Georgia Institute of Technology.

### Page1 / 24

Chapter17 - CHAPTER 17 Searching Graphs Chapter Objectives...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online