Homework of lecture, Data Structure
Problem
2
3 dfs(3)
786 368 603
5 bfs(4)
825 162 768 724 635
The number in the first line (i.e., 2) shows the number of test cases to be processed. From the second line, test cases are given, and the information for each case is provided over two lines. In the first line (line number 2 in the example above), the first number (i.e., 3) indicates the number of integers in that case, and the next string (i.e., dfs(3)) shows the location of the target number that you need to look for. In this example, the target number is on the third node of DFS.
Algorithm
- scan input data
- build elements in BST form
- scan if the first three string input is bfs or dfs
- choose appropriate searching function to be called
- scan how many times to search in string
- search
- pass the result to output file