Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Algorithms and Data Structures 1. Give an algorithm to find the minimum and maximum of a sequence of n numbers using at most d3n/2e − 2 comparisons. 2. Give an algorithm to find the second largest element in a sequence of n numbers using n + o(n) comparisons in the worst case. (Hint: 1. Start with finding the maximum element. 2. Part of the exercise is also test your understanding of the notation o(n)). 3. How do you determine whether a given graph is connected? How much time does your algorithm take if you use • an adjacency matrix to represent the given graph, • an adjacency list to represent the given graph? 4. Give an algorithm to determine whether a given graph has a cycle. Your algorithm should take O(|V |) time (regardless of the number of edges in the graph). 5. How would you find a maximum matching in a bipartite graph? What is the complexity of the algorithm? 6. Recall a binary minheap, and the time (number of comparisons, number of moves) to perform insert, deletemin operations and an O(n) time algorithm to produce a heap ordered array from a given arbitrary array. Suppose, instead of a binary heap, we use a d-ary heap for some d ≥ 2. Discuss what happens to the running times (number of comparisons and number of moves) of all these operations, and argue whether there is a better optimal value of d (than 2). In particular, suppose I am interested only in minimizing the swaps in the insert and deletemin operations, what choice of d is good? 7. Consider the insertion sort algorithm to sort an array A of n elements: Start with the sorted list A[1] of size 1: for i = 2 to n insert A[i] into the already sorted list A[1..i − 1]. • How much time (number of comparisons and moves) does your algorithm make if you use linear search to insert the element at each step of the for loop? • What if you use binary search? • Can you think of a data structure to organize the sorted list A[1..i−1] so that the insertion takes O(log n) time and you can still retrieve the sorted list (at the end) in O(n) time? 8. We would like to maintain a set of elements (from an ordered set) to support, along with the standard insert, search and delete operations, return(k) that will return the k-th smallest element in the given list for the query value of k (between 1 and n). Explain what augmentation you would use to a standard data structure (which one?) to support this operation (along with others) in O(log n) time? 1 9. Can you show the following problem N P -complete? Given two graphs G and H, determine whether there is a subgraph of G isomorphic to H? Suppose G has n vertices and H has m ≤ n vertices, can you give a brute-force algorithm to answer this question? How much time does your algorithm take? 10. Let n, k ≥ 2 be integers. Give an O(nk log k) algorithm for the following tasks: • Let A1 , A2 , . . . Ak be k sorted lists of n elements each. The problem is to sort the nk elements of A1 ∪ A2 ∪ . . . Ak . • Given a list of nk elements, determine the elements of rank in for i = 1 to k. Rank of an element is its position in the sorted list. Can you also prove corresponding Ω(nk log k) lower bound on the number of comparisons to solve these problems? 2