Puas yog graph txuas algorithm?
Puas yog graph txuas algorithm?

Video: Puas yog graph txuas algorithm?

Video: Puas yog graph txuas algorithm?
Video: Finance with Python! Net Present Value (NPV) 2024, Kaum ib hlis
Anonim

Yog ib qho tsis ncaj ncees lawm daim duab yog txuas , tsuas muaj ib txuas tiv thaiv. Peb tuaj yeem siv qhov kev sib tw algorithm , tog twg los qhov tob-ua ntej lossis dav-thawj, kom pom qhov txuas Cheebtsam ntawm undirected daim duab . Yog hais tias peb ua ib tug traversal pib los ntawm ib tug vertex v, ces peb yuav mus saib tag nrho cov vertices uas yuav ncav cuag los ntawm v.

Hais txog qhov no, koj yuav pom li cas yog tias daim duab txuas nrog?

Pib ntawm txhua qhov arbitrary ntawm tus daim duab , G. Ua los ntawm cov node siv qhov tob-thawj lossis dav-thawj nrhiav , suav tag nrho cov nodes mus txog. Ib zaug lub daim duab tau hla dhau lawm, yog tus naj npawb ntawm cov nodes suav yog sib npaug rau cov nodes ntawm G, tus daim duab txuas nrog ; txwv tsis pub nws raug txiav.

Tsis tas li ntawd, koj tuaj yeem qhia tau li cas yog tias daim duab txuas nrog hauv Python? Nws tuaj yeem txiav txim siab nrog ib qho yooj yim algorithm seb daim duab txuas nrog:

  1. Xaiv qhov kev txiav txim siab x ntawm daim duab G raws li qhov pib.
  2. Txiav txim siab teeb A ntawm tag nrho cov nodes uas tuaj yeem ncav cuag los ntawm x.
  3. Yog tias A sib npaug rau cov kab ntawm G, daim duab txuas nrog; txwv tsis pub nws raug txiav.

Kuj Paub, kev sib txuas ntawm daim duab yog dab tsi?

A daim duab tau hais tias yuav txuas yog tias muaj txoj hauv kev ntawm txhua khub ntawm vertex. Los ntawm txhua qhov vertex mus rau lwm qhov vertex, yuav tsum muaj qee txoj hauv kev mus rau traverse. Qhov ntawd yog hu ua kev sib txuas ntawm ib daim duab . A daim duab nrog ntau qhov kev sib txuas ntawm qhov sib txuas thiab cov npoo tau hais tias yuav tsum tau txiav.

Puas yog daim duab yooj yim txuas?

A daim duab yooj yim txhais tau hais tias tsuas muaj ib ntug ntawm ob lub vertices, thiab a txuas daim duab txhais tau hais tias muaj ib txoj hauv kev nruab nrab ntawm ob lub vertices hauv lub daim duab.

Pom zoo: