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: 1 year ago

Preview 1 out of 4 pages

Reviews( 0 )

$7.00

Add to cart

Instant download

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

OR

GET ASSIGNMENT HELP
34
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 3 years

227 Documents Sold


Additional information

This document has been written for:

Uploaded

May 14, 2021

Downloads

 0

Views

 34

Document Keyword Tags

Recommended For You

What is Browsegrades

In Browsegrades, 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 © Browsegrades · High quality services·