i am unable to understand my first doubt is
here we are not using reserve but directly Giving the size and and second is the graph part
Plz explain me the 9 ques
Paste the question here , in which you are having doubt in. As i don’t have access to your quiz so i have to see the question for which you are having doubt in. Just copy the question and paste it here.
Q9. Vector STL#9 Which of the following can be used to store a simple undirected graph with N nodes? vector < int > graph [ N + 1 ] bool graph [ N + 1 ][ N + 1 ] vector < vector < int > > graph(N+1) All of them.
You can use any of them as:
bool graph[N+1][N+1] -> this is adjacency matrix , u can mark graph[i][j]=true if there exist edge between vertex i and vertex j otherwise it will remain false.
vector < vector < int > > graph(N+1)-> this is same as first one, only difference is that here we are using vector in place of array so you can use this too.
what about first option
Think it as only 1d array, how can you check if there’s an edge which exist between vertex i and vertex j
At least 2d container will be needed to show any edge. that is from i to j and j to i.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.
so how can all of them be the answer
Not all of them b & c are the answer.
Hello @mohitsingh the answer for this should be ‘all of them’ as in first option we are creating array of vector so that can also be used.
in first option we are forming the 2d array only since the vectors are dynamic arrays only.
oh yes, all of them will be correct
a) can be used to represent adjacency matrix
Haven’t used that one cause of it’s bad space complexity, it was my bad.