Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

We are given a dictionary D, which is an array of n distinct strings, sorted in lexicographic order. We are also given a procedure COMPARE-STRINGS(x,

image text in transcribed

We are given a dictionary D, which is an array of n distinct strings, sorted in lexicographic order. We are also given a procedure COMPARE-STRINGS(x, y), which will compare two strings x and y in (1) time, and return true if x comes before y, and false if y comes before x in lexicographic order. We are also given an array C, which contains n. 1 of the n strings in D, but C is not sorted. We would like to develop an algorithm that will find the string that is missing in C. (a) Design a divide-and-conquer algorithm that will find the missing string in O(n) time. You can assume that we can utilize the PARTITION algorithm that is used by QUICKSORT, by modifying it to compare strings instead of comparing numbers (you do not need to show how to do the modification). Write the pseudo-code of your algorithm and explain how it works. (Hint: You can select the pivot used for PARTITION algorithm in an informed manner that guarantees the resultant subarrays to be of nearly equal size.) (b) Show that the runtime of your algorithm is O(n). = Example. Suppose D {"W, X,Y","Z"} and C {"Y, Z, W}. D contains n = 4 strings and C contains all n-1 = 3 strings in D except X. Thus, missing string in C is: X. We are given a dictionary D, which is an array of n distinct strings, sorted in lexicographic order. We are also given a procedure COMPARE-STRINGS(x, y), which will compare two strings x and y in (1) time, and return true if x comes before y, and false if y comes before x in lexicographic order. We are also given an array C, which contains n. 1 of the n strings in D, but C is not sorted. We would like to develop an algorithm that will find the string that is missing in C. (a) Design a divide-and-conquer algorithm that will find the missing string in O(n) time. You can assume that we can utilize the PARTITION algorithm that is used by QUICKSORT, by modifying it to compare strings instead of comparing numbers (you do not need to show how to do the modification). Write the pseudo-code of your algorithm and explain how it works. (Hint: You can select the pivot used for PARTITION algorithm in an informed manner that guarantees the resultant subarrays to be of nearly equal size.) (b) Show that the runtime of your algorithm is O(n). = Example. Suppose D {"W, X,Y","Z"} and C {"Y, Z, W}. D contains n = 4 strings and C contains all n-1 = 3 strings in D except X. Thus, missing string in C is: X

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

4. I can tell when team members dont mean what they say.

Answered: 1 week ago