Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My lessthan function: bool lessThan(const string &S, int first, int second){ int i=first; int k=second; for(i = first; i S[k]){ return false; } if(S[i]) S[k]){

image text in transcribed

My lessthan function:

bool lessThan(const string &S, int first, int second){ int i=first; int k=second; for(i = first; i S[k]){ return false; } if(S[i]) S[k]){ return false; } return true; }

void insertion(const string &S, vector &indices, int low, int high) An example of how the insertion function would work is that I pass in the string "abracadabra" with the low being 0 and high being 6 and the output would be :0 3 514627 8 9 10 Re-write Insertion sort algorithm to sort suffixes of a given string S. Similarly to QuickSort, your insertion function will take a string S (passed constant by reference), and a vector of integers with the starting positions of suffixes of S. The function will sort the suffixes of S in the range from low to high (inclusive indices of the range). Insertion will call lessThan function (from Assignment 5) and will swap positions of the suffixes instead of suffixes. Here is the header of this function: void insertion(const string &S, vector &indices, int low, int high) Sample input: S-"abracadabra", indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), low 3, high 7 insertion(S, indices, low, high); //will sort suffixes starting at positions 3, 4, 5, 6, and 7 Sample output: After insertion is called on the sample input, vector indices will have the following order of suffix positions: indices (0, 1, 2,7, 3, 5, 4, 6, 8, 9, 10). Only suffixes at indices 3, 4, 5, 6, and 7 are ordered alphabetically. void insertion(const string &S, vector &indices, int low, int high) An example of how the insertion function would work is that I pass in the string "abracadabra" with the low being 0 and high being 6 and the output would be :0 3 514627 8 9 10 Re-write Insertion sort algorithm to sort suffixes of a given string S. Similarly to QuickSort, your insertion function will take a string S (passed constant by reference), and a vector of integers with the starting positions of suffixes of S. The function will sort the suffixes of S in the range from low to high (inclusive indices of the range). Insertion will call lessThan function (from Assignment 5) and will swap positions of the suffixes instead of suffixes. Here is the header of this function: void insertion(const string &S, vector &indices, int low, int high) Sample input: S-"abracadabra", indices (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10), low 3, high 7 insertion(S, indices, low, high); //will sort suffixes starting at positions 3, 4, 5, 6, and 7 Sample output: After insertion is called on the sample input, vector indices will have the following order of suffix positions: indices (0, 1, 2,7, 3, 5, 4, 6, 8, 9, 10). Only suffixes at indices 3, 4, 5, 6, and 7 are ordered alphabetically

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions