Learn a little bit every day algorithm-SPFA algorithm __ algorithm

Source: Internet
Author: User
SPFA Algorithm


definition


Inventor: Dengfanding

Time: 1994

Time complexity O (e)

Principle: A FIFO queue, an array d that holds the shortest distance.

When initializing: There is only one source point in the queue. That is, the starting point itself. The value in D is the maximum value except that the starting point has its own distance of 0.

Queue={v0},d={0,max,max,max...max}, then the VO is taken out of the value of Max at the distance from the J vertex to the 0+ (Vo to its proximity point distance). If Max is greater than this value, the index value J of Max is placed in the queue. That is, VJ is placed in the queue. Traverse through to know that the queue is empty. Traversal ends. The median of D is the shortest distance from the starting point of each point.


The figure above is an example. The distance from V0 to V1 is 10 from 2,v0 to V4.

v0->v1=2

v0-v4=10

V1-v2=3

V1-v4=7

V2-v3=4

V3-v4=5

V4-v2=6

Initial value Queue={v0},d={0,max,max,max,max};

First step take V0:v0-v1=2,2<max, update Queue={0,2,max,max,max}, add V1 to D, d={v1}

V0-v4=10,10<max, Update queue={0,2,max,max,10}, add V4 to D, d={v1,v4}

The second step takes v1:v1-v2=3, then V0-v1-v2 = 2+3=5;5<max, update queue={0,2,5,max,10},d={v4,v2}

V1-v4=7, then v0-v1-v4=2+7=9<10, update queue={0,2,5,max,9}, add V4 to D, because V4 already exists, d={v4,v2}

The third step takes v4:v4-v2=6, then v0-v4-v2=10+6>5, does not update the queue. D={V2}

The fourth step takes v2:v2-v3=4, then v0-v2-v3= 5+4=9<queue. Update queue={0,2,5,9,9}, add V3 to D, d={v3}

Fifth step take v3:v3-v4=5, then v0-v3-v4 = 9+5=14>9, not update, D is empty, end.

OY.


Complexity of Time


O (e)


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.