Part 1 (5 Points): Include the answers to the questions in Part 1 as comments af
ID: 3568557 • Letter: P
Question
Part 1 (5 Points): Include the answers to the questions in Part 1 as comments after the comment block described in Getting Started section above. 1. Given the following array int a[] = { 18, 16, 19, 3 ,14, 6 }; a) How are the contents of the array arranged after each pass of the selection sort in ascending order? 2. Given the following array int b[] = { 3, 5, 6, 8, 12, 13, 16, 17, 18, 20}; a) What elements of the array are compared (in order) when searching for the number 8 with linear search? b) What elements are compared (in order) when searching for 8 with binary search? c) How many elements are compared when searching 15 with linear search? d) How many elements are compared when searching 15 with binary search? 3. Given the following 2-D array int nums[][] = { {1, 2,3, 4}, {2, 4,6, 8}, (3, 1 ,3, 0}}; a) How many rows does nums have? b) How many columns does nums have? c) What is stored in nums[2][1]? d) What is stored in nums[1][0]?Explanation / Answer
1)
a)
Array at beginning : 18 , 16 , 19 , 3 , 14 , 6
After pass #1 : 18 , 16 , 6 , 3 , 14 , 19
After pass #2 : 14 , 16 , 6 , 3 , 18 , 19
After pass #3 : 14 , 3 , 6 , 16 , 18 , 19
After pass #4 : 6 , 3 , 14 , 16 , 18 , 19
After pass #5 : 3 , 6 , 14 , 16 , 18 , 19
2)
a)
Elements of array compared when searching for number 8 with linear search are :
3, 5, 6, 8.
b)
Elements of array compared when searching for number 8 with binary search are :
12, 5, 6, 8.
c)
Elements of array compared when searching for number 15 with linear search are :
3, 5, 6, 8, 12, 13, 16 and number is not in the array.
d)
Elements of array compared when searching for number 15 with binary search are :
12, 17, 13, 16, and number is not in the array.
3)
a) rows = 3
b) columns = 4
c) nums[2][1] = 1
d) nums[1][0] = 2