Shortest Path Algorithms

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Hvaða fullyrðing er sönn varðandi tré stystu vega og léttasta spanntré, jafnvel þótt bæði séu spanntré?

  • Tré stystu vega eru óstefnd og án rótar, á meðan léttustu spanntré eru með rót og stefnu.
  • Tré stystu vega eru náttúrulegri fyrir óstefnd net, en léttustu spanntré fyrir stefnd net.
  • Tré stystu vega hafa rót og stefnu, á meðan léttustu spanntré eru óstefnd og án rótar. (correct)
  • Báðar aðferðirnar leiða alltaf til sömu niðurstöðu óháð því hvort netið er stefnt eða óstefnt.

Í hvaða tilfelli er tæknilega réttara að tala um stystu göngur frekar en stystu vegi í samhengi við reiknirit?

  • Þegar neikvæðar rásir eru til staðar. (correct)
  • Þegar unnið er með óstefnd net.
  • Þegar allar vogtölur á leggjum eru jákvæðar.
  • Þegar engar neikvæðar rásir eru til staðar.

Hvaða fullyrðing lýsir best muninum á tré stystu vega og léttasta spanntrés þegar vogtölur á leggjum eru allar ólíkar?

  • Það er aðeins eitt léttasta spanntré, en sérhver upphafshnútur gefur mismunandi tré stystu vega. (correct)
  • Það er aðeins eitt tré stystu vega og aðeins eitt léttasta spanntré.
  • Það er aðeins eitt tré stystu vega, en sérhver upphafshnútur gefur mismunandi léttasta spanntré.
  • Sérhver upphafshnútur gefur sama tré stystu vega og sama léttasta spanntré.

Í hvaða tilvikum gæti leyfi fyrir neikvæðum vogtölum á leggjum verið eðlilegt í stystu vega vandamálum?

<p>Þegar vogtölur tákna kostnað við að fara milli hnúta, þar sem neikvæðar tölur gætu táknað hagnað. (C)</p> Signup and view all the answers

Hvaða vandamál geta neikvæðar rásir valdið í stystu vega vandamáli?

<p>Þær geta gert það að verkum að stysti vegurinn er ekki vel skilgreindur. (C)</p> Signup and view all the answers

Hvaða fullyrðing er rétt varðandi reiknirit til að finna stysta einfalda veginn þegar neikvæðar rásir eru til staðar?

<p>Það er NP-erfitt. (A)</p> Signup and view all the answers

Af hverju skoðum við eingöngu stefnd net þegar kemur að neikvæðum vogtölum?

<p>Vegna þess að meðhöndlun neikvæðra vogtalna í óstefndum netum er flóknari. (D)</p> Signup and view all the answers

Hvað er sameiginlegt með reikniritunum sem finna stysta veg?

<p>Þau eru sérstök tilfelli af einu almennu reikniriti. (B)</p> Signup and view all the answers

Hvaða tvo hluti geymir hver hnútur v í Ford reikniritinu sem lýsa tilraunavegi frá upphafshnútnum s?

<p>Fjarlægð frá <code>s</code> og foreldri hnútsins á veginum. (C)</p> Signup and view all the answers

Hvað er átt við með 'spenntum legg' í samhengi við reiknirit til að finna stysta veg?

<p>Leggur þar sem hægt er að stytta tilraunaveginn með því að fara í gegnum hann. (A)</p> Signup and view all the answers

Hvaða fullyrðing er rétt um Ford-SSSP reikniritið þegar það lýkur keyrslu?

<p>Foreldravísarnir skilgreina rétt tré stystu vega og sérhvert gildi <code>dist(v)</code> er raunveruleg stysta vega fjarlægð frá <code>s</code> til <code>v</code>. (B)</p> Signup and view all the answers

Hvaða fullyrðing er rétt um keyrslu Ford-reikniritsins?

<p><code>dist(v)</code> er annaðhvort ∞ eða lengd göngu frá <code>s</code> til <code>v</code>. (A)</p> Signup and view all the answers

