WGU C949 - Searching and Sorting Algorithms Questions With Correct Answers!!
Binary search - A faster algorithm for searching a list if the list's elements are sorted and directly accessible (such as an array). Binary search first checks the middle element of the list. If the search key is found, the algorithm returns the matching location. If the search key is not found, the algorithm repeats the search on the remaining left sublist (if the search key was less than the middle element) or the remaining right sublist (if the search key was greater than the middle element). Binary search efficiency - For an N element list, the maximum number of steps required to reduce the search space to an empty sublist is [ log2 N ] + 1 Selection sort - Sorting algorithm that treats the input as two parts, a sorted part and an unsorted part, and repeatedly selects the proper next value to move from the unsorted part to the end of the sorted part. Selection sort efficiency - If a list has N elements, the outer loop executes N times. For each of those N outer loop executions, the inner loop executes an average of N/2 times. So the total number of comparisons is proportional to N * (N/2), or O(N^2) Selection sort (python) - # replace "^.+" with space def SelectionSort(numbers): ....for idx in range(len(numbers)): ........min_idx = idx ........for comp in range(idx+1, len(numbers)): ............if numbers[min_idx] > numbers[comp]: ................min_idx = comp ........temp = numbers[idx] ........numbers[idx] = numbers[min_idx] ........numbers[min_idx] = temp if __name__ == "__main__":....numlist = [ 99, 77, 33, 55, 11 ] ....print("Before: " + str(numlist)) ....SelectionSort(numlist) ....print("After: " + str(numlist)
Written for
- Institution
- WGU C949 - Searching and Sorting Algorithms
- Course
- WGU C949 - Searching and Sorting Algorithms
Document information
- Uploaded on
- November 8, 2023
- Number of pages
- 11
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
wgu c949 searching and sorting algorithms
Also available in package deal