Advertisement
Guest User

Untitled

a guest
Nov 14th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. 1. Consider the following list:
  2.  
  3. [6, 2, 4, 7, 1, 3, 8, 5]
  4.  
  5. Use it as input to the following sort algorithms:
  6. a. Show the results of each pass of Insertion Sort.
  7.  
  8. [6, 2, 4, 7, 1, 3, 8, 5]
  9. [2, 6, 4, 7, 1, 3, 8, 5]
  10. [2, 4, 6, 7, 1, 3, 8, 5]
  11. [2, 4, 6, 7, 1, 3, 8, 5]
  12. [1, 2, 3, 4, 6, 7, 8, 5]
  13. [1, 2, 3, 4, 6, 7, 8, 5]
  14. [1, 3, 2, 4, 6, 7, 8, 5]
  15. [1, 3, 2, 4, 6, 7, 8, 5]
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23. b. Show the results of each pass of Bubble Sort.
  24. [6, 2, 4, 7, 1, 3, 8, 5]
  25. [2, 6, 4, 7, 1, 3, 8, 5]
  26. [2, 4, 6, 7, 1, 3, 8, 5]
  27. [2, 4, 7, 6, 1, 3, 8, 5]
  28. [2, 4, 7, 1, 6, 3, 8, 5]
  29. [2, 4, 7, 1, 3, 6, 8, 5]
  30. [2, 4, 7, 1, 3, 8, 6, 5]
  31. [2, 4, 7, 1, 3, 8, 5, 6]
  32.  
  33.  
  34. 2. What are the main purposes of sorting?
  35.  
  36. Answer :
  37. Efficient sorting is important for optimizing the efficiency of other algorithms (such as search and merge algorithms) which require input data to be in sorted lists. Sorting is also often useful for cannibalizing data and for producing human-readable output.
  38.  
  39. 3. When choosing a sorting method, what criteria influence our decision?
  40. Answer:
  41. Significant factors include past experiences, a variety of cognitive biases, an escalation of commitment and sunk outcomes, individual differences, including age and socioeconomic status, and a belief in personal relevance. These things all impact the decision making process and the decisions made.
  42.  
  43. 4. Quick Sort is characterized by “hard division, easy combination”. Merge Sort is characterized by “easy division, hard combination”. What do we mean by these descriptions?
  44. Answer:
  45. Merge sort requires a temporary array to merge the sorted arrays and hence it is not in-place giving Quick sort the advantage of space. Worst Cases: The worst case of quicksort O(n2) can be avoided by using randomized quicksort. It can be easily avoided with high probability by choosing the right pivot
  46.  
  47. 5. Give a natural language description of Bubble and Selection Sort. Illustrate your descriptions using an unsorted list of your choice, such as [5, 7, 13, 8, 9, 2, 4, 27].
  48. Answer:
  49. Bubble sort essentially exchanges the elements whereas selection sort performs the sorting by selecting the element. Another considerable difference between the two is that bubble sort is stable algorithm while selection sort is an unstable algorithm.
  50.  
  51.  
  52. 6. In a programming language of your choice, specify the algorithm for Bubble Sort. If you need to remind yourself of the algorithm’s structure, do so with reference to a natural language description, then specify the algorithm in detail.
  53.  
  54. 7. In a programming language of your choice, specify the algorithm for Shell Sort with a gap size of 2. If you need to remind yourself of the algorithm’s structure, do so with reference to a natural language description, then specify the algorithm in detail.
  55.  
  56. 8. Using pseudo code and/or natural language descriptions specify Dijkstra’s shortest path algorithm. Annotate your algorithm to describe the algorithmic process.
  57.  
  58. 9. Supply the missing word or phrase:
  59. a. Trees are a form of _______ data structure
  60. b. Quick Sort makes O(n log n) comparisons to sort ___ items
  61. c. Linked lists are a form of ___________ data structure.
  62. d. Nearly all vertices are connected in a ______ graph.
  63. e. ________ is used by programmers to informally specify the structure of an algorithm.
  64. f. A digraph is a collection of nodes connected by ______ edges.
  65. g. An adjacency matrix is an n x n ______ matrix.
  66. h. Selection Sort uses _____ problem-solving.
  67.  
  68. 10. Indicate whether the following statements are true (T) or false (F):
  69. a. Vertices are adjacent if they are endpoints of the same edge. T or F
  70. b. In stack processing, only the last item in the sequence can be retrieved or deleted. T or F
  71. c. A complete graph is one in which every pair of vertices is connected by an edge. T or F
  72. d. Moving data items in a linked list has a time complexity of 0(n). T or F
  73. e. Shortest paths must be unique. T or F
  74.  
  75.  
  76. 11. Give the primary and secondary operations associated with the STACK ADT.
  77.  
  78. 12. Give the primary and secondary operations associated with the QUEUE ADT.
  79.  
  80. 13. What is the difference between a complete and a dense graph?
  81. 14. When is a graph traversal most efficient?
  82. 15. Consider the following unsorted list:
  83.  
  84. 1 12 5 26 7 14 3 7 2
  85.  
  86. Apply Quick Sort up to the fist partition that places the pivot value in the correct position. The pivot is the first value 7.
  87.  
  88. 16. Applying the median of three method, which value would become the pivot?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement