Delivered by FeedBurner

New Answers in your Inbox

CS62 2001 December 4 (ii) algorithm to implement breadth first search

Question: Write an algorithm / Program to implement breadth first search and also describe the program/algorithm in terms of data structure and its functioning. [CS62, 2001 December, Question 4(ii) ]

Answer:
The algorithm to implement breadth first search is listed below:
Step 1: Initialization of vertices by assigning the vaule 1 to dummy.
Step 2: Place the beginning vertix in Z and set it to halt by assigning 0 to dummy
Step 3: Loop through step 5 until Z becomes NULL.
Step 4: Delete the front vertex of Z. Manipulate the front vertex and set to active state by assigning -1 to dummy.
Step 5: Towards the back of Z, add all the active neighbors of the front vertex y assigning 1 to Dummy, and set them to halt by again assigning 0 to Dummy.
Step 6: Quit

No comments: