GATE CSE
First time here? Checkout the FAQ!
x
+3 votes
152 views
You are given $n$ positive integers, $d_1, d_2 \dots d_n$, each greater than 0. Design a greedy algorithm to test whether these integers correspond to the degrees of some $n$-vertex simple undirected graph $G = (V, E)$. [A simple graph has no self-loops and at most one edge between any pair of vertices].
asked in Algorithms by Veteran (92.5k points) 972 2329 3115
edited by | 152 views

1 Answer

+6 votes
Best answer
  1. Sort the degrees in non-increasing order.
  2. Pick up the highest degree ( let us say it a), remove it from the list of degrees and subtract 1 from next a degrees in list.
  3. Repeat Step $2$ until : 
  • If we get all $0$ entries in list $\color{red}{\Rightarrow}$ Simple Graph exits
  • If we get a negative entry or not enough entries to subtract 1 in step 2 $\color{red}{\Rightarrow}$ Simple Graph does not exist

Read More : http://goo.gl/4u3nfh

Let's take a example : $3, 2, 1, 2$

Step 1 : Sort the degree sequence : $3, 2, 2, 1$

Step 2: Pick 3, Remove 3 from list and from next 3 elements subtract 1,   $ Result : (1,1,0) $

       Again repeat step 2 : select 1, Remove 1 and from next 1 subtract 1,  $Result : (0,0,0) $

Thus, a simple graph exists for the following degree-sequence.

answered by Veteran (27.3k points) 19 71 243
selected by
The link was very helpful. A must read.

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23398 Points

  2. Bikram

    17078 Points

  3. Habibkhan

    8280 Points

  4. srestha

    6300 Points

  5. Debashish Deka

    5438 Points

  6. jothee

    4978 Points

  7. Sachin Mittal 1

    4772 Points

  8. joshi_nitish

    4352 Points

  9. sushmita

    3970 Points

  10. Rishi yadav

    3804 Points


Recent Badges

Popular Question sh!va
Popular Question sh!va
Regular Rishabh Gupta 2
Popular Question Sunil8860
Reader Rajesh Veeranki 2
Notable Question rahul sharma 5
Commentator Shivam Chauhan
Notable Question set2018
Nice Comment srestha
Notable Question set2018
27,325 questions
35,177 answers
84,123 comments
33,280 users