<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ankur Lahiry</title>
    <description>The latest articles on DEV Community by Ankur Lahiry (@alahiry098).</description>
    <link>https://dev.to/alahiry098</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F508424%2F173e7b92-6035-4c00-bf90-bebae174d466.jpeg</url>
      <title>DEV Community: Ankur Lahiry</title>
      <link>https://dev.to/alahiry098</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alahiry098"/>
    <language>en</language>
    <item>
      <title>Can you create a random graph for me?</title>
      <dc:creator>Ankur Lahiry</dc:creator>
      <pubDate>Tue, 10 Jan 2023 09:54:58 +0000</pubDate>
      <link>https://dev.to/alahiry098/can-you-create-a-random-graph-for-me-28k7</link>
      <guid>https://dev.to/alahiry098/can-you-create-a-random-graph-for-me-28k7</guid>
      <description>&lt;p&gt;It is pretty straightforward to ask others to generate a random number, right? Ask your friends to create a random number from 1 to 10, and they will generate a random number in the range. &lt;/p&gt;

&lt;p&gt;But the question is, can they create a random graph for you? &lt;/p&gt;

&lt;p&gt;Before jumping into the question, let's think of a scenario. Suppose, you have invited hundreds of your friends, and those friends or colleagues don't know each other earlier. When you announce start of your party, wait, you will see there will have some small clusters forming, and eventually the members will move from one clusters to another, will create a random graph for you. &lt;/p&gt;

&lt;p&gt;In case of above scenario, let's pick up 3 persons, Bob, Rob and Daniel. Let's assume that, Bob and Rob have met earlier. That mentioned about an edge with Bob and Rob. Some moments later, Bob have changed his place and moved to Daniel. On top of that, we assume at the time of the party, Rob and Daniel never met each other. Although they never met each other, there is a subtle path between them. That is the way the random graph is being formed. The following image will show you the scenario how a random graph generates in our real life.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe39wla4ykp0a0mq6asz7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe39wla4ykp0a0mq6asz7.jpg" alt="Source: http://networksciencebook.com"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Definition
&lt;/h2&gt;

&lt;p&gt;We can define random graphs in two ways:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;G(N, L):&lt;/strong&gt; N Nodes are being connected with L randomly picked edges. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;G(N, p):&lt;/strong&gt; N nodes are being connected with each other with a probability of p.&lt;/p&gt;

&lt;p&gt;The second definition, &lt;strong&gt;G(N, p)&lt;/strong&gt; is widely used and we will describe this in the following sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Algorithm
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def random_graph(N, p):
    graph = initialize an empty graph with isolated N nodes
    node_pairs = N * (N-1) / 2
    for every pair in node_pairs:
        random_probability = random(0,1)
        if random_probability &amp;gt;= p:
           graph.add_edge(pair)
    return graph    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Implementation
&lt;/h2&gt;

&lt;p&gt;you will find the detail implementation &lt;a href="https://github.com/AnkurLahiry/RandomGraph" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Some of the graphs of Node 10 with probability 0.3&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuvinj401jsm943vvvh4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuvinj401jsm943vvvh4.png" alt="Graph 1"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9b9gi1sb5w1ffpe9peyv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9b9gi1sb5w1ffpe9peyv.png" alt="Graph 2"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx61p9oupx8lxovrjdvvu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fx61p9oupx8lxovrjdvvu.png" alt="Graph 3"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn96n32ni9qxg2dct6w8s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn96n32ni9qxg2dct6w8s.png" alt="Graph 4"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81x5p0ejai4oh45nk3ug.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F81x5p0ejai4oh45nk3ug.png" alt="Graph 5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is how you can create a random graph.&lt;/p&gt;

</description>
      <category>network</category>
      <category>graph</category>
      <category>datastructure</category>
      <category>graphstructure</category>
    </item>
  </channel>
</rss>
