You are on page 1of 1

Questions on arrays 1.

Write an algorithm for binary search and hence find the location of 658 in the following list 5 12 15 48 78 98 125 325 658 987 Does binary search helps in locating the position of the element in the list if the search is unsuccessful? If yes, then how? 2. Write an algorithm for linear search such that if the element is present in the list, then it should tell the position of the element and if not present, then it should insert it in the start of the list. 3. Write an algorithm for insertion sort and hence sort the following list using the insertion sort 25 45 48 52 12 3 65 5 78 98 59 18 Also discuss the complexity of the algorithm. 4. (a) Suppose A is one dimensional array declared as A(-2:12) a. Find the length of array. b. Find the address of A(7) assuming base address of A is 400 and there are w = 4 words per memory location. (b) Define data structure. What are major different operations performed on a data structure? Write an algorithm to delete an element at kth position in an array. 5. (a) Write an algorithm to insert an element in the sorted array at its desired position so that the array after inserting the element remains sorted. (b) What are the preconditions on a data structure to use the binary search? Explain. 6. Write an algorithm for bubble sort and hence sort the following list using the bubble sort 25 45 48 52 12 3 65 5 78 98 59 18 Also discuss the complexity of the algorithm. 7. Write an algorithm for selection sort and hence sort the following list using the selection sort 25 45 48 52 12 3 65 5 78 98 59 18 Also discuss the complexity of the algorithm. 8. Write an algorithm for bubble sort to sort the array in descending order and hence sort the following list in descending order using the bubble sort 25 45 48 52 12 3 65 5 78 98 59 18 Also discuss the complexity of the algorithm. 9. Write an algorithm for selection sort to sort the array in descending order and hence sort the following list in descending order using the selection sort 25 45 48 52 12 3 65 5 78 98 59 18 Also discuss the complexity of the algorithm. 10. Write an algorithm for insertion sort to sort the array in descending order and hence sort the following list in descending order using the insertion sort 25 45 48 52 12 3 65 5 78 98 59 18 11 Sort the following list using bubble sort, insertion sort and selection sort 12 21 5 58 41 23 6 14 22 65 11 16

You might also like