100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

WGU C949 - Searching and Sorting Algorithms- Qs & As

Rating
-
Sold
-
Pages
12
Grade
A+
Uploaded on
23-10-2024
Written in
2024/2025

WGU C949 - Searching and Sorting Algorithms- Qs & As

Institution
WGU C949
Course
WGU C949









Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
WGU C949
Course
WGU C949

Document information

Uploaded on
October 23, 2024
Number of pages
12
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

WGU C949 - Searching and Sorting Algorithms- Qs & As

Selection sort efficiency CORRECT ANS-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) CORRECT ANS-# 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))



Binary search (python) CORRECT ANS-# replace "^\.+" with space
def BinarySearch(num, numbers):
....low = 0
....high = len(numbers) - 1
....mid = 0
....while low <= high:
........mid = (high + low) // 2

, WGU C949 - Searching and Sorting Algorithms- Qs & As
........if numbers[mid] < num:
............low = mid + 1
........elif numbers[mid] > num:
............high = mid - 1
........else:
............return mid
....return -1
if __name__ == "__main__":
....numlist = [ 11, 33, 55, 77, 99 ]
....for val in (11, 22, 55, 88, 99):
........print(f"Index of {val}: {BinarySearch(val, numlist)}")



Binary search CORRECT ANS-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 CORRECT ANS-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 CORRECT ANS-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.




Insertion sort CORRECT ANS-The list is split into a sorted half and unsorted half. Values
from the unsorted part are picked and placed at the correct position in the sorted part (left)
by shifting all the elements towards the right (unsorted portion).

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TheeGrades NEWCASTLE UNIVERSITY
View profile
Follow You need to be logged in order to follow users or courses
Sold
97
Member since
1 year
Number of followers
5
Documents
12923
Last sold
2 weeks ago
THEEGRADES

Ace Your Exams with Premium Study Guides! Unlock your full potential with our expertly crafted revision materials. Whether you're prepping for exams, quizzes, or looking to solidify your understanding, we've got you covered. Our study guides, summaries, and test banks are designed to simplify complex topics and enhance your knowledge retention. What We Offer: Comprehensive Summaries: Key points made easy for quick revision. Test Banks: Practice with real exam-like questions. Exam Prep Guides: Focused content to boost your scores. Instant Access: Download and start studying immediately! Don’t just study harder—study smarter! Excel in your exams with our trusted materials. You are Welcome. SUCCESS!!!

Read more Read less
3.3

24 reviews

5
9
4
4
3
3
2
1
1
7

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions