liveBook · Manning

Unweighted edge

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A graph edge that represents a connection without an associated weight.

An unweighted edge represents a connection between two vertices without an associated value such as distance. It records which vertices connect, not anything about the connection itself. In the bidirectional graph used here, reversing the edge lets each vertex treat the other as a neighbor. section 4.1

A concrete Swift edge provides:

  • A from vertex index, u, and a to vertex index, v. section 4.1
  • A reversed edge with the endpoints exchanged. section 4.1
  • A description such as "u <-> v" for CustomStringConvertible conformance. section 4.1

Hyperloop network

A city graph can connect Seattle to Chicago and San Francisco, then expose those neighboring cities through adjacency lists. The edges record connectivity only; travel distance is omitted. section 4.1

public protocol Edge: CustomStringConvertible {
    var u: Int { get set } // index of the "from" vertex
    var v: Int { get set } // index of the "to" vertex
    var reversed: Edge { get }
}

The Edge protocol makes endpoint indices and reversal the essential interface for an unweighted edge. section 4.1

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines the distinction from weighted edges and implements endpoints, reversal, and string description, without modeling edge values.
Examples
Uses a Hyperloop-style city network with connections among cities such as Seattle, Chicago, and San Francisco.
What it assumes
Assumes vertices and graph interfaces while defining the concrete edge representation from its required fields.
What you can do after
Build it from scratch as a Swift Edge implementation with reversible endpoints and graph insertion support.
How it connects
Connects vertices, graphs, adjacency lists, bidirectional edges, and weighted edges.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.