Вы находитесь на странице: 1из 3

1.

Consider the problem of counting, in a given text, the number of substrings that start with an A and end with B. For example, there are four such substrings in CABAAXBYA. Design a brute-force algorithm for this problem and determine its efficiency class. 2. Give and explain merge sort algorithm. Apply masters theorem to find the average case time complexity. Sort the list 8, 3, 2, 9, 7, 1, 5, 4 in ascending order using merge sort technique. 3. Write pseudo code for a divide-and-conquer algorithm for finding values of both the largest and smallest elements in an array of n numbers. Set up and solve (for n = 2k) a recurrence relation for the number of key comparisons made by the algorithm. 4. Apply merge sort to sort the list E, X, A, M, P, L, E in alphabetical order. 5. Give and explain quick sort algorithm. Derive the worst and average case time efficiencies of quick sort technique. Apply quick sort to sort the list Q, U, I, C, K, S, O, R, T in alphabetical order. 6. Write a function that prints out the node values for a BST in sorted order from highest to lowest. 7. Explain how one can check a graphs acyclicity by using breadth-first search. Does either of the two traversalsDFS or BFSalways find a cycle faster than the other? If you answer yes, indicate which of them is better and explain why it is the case; if you answer no, give two examples supporting your answer.

8. Consider the following undirected graph. Draw a DFS and BFS tree for the graph starting at node A. If several nodes can be chosen at some step, pick the vertex that is alphabetically first.

9. What do you understand by strongly connected component in a graph? Give the algorithm to find the strongly connected components of a given directed graph G using DFS. Explain with an example. 10. Apply the DFS-based algorithm to solve the topological sorting

problem for the following digraph:

Вам также может понравиться