Yuav ua li cas koj pom txoj kev luv tshaj plaws hauv daim duab qhia?
Yuav ua li cas koj pom txoj kev luv tshaj plaws hauv daim duab qhia?

Video: Yuav ua li cas koj pom txoj kev luv tshaj plaws hauv daim duab qhia?

Video: Yuav ua li cas koj pom txoj kev luv tshaj plaws hauv daim duab qhia?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Tej zaum
Anonim

Muab qhov hnyav Qhia Acyclic Daim duab thiab ib qho chaw vertex hauv lub daim duab , nrhiav cov txoj kev luv tshaj plaws los ntawm muab qhov chaw rau tag nrho lwm cov vertices.

Txoj kev luv tshaj plaws nyob rau hauv Directed Acyclic Graph

  1. Initialize dist = {INF, INF,….}
  2. Tsim ib qho kev txiav txim toplogical ntawm tag nrho cov vertices.
  3. Ua raws li txhua qhov vertex koj nyob rau hauv kev txiav txim topological.

Ua li no, ua li cas koj pom txoj kev luv tshaj plaws ntawm daim duab?

Cov kauj ruam algorithm: Rau a daim duab nrog vertices: Pib lub txoj kev luv tshaj plaws nruab nrab ntawm txhua qhov vertices nrog Infinity. Nrhiav txhua khub txoj kev luv tshaj plaws uas siv intermediate vertices, ces nrhiav tus txoj kev luv tshaj plaws uas siv intermediate vertex thiab thiaj li nyob rau.. mus txog rau thaum siv tag nrho cov vertices li intermediate nodes.

Ib sab saum toj no, koj yuav nrhiav txoj hauv kev luv tshaj hauv DFS li cas? Tsis yog, koj siv tsis tau DFS rau nrhiav txoj kev luv tshaj plaws hauv ib daim duab tsis hnyav. Nws tsis yog li ntawd, nrhiav tus txoj kev luv tshaj plaws ntawm ob lub nodes tsuas yog daws tau los ntawm BFS.

Ib yam li ntawd, koj yuav nrhiav tau txoj hauv kev luv tshaj plaws hauv tsob ntoo li cas?

  1. Traverse ntoo (qhov tob-thawj)
  2. Khaws cov indexes (nodes)
  3. ntxiv cov nqi.
  4. ua (1) mus txog rau thaum xaus ntawm tsob ntoo.
  5. piv cov sum thiab luam txoj kev thiab sum.

Lub algorithm twg yog siv los nrhiav txoj hauv kev luv tshaj?

Dijkstra's Shortest Path Thawj algorithm

Pom zoo: