Question

Provide pseudocode for either preorder traversal or post-order traversal for general trees without recursion (hint: use a sta

Provide pseudocode for breadth-first (level order) traversal for general trees. All I need is the breadth-first one, I know the post-order one. So far I knew stack, list, Queues.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.

The BFS algorithm is implmented by: Using a queue to store the nodes in the toVisitNodes data structure.

Pseudo code:

   Set all nodes to "not visited";

   q = new Queue();

   q.enqueue(initial node);

   while ( q ≠ empty ) do
   {
      x = q.dequeue();

      if ( x has not been visited )
      {
         visited[x] = true;         // Visit node x !

         for ( every edge (x, y)  /* we are using all edges ! */ )    
            if ( y has not been visited )   
               q.enqueue(y);       // Use the edge (x,y) !!!
      }
   }

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Provide pseudocode for breadth-first (level order) traversal for general trees. All I need is the breadth-first...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Programming Traversal Methods in C++ (depth first & breadth first) Need solution ASAP any help is...

    Programming Traversal Methods in C++ (depth first & breadth first) Need solution ASAP any help is much appreciated. read a set of data representing a directed, unweighted graph build an in-memory graph structure using the data display the graph using depth-first traversal display the graph using breadth-first traversal Input data - The data consists of records like this: 16 3 15 4 -1 This represents a vertex 16 with neighbors 3, 15, and 4. The -1 is the indicator that...

  • 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Yo...

    please explain each line of code! ( in python ) 1. Write a recursive function that returns the sum of all even integers in a LinkedBinaryTree. Your function should take one parameter, root node. You may assume that the tree only contains integers. You may not call any methods from the LinkedBinaryTree class. Specifically, you should traverse the tree in your function def binary tree even sum (root): Returns the sum of al1 even integers in the binary tree 2....

  • Problemi: Create a new Java Application that has the following methods: 1. A method that generate...

    Problemi: Create a new Java Application that has the following methods: 1. A method that generate a binary search tree (BST) where the number of nodes and the range of the values are from a file 2. A recursive method to print the BST in preorder traversal 3. A recursive method to print the BST in post-order traversal 4. A recursive method to print the BST in in-order traversal 5. A method to find the largest value in a BST...

  • can anyone provide answers with explaination ? thanks a lot I. In the example of recycling...

    can anyone provide answers with explaination ? thanks a lot I. In the example of recycling the elements of a list in O1) time, which situation holds? A. Both lists are circular B. Both ists are not circular C. The list to be recycled is circular, the garbage list is not D. The garbage list is circular, the list to be recycled is not 2. What is the worst-case time to perform MINIMUML) for a sorted, doubly-linked list with nodes?...

  • Hello I need help with this please I need to follow instructions in order to get...

    Hello I need help with this please I need to follow instructions in order to get all points. This is from principals of accounting and please post in a picture. It needs to be detailed Thank you bellow are some examples of the answers I need, I need to post an answer for both examples as well five sentences at least EXAMPLE 1 NEED AN ANSWER EXAMPLE 2 NEED AN ANSWER THANK YOU In this chapter we were provided a...

  • I need help with this code, I'm stuck on it, please remember step 4, I'm very...

    I need help with this code, I'm stuck on it, please remember step 4, I'm very much stuck on that part. It says something about putting how many times it appears Assignment #1: Sorting with Binary Search Tree Through this programming assignment, the students will learn to do the following: Know how to process command line arguments. 1 Perform basic file I/O. 2. Use structs, pointers, and strings. Use dynamic memory. 3. 4. This assignment asks you to sort the...

  • can someone help with the blue reader project, please? I have the journal entries I need...

    can someone help with the blue reader project, please? I have the journal entries I need help with journal ledger and trial balance so I can I do the financial statements. thanks can someone help me the ledger and trial balance please, I posted all the information about the picture Credit The accounting cycle illustrated below is designed to provide information about a company's profitability for lack thereof) along with many other important financial characteristics. This same accounting Cycle is...

  • I had a question about Step 5-9. I already completed the general journal with the entries...

    I had a question about Step 5-9. I already completed the general journal with the entries into the general ledger. Now I need help creating the adjusted trial balance, I cant get it to equal to $20,743. Also, I need help completing the financial statements: income statements, statement of owners equity, and a balance sheet. *Net Income has to equal $1024 and total assets has to equal $18,354. The question is how can I balance out my adjusted trial balance...

  • I need this in C++. This is all one question Program 2: Linked List Class For...

    I need this in C++. This is all one question Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we'll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct...

  • I need help in C++ implementing binary search tree. I have the .h file for the...

    I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT