I'm currently writing code for an assignment that deals with cities and bridges. I have to print the cities and bridges out in their respected districts such as:
//unorganized inputs from user given the # of "paths" we need
4 // the # of paths
1 2 5 // 1 = city , 2 = city, 5 = bridge length
6 7 5 // 6 = city , 7 = city, 5 = bridge length
2 3 7 // 2 = city , 3 = city, 7 = bridge length
6 9 7 // 6 = city , 9 = city, 7 = bridge length
After run through program, it will be sorted as:
first district
1 2 5
2 3 7
2nd district
6 7 5
6 9 7
Now, I'll be reading these inputs through cin. I want to store all the possible paths such as 1 2 5 into an array and then sort and organize them through the program. The problem is that I may have over 500,000 paths from the user. I want to create 500k dynamic arrays. Will this cause serious problems in terms of memory?
I have looked at other possible ways of solving this such as kruskal's algorithm and disjoint sets(I think is the most useful). I'm having a very hard time understanding the coding of disjoint sets, I figured I try a way I'm more familiar with.
Any help with where to store the values and compare and organize them would be great. Links to places where I read info on this would help. I've read a lot over the past few days. Hasn't helped much.
To sum it all up, my questions are:
- Will 500k dynamic arrays cause serious problems in terms of memory?
- Where to store the values and compare and organize them given the paths?