why did you use bool *visited = new bool[V]{0} instead of bool visited[V] ? is it because the former allows you to initialize the elements in array to false on declaration?
I have the same doubt for int *count = new int[N]{0} as well
Doubt regarding the coding part
bool *visited = new bool[V]{0} … is dynamic way of initializing
bool visited[V] … is static way
bool visited[V] ={0} can also be used.
1 Like
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.
why would we want to use the dynamic way over the static way? Is it becuase it requires the value of V at compile time in static way?
Yes, in competitive programming you can use static everything, won’t be an issue.