You are not logged in. Please login at to post your questions!


let see how much deep u know about segmentation fault in c++


Question link - link text

solution link -link text

I want to know why i am getting segmentation fault on answer where my code is working for smaller input. It work on on dijkistra algo and code help is from geeksforgeeks code link

for more test cases refer to hackerrank

And this question form hackerrank week of code 38

asked 25 Jun '18, 16:50

gyanendra371's gravatar image

accept rate: 33%

to understand the code quickly u can visit geeksforgeeks link given

(25 Jun '18, 16:56) gyanendra3713★

Well all those who can suggest possible reason for segmentation fault are most welcome , i think it will help others to know about segmentation fault or runtime error which is hard to debug. And for any assistance just comment here i will serve it.

(25 Jun '18, 16:58) gyanendra3713★

Hi @gyanendra371,

I have check your code and the ONE MAJOR BUG in your code is that you have created the graph using adjacency matrix and not adjacency list.

The given constraint for number of nodes is 1≤N≤104 and in most of the programming languages you can allocate at most 106 to 107 memory space. But, in your code you have created the graph as long graph[n][n] , which would try to allocated 108 memory locations and hence would fail.

So, in my opinion you should learn to build graph using adjacency list.

You can check my accepted solution here.

You can ping me in case of any doubts.

Hope this helps!! Happy Coding!! :-)


answered 25 Jun '18, 17:28

brijwasi1995's gravatar image

accept rate: 11%

hey can u provide reference for dijkistra algo using adjancey list which can store the shortest path @brijwasi1995 and would u mind adding little bit of comment in ur code that can help lot. And thanks for giving ur precios time .

(25 Jun '18, 17:58) gyanendra3713★

Hi, you can learn about adjacency list and shortest path algorithm implementation from the following links.

  1. Adjacency List -

  2. Shortest path algorithm implementation -

(25 Jun '18, 18:41) brijwasi19952★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 25 Jun '18, 16:50

question was seen: 188 times

last updated: 25 Jun '18, 18:41