@@ -57,13 +57,13 @@ Seam carving is a 3-step algorithm, each represented as a Java `class` or `inter
`SeamCarver`
: The seam carving algorithm combines an energy function with the seam finder to identify and remove the most unnoticeable seams from an picture. This class handles vertical seams by transposing the picture before calling `SeamFinder`.
The focus of this project is on comparing implementations for `SeamFinder`. In order to solve this problem, the `SeamFinder` algorithm must find the shortest path from the left edge of a `Picture` to its right edge. To bootstrap the design, we've provided common graph interfaces and algorithms in the `graphs` package based on code presented in the lesson.
The focus of this project is on comparing implementations for `SeamFinder`. In order to solve this problem, the `SeamFinder` algorithm must find a shortest path from the left edge of a `Picture` to its right edge. To bootstrap the design, we've provided common graph interfaces and algorithms in the `graphs` package based on code presented in the lesson.
`graphs.Graph<V>`
: Represents a directed, edge-weighted graph with a single method that returns a list of the `neighbors` of a given vertex. The directed `Edge` class provides 3 methods: access to the origin vertex `from`, the destination vertex `to`, and the edge `weight`.
`graphs.ShortestPathSolver<V>`
: Computes the shortest paths in a directed, edge-weighted `Graph`. Implementations of the `ShortestPathSolver` interface must provide a public constructor that accepts two parameters: a graph and a start vertex. The `solution` method returns the list of vertices representing the shortest path in the graph from the start vertex to the given `goal` vertex.
: Computes a shortest paths tree in a directed, edge-weighted `Graph`. Implementations of the `ShortestPathSolver` interface must provide a public constructor that accepts two parameters: a graph and a start vertex. The `solution` method returns the list of vertices representing a shortest path from the start vertex to the given `goal` vertex.
`graphs.ExtrinsicMinPQ<T>`
: Priority queue interface for `DijkstraSolver`.
...
...
@@ -98,7 +98,7 @@ Design and implement an alternative graph representation and graph algorithm for
: Rather than precomputing and storing the neighbors for every single `Pixel` in a 2-D array, this graph representation computes the `neighbors` for each pixel on demand to reduce memory usage. Identify the relevant portions of the `AdjacencyListSeamFinder.PixelGraph` class and modify it so that the `PixelGraph.pixels` and `Pixel.neighbors` fields are no longer needed.
`graphs.ToposortDAGSolver`
: Computes the shortest paths in a directed acyclic graph using the reduction to topological sorting presented in the lesson.
: Computes a shortest paths tree in a directed acyclic graph using the reduction to topological sorting presented in the lesson.
: 1. Initialize `edgeTo` and `distTo` data structures just as in `DijkstraSolver`.
1. List all reachable vertices in depth-first search post-order. Then, [`Collections.reverse`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#reverse(java.util.List)) the list.
1. For each node in reverse DFS post-order, apply Dijkstra's edge relaxation step: if the distance to the neighboring node using the given edge is less than the `distTo` value to the neighboring node, update `distTo` and `edgeTo` accordingly.
...
...
@@ -107,7 +107,7 @@ Design and implement an alternative graph representation and graph algorithm for
: A [dynamic programming seam finding algorithm](https://avikdas.com/2019/05/14/real-world-dynamic-programming-seam-carving.html#bottom-up-implementation). This algorithm solves the problem by considering pixels from left to right similar to the `ToposortDAGSolver` except that it operates directly on the `Picture` rather than through an abstract `Graph` representation.
: 1. Initialize a 2-D `double[picture.width()][picture.height()]` to represent the cost of the **minimum energy path** from the left edge to each pixel.
1. Iteratively compute the minimum energy path to each pixel starting from the left edge of the picture and working towards the right edge by considering each pixel's preceding path costs: the **left-up**, **left-middle**, and **left-down** pixels.
1. Compute the shortest path by starting from the right edge and working back towards the left edge, adding each minimum-cost **y-coordinate** to a list.
1. Compute a shortest path by starting from the right edge and working back towards the left edge, adding each minimum-cost **y-coordinate** to a list.
1.[`Collections.reverse`](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/util/Collections.html#reverse(java.util.List)) the list to obtain the horizontal seam.