if(processed.containsKey(key)) {
continue;
}
ma’am even if you remove this piece of code there will be no issue in the answer. Since, we are checking the same condition inside of the while loop. The inner one was sufficient. So why are you using it above again.
Breadth First traversal
Hi @D19CRXPP0041,
Yes there will be no issue but we will going inside the while loop unnecessarily as a key which is already processed will also be enqueued. So to prevent that we add a check so that already processed nodes do not enter the queue.
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.