Searching Algorithms

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What are the disadvantages of BFS?

A BFS on a binary tree generally requires more memory than a DFS.

What are the advantages of BFS?

A BFS will find the shortest path between the starting point and any other reachable node. A depth-first search will not necessarily find the shortest path.

What is Binary Search?

A binary search algorithm finds an item in a sorted array in O(log n) time.

Applications of DFS: Finding Strongly Connected Components of a graph

A directed graph is called strongly connected if there is a path from each vertex in the graph to every other vertex.

Applications of DFS: Detecting cycle in a graph

A graph has cycle if and only if we see a back edge during DFS. So we can run DFS for the graph and check for back edges.

What are the advantages of DFS?

Advantages: Depth-first search on a binary tree generally requires less memory than breadth-first. Depth-first search can be easily implemented with recursion.

How can you use Binary Search built in in Java?

Arrays.binarySearch(data_type arr, data_type key) is the simplest and most efficient method to find an element in a sorted array in Java data_type can be any of the primitive data types: byte, char, double, int, float, short, long and Object as well. This returns the index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the array: the index of the first element greater than the key, or a.length if all elements in the array are less than the specified key. Note that this guarantees that the return value will be >= 0 if and only if the key is found.

Explain BFS again

BFS is a traversing algorithm where you should start traversing from a selected node (source or starting node) and traverse the graph layerwise thus exploring the neighbour nodes (nodes which are directly connected to source node). Therefore, in BFS, you must traverse all the nodes in layer 1 before you move to the nodes in layer 2.

Applications of BFS: GPS Navigation systems

Breadth First Search is used to find all neighboring locations

What is BFS?

Breadth-first search (BFS) is a method for exploring a tree or graph. In a BFS, you first explore all the nodes one step away, then all the nodes two steps away

Applications of BFS: Crawlers in Search Engines:

Crawlers build index using Breadth First. The idea is to start from source page and follow all links from source and keep doing same. Depth First Traversal can also be used for crawlers, but the advantage with Breadth First Traversal is, depth or levels of built tree can be limited.

Applications of DFS: Solving puzzles with only one solution, such as mazes

DFS can be adapted to find all solutions to a maze by only including nodes on the current path in the visited set.

What is DFS?

Depth-first search (DFS) is a method for exploring a tree or graph. In a DFS, you go as deep as possible down one path before backing up and trying a different one

What are the disadvantages of DFS?

Disadvantages A DFS doesn't necessarily find the shortest path to a node, while breadth-first search does.

What does backtracking mean in DFS?

Here, the word backtrack means that when you are moving forward and there are no more nodes along the current path, you move backwards on the same path to find nodes to traverse. All the nodes will be visited on the current path till all the unvisited nodes have been traversed after which the next path will be selected.

Explain DFS again

The DFS algorithm is a recursive algorithm that uses the idea of backtracking. It involves exhaustive searches of all the nodes by going ahead, if possible, else by backtracking.

Applications of BFS: Peer to Peer Networks

In Peer to Peer Networks like BitTorrent, Breadth First Search is used to find all neighbor nodes.

Applications of BFS: Social Networking Websites

In social networks, we can find people within a given distance 'k' from a person using Breadth First Search till 'k' levels.

Applications of BFS: Cycle detection in undirected graph:

In undirected graphs, either Breadth First Search or Depth First Search can be used to detect cycle. In directed graph, only depth first search can be used.

Applications of BFS: Explain how BFS can be used to find the shortest path in an unweighted graph

In unweighted graph, the shortest path is the path with least number of edges. With Breadth First, we always reach a vertex from given source using minimum number of edges.

What is the time complexity of DFS when using an adjacency list?

O(V+E), when implemented using the adjacency list, where V is vertices and E is edges

What is the time complexity of BFS to traverse a graph?

Time complexity of both BFS will be O(V + E), where V is the number of vertices, and E is the number of Edges. This again depends on the data structure that we user to represent the graph. If it is an adjacency matrix, it will be O(V^2) . If we use an adjacency list, it will be O(V+E).

Applications of DFS: Topological Sorting

Topological Sorting is mainly used for scheduling jobs from the given dependencies among jobs. In computer science, applications of this type arise in instruction scheduling

Applications of DFS: To test if a graph is bipartite

We can augment either BFS or DFS when we first discover a new vertex, color it opposited its parents, and for each other edge, check it doesn't link two vertices of the same color. The first vertex in any connected component can be red or black!

Applications of DFS: Path Finding

We can specialize the DFS algorithm to find a path between two given vertices u and z.


Set pelajaran terkait

Writing a Narrative Application Essay 70%

View Set

Anti-Discrimination Law: Title VII of the Civil Rights Act of 1964

View Set

International Business Chapter 9

View Set