Hvað gerist ef neikvæð rás er aðgengileg frá upphafshnúti s í Ford reikniritinu?

<p>Reikniritið stöðvar aldrei. (B)</p> Signup and view all the answers

Hvaða tvö atriði þarf að huga að við útfærslu á Ford-reikniritinu?

<p>Hvernig á að finna spennta leggi og hvaða leggi á að slaka ef margir eru til staðar. (A)</p> Signup and view all the answers

Hver er grundvallarmunurinn á breiddarleit og dýptarleit?

<p>Breiddarleit notar biðröð (FIFO), en dýptarleit notar stafla (LIFO). (D)</p> Signup and view all the answers

Hvað gerir breiddarleit þegar spenntur leggur u → v finnst?

<p>Hann slakar á leggnum og setur hnút <code>v</code> í biðröðina. (C)</p> Signup and view all the answers

Hvaða fullyrðing er rétt varðandi notkun tákns í breiddarleit?

<p>Táknið er notað til að greina á milli fasa í breiddarleitinni. (C)</p> Signup and view all the answers

Hvaða fullyrðing er alltaf sönn við lok i-ta fasans í breiddarleit með tákni?

<p>Annaðhvort er <code>dist(v) = ∞</code> eða <code>dist(v) &lt;= i</code>, og ef <code>v</code> er í biðröðinni þá og því aðeins að <code>dist(v) = i</code>. (A)</p> Signup and view all the answers

Hvaða tímaflækju hefur breiddarleit?

<p>$O(V + E)$ (D)</p> Signup and view all the answers

Hvaða fullyrðing er rétt varðandi fjarlægð hnútar v í breiddarleit?

<p>Fjarlægð hnútar <code>v</code> hækkar aldrei. (A)</p> Signup and view all the answers

Við hvaða skilyrði getum við skipt út skilyrðinu dist(v) > dist(u) + 1 út fyrir skilyrðið dist(v) = ∞ í breiddarleit?

<p>Alltaf, þau eru jafngild. (C)</p> Signup and view all the answers

Hvað er markmiðið með því að finna stysta veg milli tveggja borga?

<p>Að finna leiðina sem lágmarkar aksturstíma, þar sem hnútar eru borgir og leggir eru vegir. (C)</p> Signup and view all the answers

Af hverju er mikilvægt að reikna út stysta mögulega veginn?

<p>Til að spara tíma og eldsneyti í ferðalögum. (D)</p> Signup and view all the answers

Í hvaða tilfelli er Single Source Shortest Path (SSSP) vandamálið gagnlegt?

<p>Þegar þarf að finna stysta veg frá einum upphafspunkti til allra annarra punkta í neti. (D)</p> Signup and view all the answers

Hvað táknar hvert hlutfall stysta vegar í stærra samhengi?

<p>Sérhver hluti stysta vegar er einnig stysti vegur. (A)</p> Signup and view all the answers

Hvers vegna er mikilvægt að huga að neikvæðum vogtölum í leggjum?

<p>Til að geta nýtt sér leiðir sem gefa hagnað eða afslátt. (B)</p> Signup and view all the answers

Hvaða vandkvæði geta neikvæðar vogtölur valdið?

<p>Neikvæðar vogtölur geta leitt til endalausra hringrása þar sem leiðin verður endalaust styttri. (C)</p> Signup and view all the answers

Hvers vegna er breiddarleit notuð í óvegnum netum?

<p>Til að finna stystu leiðir þegar allir leggir hafa sama vægi. (B)</p> Signup and view all the answers

Í upphafi reikniritsins er hnúturinn s tekinn fyrir og settur í biðröð, hvernig hefur breiddarleitin áhrif á þetta?

<p>Þetta er upphafspunkturinn sem reikniritið notar til að leita. (B)</p> Signup and view all the answers

Hvað gerist þegar breiddarleitin finnur spenntan legg?

<p>Hún slakar á leggnum, uppfærir fjarlægðina og foreldrið, og setur hnútinn síðan aftan á biðröðina. (B)</p> Signup and view all the answers

