Computer Science > QUESTIONS & ANSWERS > University of FloridaCOP 3530exam1_solution-VERIFIED BY EXPERTS 2021-GRADED A+ (All)

University of FloridaCOP 3530exam1_solution-VERIFIED BY EXPERTS 2021-GRADED A+

Document Content and Description Below

COP 3530 Midterm, Part 1 (Mar 3, 2008) SOLUTION: . 1. (10 points) Define the term in-place, as it applies to sorting algorithms. Give an example of a sorting method that is not in-place. Solution:... An in-place sorting algorithm uses no extra workspace. Merge-sort is not in-place. 2. (15 points) Suppose you are searching for an item that appears more than once in the list. Which one will be found by a sequential (linear time) search? Which one will be found by a binary search? Answer as precisely as possible. Solution: Assuming the sequential search goes from i = 0 to n − 1, the value with the smallest index will be found. For binary search, there is no guarantee which will be returned. 3. (20 points) Write an algorithm that takes as input an array of n real numbers that is known to be sorted in ascending order, and sorts the array in descending order instead. You may assume that n is even. Use no additional size-n workspace. What is the time complexity of your algorithm? Solution: for (i = 0 ; i < n/2 ; i++) swap A[i] and A[n-i-1] The time complexity is O(n). 4. (20 points) Write an algorithm that computes the mode of a set of n real numbers. The mode is the most frequently occuring value in the set. In general an arbitrary set can have more than one mode, but you may assume that there is only one mode in the set given. What is the time complexity of your algorithm? Solution: First, sort the array (no need to explain which sort is used) in O(n log n) time. Next, scan the sorted array to find the mode. Here is one way to do it. The total time complexity of O(n log n). count = 0 for (i = 0 ; i < n ; ) { // find how many times a(i) appears in the list x = A[i] [Show More]

Last updated: 2 years ago

Preview 1 out of 4 pages

Buy Now

Instant download

We Accept:

We Accept
document-preview

Buy this document to get the full access instantly

Instant Download Access after purchase

Buy Now

Instant download

We Accept:

We Accept

Reviews( 0 )

$7.00

Buy Now

We Accept:

We Accept

Instant download

Can't find what you want? Try our AI powered Search

72
0

Document information


Connected school, study & course


About the document


Uploaded On

May 14, 2021

Number of pages

4

Written in

Seller


seller-icon
d.occ

Member since 4 years

232 Documents Sold

Reviews Received
30
8
4
1
7
Additional information

This document has been written for:

Uploaded

May 14, 2021

Downloads

 0

Views

 72

Document Keyword Tags


$7.00
What is Scholarfriends

In Scholarfriends, a student can earn by offering help to other student. Students can help other students with materials by upploading their notes and earn money.

We are here to help

We're available through e-mail, Twitter, Facebook, and live chat.
 FAQ
 Questions? Leave a message!

Follow us on
 Twitter

Copyright © Scholarfriends · High quality services·