Traversals + QuickSort = Pain

Link to the project or level: [replace with link to the curriculum or get the “Share” link to a project]

What I expect to happen: [replace with a detailed description of the behavior you’re trying to create]
Okay, what I’m trying to do is create a program that takes all of the tweets of this guy Elon Musk, and then finds the “Best” and “Worst” tweets (Those with the most and least likes) and then also use the tone identification to analyze the average success rates based on tone used (Neutral, Positive, Negative). And then for the Best and Worst, display the Top 10, with the date of the tweet in question, and a tappable element it is contained in which brings you to the tweet itself.
What actually happens: [replace with a detailed description of what actually happens when the code runs including any errors or unexpected behavior]
What actually happens is that after sorting the list by like count, the relevant data needed for the Best and Worst functions is lost, as it only sorts the Likes and not any of the other data in the row, making the end result (The top list showing the tweets as dates with clickable links to that tweet) impossible.
What I’ve tried: [replace with a detailed description of what you’ve already tried to do to solve the problem]
I’ve tried everything, but I cannot figure out how to sort the rest of the relevant information or at least link the two separate lists, and neither can people more knowledgable in my class. PLEASE HELP!!!

Hi @glare-longs-0m,

What an ambitious project! Is your student using this as the end-of-unit project?

The first thing I notice is that there are a lot of variables at the beginning of the student’s program that aren’t called later in the program. Where does the student intend to use these?

I also see that “category” is misspelled as “catagory” in lines 50 and 53, and possibly elsewhere. I’d remind the student that spelling counts, as this is especially helpful when debugging.

Finally, I tried to remix the project myself but could not find the dataset in the library. Is the student pulling this from elsewhere, or am I searching for it incorrectly? If it’s being pulled from elsewhere, can you link it as a Google Sheet so we can test it out?

Thank you!

–Michael K.

2 Likes

Yes, the student is using this as their end-of-year project, they stopped after running into this roadblock, leaving many unused variables. The dataset is being pulled from elsewhere, and is linked here:

THANKS FOR THE HELP :slight_smile:

1 Like

All the lists in your program are parallel lists, i.e., an ith value in all lists is information about the ith tweet. For example, text[0] is the text of the 0th tweet, the sentiment[0] is the sentiment of the 0th tweet, date[0] is the date of the 0th tweet and so on. When you sort the likes list, you must move all the elements of all the other lists, as well so that the lists all stay parallel. If you move the 10th element on the likes list to another location in the list, you must also move the 10th element of all the other lists to the same location as you did in the likes list. I hope this makes sense.

3 Likes

It does! It’s the application that stumps me… because the actual sorting is based on the values of the Likes list, so I don’t know how to sort in between that.

You are only sorting one list in the quick sort method. You need to also change all of the other corresponding lists, so the relationship between the parallel lists is maintained. For example, if you print out the first 2 elements of the Likes list and the ID list, the Likes will be sorted, but now the IDs don’t correspond to the correct tweet. ID[0] is still the ID of the original tweet that was at position 0. To do this you will need to pass six lists to your quick sort method. The first list should be the one you want to sort by. For example, if you are sorting by likes, use the Likes list as your first list. Pass all the remaining five lists too. In your partition method, you will have to swap the elements in the remaining five lists as well.

1 Like

Yes, but how? It’s harder than it sounds…

Here is a link to your project that I remixed and modified. App Lab - Code.org

1 Like