Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose you want to rearrange a music playlist so that every see picture Question 7: Taylor and Friends Suppose you want to rearrange a music

Suppose you want to rearrange a music playlist so that every

see pictureimage text in transcribed

image text in transcribed

image text in transcribed

Question 7: Taylor and Friends Suppose you want to rearrange a music playlist so that all of your Taylor Swift songs play first, followed by all of your Kool & the Gang songs, followed by the songs of all other artists. In this problem you will formulate, solve, prove correct, and analyze an algorithm to achieve this task. The data for the problem is simply a vector whose entries each represent a song, denoted by a single character indicating its artist. So, for example, the array PLbad = [T, T, K, A, K, B] consists of two songs by Taylor, followed by a song by Kool followed by a fourth whose artist is denoted by A, another by Kool, and finally, a song by an artist denoted by B. That playlist does not satisfy our constraints, because the songs by Kool do not all precede the songs by everyone else. The playlists represented by PLgood1 = [T, K, K, B], PLgood2 = [K, K, A, B], and PLgood3 = [T, T, T], are all good playlists. For simplicity, you may assume that the playlist is non-empty. You do not care about the order of the songs within the blocks, and those orders can change. You do not know how many Taylor Swift songs or Kool & the Gang songs you possess! Please use n to represent A.size(), unless you are writing code. The playlist Function Assume that you are given a function void swap(char & a, char & b) that correctly exchanges the data in two vector locations. In your argument for correctness of your playlist algorithm, please refer to this assumption as (fact Swap). Our nearly-complete algorithm for solving the playlist problem is given below. Your first task is to complete the playlist function so that it successfully creates a playlist according to the constraints above. Tell us how to complete the code in the answer box. (Do not include a semicolon in your response.) void playlist(vector char> & A) { int w = ????; // Line 3 RHS -- enter below!! int u = 0; int v = A.size(); while (u

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

Students also viewed these Databases questions

Question

(1) How many levels and factors are there in this example? Pg45

Answered: 1 week ago