Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7014327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:30:25+00:00 2026-05-27T22:30:25+00:00

I have a weighted graph with (in practice) up to 50,000 vertices. Given a

  • 0

I have a weighted graph with (in practice) up to 50,000 vertices. Given a vertex, I want to randomly choose an adjacent vertex based on the relative weights of all adjacent edges.

How should I store this graph in memory so that making the selection is efficient? What is the best algorithm? It could be as simple as a key value store for each vertex, but that might not lend itself to the most efficient algorithm. I’ll also need to be able update the network.

Note that I’d like to take only one “step” at a time.


More Formally: Given a weighted, directed, and potentially complete graph, let W(a,b) be the weight of edge a->b and let Wa be the sum of all edges from a. Given an input vertex v, I want to choose a vertex randomly where the likelihood of choosing vertex x is W(v,x) / Wv

Example:

Say W(v,a) = 2, W(v,b) = 1, W(v,c) = 1.

Given input v, the function should return a with probability 0.5 and b or c with probability 0.25.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:30:26+00:00Added an answer on May 27, 2026 at 10:30 pm

    If you are concerned about the performance of generating the random walk you may use the alias method to build a datastructure which fits your requirements of choosing a random outgoing edge quite well. The overhead is just that you have to assign each directed edge a probability weight and a so-called alias-edge.

    So for each note you have a vector of outgoing edges together with the weight and the alias edge. Then you may choose random edges in constant time (only the generation of th edata structure is linear time with respect to number of total edges or number of node edges). In the example the edge is denoted by ->[NODE] and node v corresponds to the example given above:

    Node v
        ->a (p=1,   alias= ...)
        ->b (p=3/4, alias= ->a)
        ->c (p=3/4, alias= ->a)
    
    Node a
        ->c (p=1/2, alias= ->b)
        ->b (p=1,   alias= ...)
    
    ...
    

    If you want to choose an outgoing edge (i.e. the next node) you just have to generate a single random number r uniform from interval [0,1).

    You then get no=floor(N[v] * r) and pv=frac(N[v] * r) where N[v] is the number of outgoing edges. I.e. you pick each edge with the exact same probability (namely 1/3 in the example of node v).

    Then you compare the assigned probability p of this edge with the generated value pv. If pv is less you keep the edge selected before, otherwise you choose its alias edge.

    If for example we have r=0.6 from our random number generator we have

    no = floor(0.6*3) = 1 
    pv = frac(0.6*3) = 0.8
    

    Therefore we choose the second outgoing edge (note the index starts with zero) which is

    ->b (p=3/4, alias= ->a)
    

    and switch to the alias edge ->a since p=3/4 < pv.

    For the example of node v we therefore

    • choose edge b with probability 1/3*3/4 (i.e. whenever no=1 and pv<3/4)
    • choose edge c with probability 1/3*3/4 (i.e. whenever no=2 and pv<3/4)
    • choose edge a with probability 1/3 + 1/3*1/4 + 1/3*1/4 (i.e. whenever no=0 or pv>=3/4)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a weighted, directed graph which is dense with around 20,000 nodes. Given
Suppose I have a weighted non-directed graph G = (V,E). Each vertex has a
I have got an undirected weighted connected graph. If I select one vertex I
I have an undirected weighted graph and derive a new graph based on groups
I have a directed, weighted, complete graph with 100 vertices. The vertices represent movies,
I have a non-weighted DAG graph. What I want to do is to find
I have a simple weighted graph A 1 / \\ 0.5 / \\0.5 B
I have a directed, positive weighted graph. Each edge have a cost of use.
In a sample problem, I'm given a MST T for a weighted graph G
What algorithm I can use for problem like this: Have a graph positive weighted,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.