An algorithm prints the following pattern:
* * * * * * * * * * * * * * *
A spreadsheet keeps track of student scores on all the exams in a course. Each row of the spreadsheet corresponds to one student, and each column in a row corresponds to his/her score on one of the exams. There are r students and c exams, so the spreadsheet has r rows and c columns.
Consider an algorithm that computes the total score on all exams for each student, and the average class score on each exam. You need to analyze the running time of this algorithm.
A card game program keeps a deck of cards in an array. Give an algorithm to "unshuffle" the deck so that all the cards of a suit are grouped together, and within each suit, the cards are in ascending order or rank--consider the ace as the lowest ranked card. Since there are only 52 cards, space is not an issue so you can use extra space if needed. The only constraint is that your algorithm be as fast as possible.
What is the worst case big O running time of your algorithm? What are the basic operations you used in your analysis? Is the average big O running time different from the worst case?
Two people compare their favorite playlists for matching songs. The first playlist has n songs, and the second has m. Each is stored in an array, in no particular order.
There is a highway with n exists numbered 0 to n - 1. You are given a list of the distances between them. For instance:
Exits: 1 2 3 4 5 6 Distances: 5 3 4 2 8 6
The distance from the start of the highway to exit 1
is 5, from exit 1 to 2 is
3, and so on.
You have to devise an algorithm that would calculate the distance between any two exits. Imagine that this distance function is called millions of times by applications that need this information, so you need to make your algorithm as fast as possible.
Describe your algorithm. What is the worst-case big O running time? Make sure to state all the parameters you use in the analysis and relate them to the algorithm.