Exam One

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Given array 8, 5, 3, 7, 1, 6, 4, 2 List array to show the array changes in memory. You may list array after each partition call is terminated.

2, 5, 3, 7, 1, 6, 4, 8 2, 5, 3, 4, 1, 6, 7, 8

Consider the following array: 12, 13, 15, 15, 16, 16, 19, 23, 25, 26, 30, 31, 32 If using binary search algorithm from your textbook with search key 16, what is the return value?

4

Consider the following array: 12, 13, 15, 15, 16, 16, 19, 23, 25, 26, 30, 31, 32 If using linear search algorithm from your textbook with search key 16, what is the return value?

4

Merge Sort Given array 8, 5, 3, 7, 1, 6, 4, 2 List array to show the array changes in memory. You may list out array after each merge call is terminated

5 8 3 7 1 6 4 2 5 8 3 7 1 6 4 2 3 5 7 8 1 6 4 2 3 5 7 8 1 6 4 2 3 5 7 8 1 6 2 4 3 5 7 8 1 2 4 6 1 2 3 4 5 6 7 8

Order the following Big O notation from the fastest running time to the slowest running time: 1000, 2^n, n * log n, 2n^2, n

O(1000) < O(n) < O(n * log n) < O(2n^2) < O(2^n)

What is the running time of merger sort?

O(n log n)

What is the running time of quick sort?

O(n log n)

What is the running time of merger?

O(n)

What is the running time of partition?

O(n)

Determine big O notation for function f(n) = 1000n + 0.1n ^2 + n * log n

O(n^2)

In your textbook, the binary search is presented in iteration format. Please rewrite the binary algorithm in recursive format. You should write the algorithm in the follow format. The italic parts are the parts you need to modify. Input: Describe what is the input of the algorithm, Output: Describe what is the output of the algorithm. Procedure BinarySearchRecursive(argument list) Algorithm details End Procedure

Procedure BinarySearchRecursive(arr, begin, end, key) { if begin > end return -1 mid = (begin + end) / 2 if(arr[mid] == key) return mid if(arr[mid] < key) return BinarySearchRecursive(arr, mid + 1, end) if(arr[mid] > key) return BinarySearchRecursive(arr, begin, mid - 1) End Procedure // Driver Algorithm Procedure BinarySearch(arr, size) return BinarySearchRecursive(arr, 0, size - 1)

According to your book, "...To partition the input, quicksort chooses a pivot to divide the data into low and high parts. The pivot can be any value within the array being sorted, commonly the value of the middle array element." Now rewrite the partition algorithm by using the last element of the subarray as the pivot.

Simply change one statement: pivot = numbers[midpoint] to pivot = numbers[k]. Also, delete midpoint = i + (k-i)/2.

How many time will the partition algorithm be executed in a quick sort? Assume the array size is n. Justify your answer.

We need to place n elements in their final position, so we need n partitions.

Merge Sort How many comparisons are needed to sort a list of 2,048 elements?

n * log n 2048 elements * log 2048 2048 * 11 = 22,528

Quick Sort How many comparisons are needed to sort a list of 2,048 elements?

n * log n 2048 elements * log 2048 2048 * 11 = 22,528

How many times will the merger algorithm be executed in a merger sort?

n - 1


Set pelajaran terkait

28- Cholinergic Agonists + Antagonists

View Set

Learning Curve: 13a Defining and Classifying Psychological Disorders

View Set

Unit Four- Healthcare Facilities

View Set

Systematic Theology: Pneumatology Review Study Guide For TEST

View Set

Chapter 4 - Probability & Counting Rules

View Set