Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


COMP125 Fundamentals of Computer Science

Module Exam

Searching and Sorting

QUESTION SET 40


Instructions

• Write your answer neatly in space provided after each question, request blank pages if you need more space. Answers must be clear enough to read in order to be marked

• Any attempt of plagiarizing will result in an automatic zero.


Questions

Question 1 (30 points)

Trace the state of the original array {4, 1, 6, 5, 3, 2} after each iteration of,

(a)  (15 points)  selection sort

(b)  (15 points)  insertion sort


Question 2 (20 points)

Circle the median items that are chosen while searching for item 20 in the following array using binary search

algorithm with initial settings as first  =  0,  last  =  a.length  -  1 and the median computation as median  = (first  +  last)/2.


int [] a = {1 , 1, 5, 8, 20 , 30 , 55 , 80 , 90 , 92 , 94 , 99 , 100 , 130 , 160 , 180};


Question 3 (30 points)

Write a method that sorts an array of type double in ascending order using either selection sort OR insertion sort. The name of the method should clearly indicate the sorting algorithm being used otherwise you will be penalized 10 points.


Question 4 (20 points)

Write a method that when passed an integer aray arr, and an integer target, returns true if the item target occurs in the second half of the arr, and false otherwise (or if the array arr is null). If the array has an 8 or 9 items, the second half contains items starting from index 4.