Flashcards

Shortest Path Problem

Find the shortest path P from a start node s to an end node t in a weighted, directed graph G. The edge weights are w.

Single Source Shortest Path (SSSP)

A more general problem than finding the shortest path between two specific nodes. It finds the shortest paths from a source node to all other nodes in the network.

Shortest Path Tree

If the shortest paths from a source node are unique, they form a tree structure.

Shortest Path Tree with Multiple Optimal Paths

Even with multiple shortest paths, one path to each node can be chosen to form a tree.

Signup and view all the flashcards

Shortest Path Trees vs. Minimum spanning trees

Trees of shortest paths have a root (the starting node) and direction. Minimum spanning trees are undirected and not rooted.

Signup and view all the flashcards

Positive Edge Weights

The best approach is to assume positive weights. It also makes sense if these are distances or times.

Signup and view all the flashcards

Negative Edge Weights

These can indicate profit instead of cost and are common.

Signup and view all the flashcards

Negative Cycles

It indicates an unsolvable problem without more constraints.

Signup and view all the flashcards

Dijkstra Algorithm

Calculates shortest paths with non-negative edge weights.

Signup and view all the flashcards

Bellman-Ford & Moore Algorithms

These rely on edge relaxation and finds paths even with negative edges.

Signup and view all the flashcards

Ford's SSSP Algorithm

Used to describe multiple shortest path algorithms, first presented by Lester Ford in 1956.

Signup and view all the flashcards

SSSP Node Values

Each node v stores a tentative distance and a parent node in the path.

Signup and view all the flashcards

Tense Edges

If dist(u) + w(u -> v) < dist(v) then the edge needs to be updated.

Signup and view all the flashcards

Relaxing an Edge

Reduce overestimation by refining the distance to the node.

Signup and view all the flashcards

Ford SSSP Process

Relax tense edges until none remain. When there is nothing left, the path is solved.

Signup and view all the flashcards

Breadth-First Search (BFS)

It visits layers of the graph systematically at uniform length from the starting node. It can do this using First In First Out.

Signup and view all the flashcards

BFS Queue

Initially contains only the starting node s.

Signup and view all the flashcards

BFS Edge Processing

Explore all outgoing edges u → v and relaxes the edge, putting v in the queue.

Signup and view all the flashcards

BFS Phases

Terminate phase with X.

Signup and view all the flashcards

Study Notes

  • Study notes generated from the provided text.

Overview

  • Focus is on shortest paths in graphs.

Shortest Paths

  • Given a weighted graph G = (V, E, w) with two specific nodes, the goal is to find the shortest path P from node s to node t.
  • The total weight of path P is minimized.
  • Hnodes are cities, edges are roads, and weights are travel times.

General Problem: Single Source Shortest Path (SSSP)

  • Many algorithms finding the shortest path between two nodes solve a more general problem.
  • It finds the shortest path from the starting node s to all other nodes in the network.
  • Solution usually involves constructing a tree of shortest paths rooted at s.

Properties of Shortest Paths

  • If the shortest paths are unique, they form a tree.
  • Every subpath of a shortest path is also a shortest path.
  • Even with multiple shortest paths, a single path to each node can be chosen to form a tree

Shortest Path Tree vs. Minimum Spanning Tree

  • Two distinct types of trees.
  • Shortest path trees are rooted and directed.
  • Minimum spanning trees are undirected and unrooted.
  • Shortest path trees are more suitable for directed graphs
  • Minimum spanning trees are better for undirected graphs.
  • Unique edge weights ensure a single minimum spanning tree, but multiple shortest path trees may exist depending on the starting node.
  • Shortest path trees may use different edges than the minimum spanning tree.

Negative Weights

  • Shortest path problems typically assume positive edge weights.
  • However, negative weights can be useful.

Negative Cycles

  • Can cause issues in shortest path problems, potentially leading to undefined shortest paths.
  • The shortest path from s to t exists if there's a path and no path from s to t intersects a negative cycle.
  • If a path touches a negative cycle, a shorter path exists by traversing the cycle one more time.
  • These cases technically involve finding shortest walks, not shortest paths.
  • If a shortest walk exists it must be a simple path.
  • Finding the simple shortest path when negative cycles exist is NP-hard

Negative Weight Notes and Undirected Graphs

  • The focus may be on directed graphs when negative weights are involved.
  • Some algorithms can work on undirected graphs with modifications if negative weights are not allowed.

Handling Negative Weights

  • Handling negative weights in undirected graphs is more complex
  • Replacing an undirected edge with negative weight creates a negative cycle and requires some additional work.
  • Hedges that contain negative weights may no longer be the shortest path

Non-negative Edges

  • The set of all the shortest path cannot create a tree

Undirected and Negative Weights

  • Course work does not cover undirected nets with negative weights
  • The simplest way to find the shortest path in undirected nets with negative weight, is to do a transformation.
  • The transformation has a time complexity of O(VE + V * V log V)
  • The process builds on transfers of maximum weighted matching

Single Source Shortest Path Algorithms

  • (SSSP) algorithms described
  • Many SSSP algorithms can be seen as specific versions of one general algorithm.
  • The general algorithm was first suggested my Lester Ford in 1956
  • The algorithm was published independently by George Dantzig in 1957 and George Minty in 1958

SSSP algorithm node values

  • Each node v stores two values related to tentative path s ~ v
  • dist(v) is the length of the tentative path s ~ v, or infinite if no such path exists
  • pred(v) is the parent of v on the path s ~ v, or Null if no parent exists

Initialize SSSP algorithm

  • Node distances and parents are initialized as shown

Spanning Edges are relaxed

  • An edge u -> v is relaxed is dist(u) + w(u -> v) < dist(v)

Tentative path assumptions

  • If u -> v is relaxed then the tentative path s ~ v is wrong, because s ~ u -> v is shorter

Repairing tentative paths

  • repair or lower the cost, by relaxing the nodes
  • An edge u -> v that is tense is relaxed until there are no more tense edges left

Correctness of Ford SSSP Algorithm, it can be shown that:

  • The parent pointers define a correct shortest-path tree
  • Each value dist(v) is the true distance of its shortest path from s to v.
  • If s can't reach v, dist(v) = infinity.
  • If a negative cycle can be reached from s, the algorithm never stops.

Ford Algorithm Proofs

  • The Ford algorithm is proved through the affirmational statements that hold true:
    • For any time in the algorithms iteration, dist(v) is either infinite, or the length from s to v
    • If the net has no negative circles, the dist(v) is either infinite or the length of the line from s to v
    • If there are not negative circles, then dist(v) is in relation to length between s and v
    • All nodes in G do not have spenntur then dist(v)

Ford Algorithm Implementations

  • The implementations can alter based on different types of nets

Breadth-First Search (BFS)

  • A type of Ford Algorithm
  • Used for unweighted nets
  • Uses a queue (FIFO) to hold nodes.
  • Initially, the queue contains only the starting node s.
  • Each vertex u is taken from the queue.
  • Slacks the line u -> v, and v is added to the queue
  • Once the queue is empty, returns to start

Breadth-First Search Phase Tracking

  • Make it easier to follow processes by adding phases.
  • Phases can be tracked in the queue.
  • The algorithm adds a phase to the queue and then goes through the nodes.
  • Phases begin and return during the marking of the queue.
  • The first phase starts by queuing the starting node
  • Phases are ignored, only really used to mark the queue.
  • Gives a more accurate timeline and process flow.

Important Facts about BFS with distance (v)

  • BFS gives the distances in a non-decreasing order; the distances never increase.
  • The line dist(v) = dist(u) + 1 runs only once during each node visit.
  • pred(v) can be the distance in a path dist(v) and can then get checked.
  • The line dist(v) > dist(u) comes from the distances given from dist(u) + 1

When BFS Ends

  • BFS ends when path dist(v) is the smallest G can make it from vertex s -> v.
  • Distance (v) and the distance it creates helps identify the smallest distance it has.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser