![]() |
What was the question
The question is long so I will sumarize. There are 4 questions on the test and the test booklet is 16 pages long just to give you an idea.
The kids are talking about part b of the fourth question on the AB exam. There is an A exam and an AB exam. The AB covers a lot more matterial than the A exam. In any case. The method CharToBitsHelper for the CodeTree class returns a binary representation of the the path to a specific letter in a binary tree of letters. Taking the left branch is indicated by a 0 and takingthe right branch is indicated by a 1. So if you take a left and two rights to find the letter CharToBitsHelp returns "011". The actual method prototype (I have it in front of me) is apstring CodeTree::CharToBitsHelper(char ch, Node * T, const apstring & pathSoFar) const // postcondition: if ch is in subtree T, return code for ch I'll post my solution shortly. I want to read part A before I start. |
my solution
Node * Temp = T; // Pointer to use for traversal
apstring rtn = ""; // Return string while (Temp != null && Temp.letter != ch) { if ( ch > Temp.Letter) { rtn += "1"; Temp = Temp->right; } else { rtn += 0; Temp = Temp->left; } } if (Temp.letter == ch) return rtn; else return ""; The last bit is importent because you have to handle the case where the char is not found in the tree. My guess is that you will lose at least one point (of 4/5 for part b) if you leave that out. You will probably also lose a point if you did not create your own temp pointer for the traversal. But that's just a guess. |
my school must really suck, because there's only Visual Basic here for programming, and there are absolutely NO AP computer courses, I wish though.
|
VB
Visual Basic is a great language. But I'm biased as our school uses a VB text book I wrote. :)
BTW I think there is a problem with my solution to the AP question. I realized that there isn't a letter in the nodes only the leaves. So you have to recursively search each path and return the one that is good. A whole different set of code. Back to the drawing board. |
Quote:
Oh, and yep, Mr. Thompson, you're right, the letters are only in the leaves. You can look at my solution or Rucky G's solution for a right anser. The only difference between ours is that I check to see if the letter is found in the left subtree before I look in the right subtree, he looks in every node of the tree in all cases. So, mine is more effecient, but I think his looks more elegant, since he takes advantage of the fact that if the letter is not found, he returns the empty string, and thus can be appended to the answer without changing it. Stephen |
IMO, I did well enough to get a four on the comp sci A exam, and should I have done miraculously well on the part I, I might even have pulled a five. However, my answer to the case study part II would probably cause me to lose a few points here and there.
See, I looked at the fish maybe, uh, once, so I had no clue and knew as much going into the test. So my answer for #3 was to define 527 different variables. You never know, I could always get a partial credit point or something maybe.... :rolleyes: |
Quote:
|
Quote:
|
Quote:
Stephen |
| All times are GMT -5. The time now is 18:09. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi