Question

For the sixth question of this assignment, you must design and implement a function that takes...

For the sixth question of this assignment, you must design and implement a function that takes a Graph as its first argument and a Node as its second argument and has a list of Nodes (i.e., a [Node] as its return value). The return value must be the list of Nodes traversed by a breadth-first search traversal of the Graph argument, starting from the Node argument, in the order in which they appear during the traversal. When your breadth-first search algorithm has a "choice" of which Node to explore, it must process the nodes in numerical order. As a clarifying example, please note that the breadth first search traversal of the Graph included as the previous example starting from Node 1 should be [1, 3, 4, 2]

(Programming in Haskell)

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

#include "main.h"
int distinctWord(string fileName)
{
   fstream f(fileName.c_str());
   map< string,set<int> > dict;
   if(f==NULL)
   {
       cout<<"file doest opened"<<endl;
       exit(1);
   }
   string word;
   string line;
   int lineNo=0;
   map< string,set<int> >::iterator itr;
   set<int>::iterator i;
   while(getline(f,line))
   {   lineNo++;       //for counting of current line no
       stringstream iss(line);
       while(iss >> word)
       {  
       dict[word].insert(lineNo);   //storing word as key and set as value which store line in which word present
       }
   }
   for( itr=dict.begin();itr!=dict.end();itr++)
   {
       cout<<"word: "<<itr->first<<endl<<"lines: ";
       //printing the set values
       for(i= (itr->second).begin();i!=(itr->second).end();i++)
           cout<<*i<<" ";
       cout<<endl;
   }
   return 0;
}

int main(){
   string s;
   cout<<"enter the file location: ";
   cin>>s;
  
   distinctWord(s);
   return 0;
  
}

Add a comment
Know the answer?
Add Answer to:
For the sixth question of this assignment, you must design and implement a function that takes...
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
  • QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent...

    QUESTION 1 In a tree, a ____ is a node with successor nodes. root child descendent parent sibling QUESTION 2 In a tree, the ____ is a measure of the distance from a node to the root. count degree branch height level QUESTION 3 Which of the following is not a characteristic of a binary search tree? Each node has zero, one, or two successors. The preorder traversal processes the node first, then the left subtree, and then the right...

  • Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive...

    Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive function in Haskell that takes a list of characters as an argument and returns a list that contains only every third element from the argument list in the same order. As a clarifying example, this function, when passed the argument list “ABCDEFGHIJKLMNO”, should return the list “ CFILO”. It should also be noted that your function must work (i.e., not terminate with an error)...

  • # Problem 4 problem4_breadth_first_traversal = [0,] problem4_depth_first_traversal = [0,] def bfs(g,start): start.set...

    # Problem 4 problem4_breadth_first_traversal = [0,] problem4_depth_first_traversal = [0,] def bfs(g,start): start.setDistance(0) start.setPred(None) vertQueue = Queue() vertQueue.enqueue(start) while (vertQueue.size() > 0): currentVert = vertQueue.dequeue() for nbr in currentVert.getConnections(): if (nbr.getColor() == 'white'): nbr.setColor('gray') nbr.setDistance(currentVert.getDistance() + 1) nbr.setPred(currentVert) vertQueue.enqueue(nbr) currentVert.setColor('black') class DFSGraph(Graph): def __init__(self): super().__init__() self.time = 0 def dfs(self): for aVertex in self: aVertex.setColor('white') aVertex.setPred(-1) for aVertex in self: if aVertex.getColor() == 'white': self.dfsvisit(aVertex) def dfsvisit(self,startVertex): startVertex.setColor('gray') self.time += 1 startVertex.setDiscovery(self.time) for nextVertex in startVertex.getConnections(): if nextVertex.getColor() == 'white': nextVertex.setPred(startVertex)...

  • Please provide C language code no c++ ,txt file also needed with comment Finish task 5...

    Please provide C language code no c++ ,txt file also needed with comment Finish task 5 Task5: Breadth First Search (15 pts) · Write a program to read the graph information from the file and traverse the graph using BFS algorithm as introduced in lecture. The input for each algorithm is an undirected unweighted connected graph stored in a local file using an adjacency list. Following is the example of the input file (graph.txt) and the graph First line is...

  • Breadth-First search traversal. 100% Upvote/Thumbs up. Thank you in advance QUESTION 20 Consider an undirected, unweighted...

    Breadth-First search traversal. 100% Upvote/Thumbs up. Thank you in advance QUESTION 20 Consider an undirected, unweighted graph G = (V,E) with V = {1,2,3,4,5,6) and E = {(1,2),(1,3), (1,4),(2,3),(2,5),(3,5),(4,6).(5,6)}. What is the Breadth-First Search traversal starting at vertex 67 Build your adjacency list in ascending order. List the values separated by spaces.

  • Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the followi...

    Exercise 1 Adjacency Matrix In this part, you will implement the data model to represent a graph. Implement the following classes Node.java: This class represents a vertex in the graph. It has only a single instance variable of type int which is set in the constructor. Implement hashCode() and equals(..) methods which are both based on the number instance variable Node - int number +Node(int number); +int getNumberO; +int hashCode() +boolean equals(Object o) +String toString0) Edge.java: This class represents a...

  • Would appreciate the answer in the Java coding language please and thank you! 10d 10h left...

    Would appreciate the answer in the Java coding language please and thank you! 10d 10h left Java 7 1. Check the Structure Autocomplete Ready 1 > import java.io.*;... 10 ALL A binary tree uses a multi-node data structure where each node may have 0 to 2 child nodes, and has one stored value, its node number in this case. A tree may either be: 11 class Result { * Complete the 'isValid' function below. • An empty tree, the root...

  • Am Specification For this assignment, you will write a multi-file C program to define, implement ...

    Must be written and C, and compile with MinGW. Thank you! am Specification For this assignment, you will write a multi-file C program to define, implement and use a dynamic linked lists. Please refer to Lab 07 for the definition of a basic linked list. In this assignment you will need to use the basic ideas of a node and of a linked list of nodes to implement a suit of functions which can be used to create and maintain...

  • (true/false) All nodes in the right subtree of a node must be smaller in value than...

    (true/false) All nodes in the right subtree of a node must be smaller in value than their parent (true/false) Each node in a binary search tree may contain zero, one, or two children nodes. (true/false) It is possible to recursively process a binary search tree to print all the data in a binary search tree in sorted order. (true/false) The value of a parent must be less than all its children. (true/false) All nodes in the right subtree of a...

  • Can you complete the following code, please? Thank you. class BinaryNode: def __init__(self, valu...

    Can you complete the following code, please? Thank you. class BinaryNode: def __init__(self, value): self.__value = value self.__left = None self.__right = None self.__parent = None self.__height = 1    def getValue(self): return self.__value    def setHeight(self, height): self.__height = height    def getHeight(self): return self.__height    def setParent(self, node): self.__parent = node    def getParent(self): return self.__parent    def setLeftChild(self, child): self.__left = child child.setParent(self)    def setRightChild(self, child): self.__right = child child.setParent(self)    def createLeftChild(self, value): self.__left = BinaryNode(value)    def createRightChild(self, value): self.__right = BinaryNode(value)    def...

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