Question

In: Computer Science

This question has three parts: a) binary search, b) selection sort, and c) merge sort. a)...

This question has three parts: a) binary search, b) selection sort, and c) merge sort.

a) Suppose we are performing a binary search on a sorted list called numbers initialized as follows:

#index 0 1 2 3 4 5 6 7 8 9 10 11 12 13

numbers = [-2, 0, 1, 7, 9, 16, 19, 28, 31, 40, 52, 68, 85, 99]

#search for the value 5

index = binary_search(numbers, 5)

Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code) and write the value that would be returned from the search. Assume that we are using the binary search algorithm shown in lecture and section.

Indexes examined :

Value returned :

b) Write the state of the elements of the list below after each of the first 3 passes of the outermost loop of the selection sort algorithm.

numbers = [63, 9, 45, 72, 27, 18, 54, 36]

selection_sort(numbers)

after pass 1 :

after pass 2 :

after pass 3 :

c) Trace the complete execution of the merge sort algorithm when called on the list below, similarly to the example trace of merge sort shown in the lecture slides. Show the sub-lists that are created by the algorithm and show the merging of sub-lists into larger sorted lists.

numbers = [63, 9, 45, 72, 27, 18, 54, 36]

merge_sort(numbers)

1st split :

2nd split :

3rd split :

1st merge :

2nd merge :

3rd merge :

Solutions

Expert Solution


Related Solutions

Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with...
Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort I need it in Java with comments and I need the input file to be placed with Scanner not BufferedReader Please help I need Class River Class CTRiver and Class Driver Class River describes river’s name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles...
Question 6 (this question has three parts (a), (b) & (c)) There are three securities (A,...
Question 6 (this question has three parts (a), (b) & (c)) There are three securities (A, B and C) in the market. The covariance matrix and the standard deviations of the securities and the market are given in the following tables. Covariance matrix A B C B -0.086 - - C 0.056 -0.0457 - Market 0.023 -0.0781 0.0354 Standard deviation table A B C Market 32.25% 48.25% 25.24% 23.25% Calculate the correlation coefficient between: A and B. B and C....
Question 1 (this question has three parts, (a), (b), and (c)) (a) As a response to...
Question 1 (this question has three parts, (a), (b), and (c)) (a) As a response to the recent COVID-19 outbreak, the Commonwealth Government put in place lockdown restrictions. Using the dynamic AD-AS framework, analyse and demonstrate the impact of the COVID-19 pandemic on the level of output (or real GDP), unemployment, and inflation. [4+4 marks ] (b) In response to the COVID-19 pandemic, in March 2020 the Commonwealth Government announced a fiscal stimulus which included income support for workers and...
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick...
Which of the following sorting algorithms are stable: insertion sort, selection sort, merge sort and quick sort? Give a simple scheme that makes any sorting algorithm stable. How much additional time and space does your scheme entail?
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge...
2 real-time examples on the Insertion sort, Bubble sort, Selection sort, Quick sort, Shell sort, Merge sort, Radix sort, Bucket sort, and Counting sort.
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted...
ASAP! write a program including   binary-search and merge-sort in Python. You also need to  modify the code posted and use your variable names and testArrays.  
I would like to integrate a bubble sort into this binary search in c ++ Thank...
I would like to integrate a bubble sort into this binary search in c ++ Thank you! #include <iostream> using namespace std; // Binary search algorith // f is the first , l is the last , t is the target int binarySearch(int stgrade[], int f, int l, int t) {         while (f <= l)         {             int m = f + (l - l) / 2;                 // Check if...
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Rank the algorithms from slowest to fastest. . Bubble Sort Linear Search Binary Search Shellsort
Sorting with Binary Search Tree This assignment asks you to sort the lines of an input...
Sorting with Binary Search Tree This assignment asks you to sort the lines of an input file (or from standard input) and print the sorted lines to an output file (or standard output). Your program, called bstsort (binary search tree sort), will take the following command line arguments: % bstsort [-c] [-o output_file_name] [input_file_name] If -c is present, the program needs to compare the strings case sensitive; otherwise, it's case insensitive. If the output_file_name is given with the -o option,...
C++ --------------------------------------------- Do a comparison of a slow sort with Big O(n2) (selection sort, insertion sort,...
C++ --------------------------------------------- Do a comparison of a slow sort with Big O(n2) (selection sort, insertion sort, or bubble sort) and one faster sort of Big O(n * log n) (mergesort or quicksort). Count the number of moves (a swap counts as one move). With mergesort, you can count the range of the part of the array you are sorting (i.e. last-first+1). Use the code from the textbook (copy from the lecture notes) and put in an extra reference parameter for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT