2

(C++)Create a (partial) BST class and a driver program to testit. The tree node will store integers as the data/key field (singlefield). Note that you will need to ...

Question

(C++)Create a (partial) BST class and a driver program to testit. The tree node will store integers as the data/key field (singlefield). Note that you will need to guarantee there are noduplicates in your insert function (the tree should refuse toinsert a duplicate key). Call your files “tree.h”, “tree.cpp” and“main.cpp”. In addition, draw a picture of your tree (see noteabout random values below)Public methods to include:ConstructorCopy ConstructorOverloaded Assignment OperatorDestr

(C++)Create a (partial) BST class and a driver program to test it. The tree node will store integers as the data/key field (single field). Note that you will need to guarantee there are no duplicates in your insert function (the tree should refuse to insert a duplicate key). Call your files “tree.h”, “tree.cpp” and “main.cpp”. In addition, draw a picture of your tree (see note about random values below) Public methods to include: Constructor Copy Constructor Overloaded Assignment Operator Destructor Insert value (do not add duplicate values) Find key – returns bool indicating if value is present in tree Print ancestors – prints a list of all values on the path to the given value Find height – returns integer Post-Order Traversal done recursively (print key values to screen) In-Order Traversal done iteratively (print key values to screen) (use STL Stack for this – see instructions on Canvas course site) Count leaves – returns number of leaves in tree Count full nodes – returns number of full nodes (nodes with two children) in tree There will be additional private helper methods needed. The only methods that may print to the screen are the two traversals and the print ancestors. Your driver should insert a minimum of 25 random* values to the tree. Test all the public methods of your class in the driver, printing the results to the screen. The user interface should clearly explain what is being tested and what results are expected. *Random doesn’t mean you need to use the random number generator, though you are welcome to do so. But it does mean you do not want to insert values 1 thru 20 (in that order) into your tree (why not?). Consequently, you should decide on your values in advance and store them (in an array??) to insert. Include at least one duplicate value to properly test the insert.



Answers

The tournament sort is a sorting algorithm that works by building an ordered binary tree. We represent the elements to be sorted by vertices that will become the leaves. We build up the tree one level at a time as we would construct the tree representing the winners of matches in a tournament. Working left to right, we compare pairs of consecutive elements, adding a parent vertex labeled with the larger of the two elements under comparison. We make similar comparisons between labels of vertices at each level until we reach the root of the tree that is labeled with the largest element. The tree constructed by the tournament sort of 22, 8, 14, 17, 3, 9, 27, 11 is illustrated in part (a) of the figure. Once the largest element has been determined, the leaf with this label is relabeled by ??, which is defined to be less than every element. The labels of all vertices on the path from this vertex up to the root of the tree are recalculated, as shown in part (b) of the figure. This produces the second largest element. This process continues until the entire list has been sorted.

Show that the tournament sort requires $\Theta(n \log n)$ comparisons to sort a list of $n$ elements. [Hint: By inserting the appropriate number of dummy elements defined to be smaller than all integers, such as $-\infty,$ assume that $n=2^{k}$ for some positive integer $k . ]$

Good day, ladies and gentlemen, today we are looking live at problem number 8 18. It is the circle to D. Class. And needless to say it is a long one. It is a big one. Okay, so I'm just gonna yeah it's big. So let's just begin by saying Ok so what the problem basically asked us for is to create the circle to D. Classes. Creation of the class on the class is a bunch of private data fields. There's three private data fields. We have to create the set methods for each one. Um and classes supposed to construct a circle object which has center um X I guess here it should say um X. Um Why? Uh and uh Y equals zero. So it should initialize with X equals zero, Y equals zero and radius I guess zero. Um And the respective getting set methods uh and then we're supposed to create a bunch of methods to get area which of course gets its area. Um Prince Prince the area get parameter which which Prince the perimeter. And then these other ones contain point contained circle and overlaps. And we'll get into those in just a second. Now, I just want to talk a little bit about the questions that I actually had some problems with and it's really these contained points contains circle and overlaps. So the basic idea, I guess if you let me let me scroll down here a bit. So if you have a point here, so we'll just say we have this point here, okay? And you know, you just have to forgive me because I'm really not very good at drawing but um if we have a circle here, so we have a circle like this going around the sky and this circle of course has the radius here of our so it has a radius and I'll call this the radius big are okay now this is our circle object. So this is our this and I guess you'd say in some sense this is our circle object. This is sort of like a pickerel representation of our circle. Ob. So we'll just call this C. one which is a circle object. Okay? Now we have out here um so we have out here some other point here, we'll call this point why here? Okay? And it we'll just say there's another circle here and of course has this point at the center and I'm sorry that my my circles aren't beautiful, but I try my best here and this guy has another radius which is a little R No, I got to admit this whole conversation is pretty important. So please forgive me for going on about it, but it's kind of important. So this guy here is my c. two. Okay, this is c. two. we'll call it circle object, circle object. Uh huh. Two. Okay. Now the first thing that you should be. So the first question of course is how can we tell if there is any overlap? Well that's a good question. How can you tell that? Because um certainly when we uh let me see here if I okay, so if I grab this object will just take it over here for now and you look and uh we obviously have our little point. Why here? So why is the center here? And you'll see that if we draw a line, so if we draw a line from extra wise we just draw a line through wire. Yes. Okay. Um now obviously this this line um has some distance and we'll call that distance D. So the line from X to Y. Has some distance D. So dear. Um is D. Oops, okay, the uh is equal to the distance from and I'm just going to call it Big X. Two Big Y. To avoid the the concerns with the coordinates versus the guy itself. Okay, so um this distance here, the distance between the points has the distance uh X. Distance from X to Y. And now what we're concerned with is when so you can watch this little circle. If you draw it as it crosses this point here, as it crosses the the outer perimeter of the circle, it goes from having no overlap and all the answers being false to having overlap. You know that once it crosses there it has some overlap and then slowly bit by bit if if if this is my center again. So So this whoops wrong one. So. Okay. Yeah, this guy. Okay. Yeah, if this were my center here, obviously, sorry, it didn't work out very well, but that's my center, obviously. Now the center is contained in it and then at a certain point the whole circle becomes, becomes contained in there. So the main problem I had with doing this is first off trying to find conditions that guaranteed that the um, the one circle is contained in the other and to do this, basically, I did some, you know, I'm not, I'm not going to explain the algae run everything behind it, but I have to admit that this was a big problem to me. And as you'll see in the the forthcoming solution, um, I did basically what I did is I ended up doing some algebraic manipulations to find the equations that I needed. And then once I found those, then, um, then everything else was, you know, okay. But it it's quite involved problem trying to figure out what the conditions are and they end up being pretty simple but I I still needed to justify them. So because this problem so involved, I'm just gonna cut to the chase and show you the program I wrote. And then I'll show you the test program and work you through the steps of the the program itself and then the test program. And then we'll just glance at the results. Finally we'll go over the uml diagram and that will be it for this one. So okay so here we go. Um this is the circle to be. And first off because I'm using square roots and stuff, I had to import math So I did that but now I created this class two D. And of course like I said here these guys are my um So Class two d. So when I do it I have to first define the initialize er method and of course whenever you do that you self. And because it's said to initialize X. Y. And the radius to zero initially um I set that X two B zero, Y. Zero and radius to be zero. And now these are private methods, so use the underscore as such, so I set myself underscore X to be X and so on and so forth. Um And now get X. Now that these are the assessor methods. Again, now the assessor methods, all they're doing is they're returning their respective variable, the respective values and because their their their private they cannot be seen from the outside. I so you Doing the assessor meth methods allows 1 to see it. Um And then the mutate er method. Again, the mutate er methods. All they're doing is they're allowing you to input new values in for the X to Y and the radius. So this allows you to mutate the original object. Well, okay. Um so moving on now we get to the methods he asked for and these are now not just get assessor mutate or message uh to get area, of course is just returning the area and now this is where we start needing to use math because we the math module because we need this math pi number and all I'm returning of course, is the the corresponding area here. I'm returning the perimeter of course for the perimeter and now we get to a little bit more interesting one which is this contained point. So contains point of course, just you just input some point X and Y into the function and then it mm it returns true. If the distance here, the distance from the point to the center is less than the radius of the circle, you return true and false. Otherwise, if we go to the diagram, I mean really it's pretty clear what's happening. Basically. I have some, you know, point out here, you know, some point here which is a. B. And I'm just looking at the distance from the point to here. So I'm just looking at I'm just calculating that distance and if it's less than a little r, r big r then I'm good if it's not so fault. Okay, now contains here is taking another circle objects. So to um to do contains you actually have to calculate, you have to create a second circle object and then you and I will show you how to do it in just a moment when we when we do the implementation of it, but you just taken another circle object and then you use the get methods of the the circle object and the gap methods of the given object. So my current myself object and you do the calculations and what I've done here is basically I first calculate the distance uh and I say well if the distance, if the distance if this distance distance plus the radius of my current circle, so um sorry this this distance I calculate here plus the distance of my um input circle. In other words my other the other circle I created if that is less than my current distance or the radius of the big circle, then I returned true, otherwise I return false um to to show this what this is doing is um so remember the distance here, so this distance here is D okay and this distances are so this is our so basically what the the calculation there is saying that um the it's asking uh if B. Plus Little R. Is or I'm sorry? Um Yeah yeah yeah D. Plus little R. Is less than big are basically you can think of big are as being something like this, and I'm actually thinking this is incorrect. Let me just check here. Something's not right about that. Um Sorry um Sorry? Um Uh that was not to write one. Oh I see, I'm I apologize, I'm sorry. Uh This one is the overlaps. Oh okay. Or this one's that contains I'm sorry this one's that contains module, that's why, because I knew this wasn't the right calculation. Um Yeah, so the the point here is that um what you're uh this picture is getting messy now, I'm sorry. So if we maybe we go down a little further and so I have the circle here, I have that circle there which has radius big are um and then I have another circle um like this guy here and the two centers will be here here. This is why. And assist X. So if I draw the line between it, I draw the line between X and Y. This has just this is distance. The and this is distance are so D. Plus R. D. Plus little R. Is um the distance from this point here. So D. Plus R. Is the distance from here to the what would be the farthest point away from X. So D. Plus R. Is the farthest point away from X. Within this circle. So D plus are is furthest point uh in circle in a circle C. Two from center X. Or big X. Of circle? Uh C. One oh this point is the furthest away. So if um and D. Plus are is that distance from here to there? So if this is um if this is less than big are then this circles would be contained in this circle would be contained in there. And that's what this that's what this calculation is after. And you have to remember how to do it because um yeah because here we have to use the gut method um on both circles, this one's for the circle, you're inputting the circle to d. And this one's for the the current circle. Um And finally and then you return true. If it's less than finally on the last one then um the overlaps. The overlaps condition is pretty much is similar to the other one basically overlap. I'm really looking at compared to the other one. I'm really just looking at, whoops. Sorry, what I'm looking at is this point here. So if I if I draw that line again, so if I draw this line again here passes through the center, sorry, it's supposed to be a straight line, it passes through the center here and just focusing on this point here, which is on the vector from X. Y. Um And as soon as this point is less than our from X, then there's overlap. So that's that's pretty much what this this equation here. Um This final one does, is it try basically, I found a way to calculate that and if that's less than I'm not going to go into it. But if that's less than if the distance is less than big hour plus little are then I return true and it's false otherwise. Okay. So as you can see this is actually quite a law, it is actually quite involved problem. Um But you know, we'll just run it and finally what I want and the fine and the next step is then to look at the the test program. Now the test program in itself is kind of interesting because I'm doing something here that there is a little different than what I did in previous videos in this one. I actually read in The coordinates, X. Y. and Radius in one line. And then so I just took the input of X. Y. And radius for both circles. Some the question um asked you know of course to prepare two circles. So I'm just in putting the two circles with the corresponding X. Y. And radius. Um And then what I what I do is um basically so I create this longer string which is my string one. Um comma my string too. So I'm taking the original strings here creating a longer string. And then what I do is I I just. Uh huh. You know I I split this string because these numbers are split by comma. So I have X. One Y. One radius. And I split this string by the comma. So that's one becomes the the terms before the first comma. Why one string becomes the terms before the second comma. And then radius string one becomes the turns it for the third one, so on and so forth. You have the 4th 1/5 1. And then you're done. So that's what I'm doing here. And then of course I'm creating my circle which is the circle to the object created by the of course I need to use floats. So I just use the float of these strings because they're turned. If you do this you're just turning it into to a number element. Now or I guess a string element. But by using float it becomes a number. Um And then basically I go through and then I actually apply it here. So again let's just look at the resultant. Okay? And if I print out, so I go five, 5.5 and 10, this is the example from the book again. So this is nine, 1.3 and 10. And that's the print out that I get. So the area of the circle, of course history under 14 point blah blah blah perimeter. Both circles apparently had very close to the same or the same radio. Yeah, they had the same radius, so they have the same area and perimeter. And you can see um see one contains C. Two, but it does not contain all of C. Two contains the center of C. Two, but not all of C. Two and their overlaps. Okay so let's um uh let's uh let's let's go let's move on to the uml diagram here. Okay so the so the uml diagram um let's see. Okay let's just go to the bottom here. So the ml diagram again um And this is I hope by now you guys have kind of become accustomed to what this is supposed to be I guess or how to do this. So this is circle uh uh Two D. Okay and again it has the variables. The private variables X. Y. Radius. No these are all private variables. Sorry private data fields. I call them variables. I get used to the term. I'm a mathematician by trade so I'm used to thinking them as variables but the proper languages data fields here and of course they just reflect the the properties, you know the properties of the circle object were they of the circle object? Cervical mm object I guess reflect isn't really the right term they represent or carry I guess they give the circle I guess is probably a better word. Okay. Um And they're all private. So now we have the circle uh two D. And it has um X equals to zero and it's a float Y equals to zero. It's also a float and radius equals to zero and it's a float again. The the equal zero just means that it initialize is it Or it's If you don't if you don't give a value two x. Um In the when you when you set it up when you find a circle object then you know then then it will set a zero. Um So in particular what I mean is I can go like this let me see I can go um C equals to circle um radius equals to two and sure oh sorry I did that wrong. C equals to circle um To the Radius Radius Radius Equals two, one. And and then you can get um Or I should say c. one got get get X. And what, sorry? It's C dot get tax is what I mean and the X coordinate of the circle is zero, you know, so on and so forth. So it's so funny but that's what the initializing at zero does is it um gives it gives the gives the sort of the initial value or something the term. Um Okay so um and then we have the the get an assessor methods for the private variable. So we have gets X. And of course this is just float. It's all it does is give you the value as I showed you get why? Again it's a float and get radius and it's just a float. Um And then the assessor or the mutate er which is set X. And X. Which is a float. And it returns non none. Okay. Set why and why float and returns none. And then um sat radius, radius radi us I guess something like that can't even spell radius and then rad and of course none. And and like I said these are just the mutate er which which allows you to mutate the initial object. Um And finally we have the Gatch area and it returns afloat. Just just calculates the area of the given object. Jet rim immature again returned the float and then contains point and this is of X. Float and why afloat. Um Again it just it returns a boolean true or false statement whether the points in the circle or not and then contains um which Mick circle To D. or two d. That's a circle objects, Circle object and this returns bullying um whether whether the circles contained in these in your object or not and finally overlap, overlap and that again um Circle two on the object circle object circle circle object and again it returns of the land. You know again it returns true or false whether circles continue their or not. Okay so that that's the that's the idea. I mean this is necessarily an involved problem. It's a lot of different things. It's very nice problem but it's very involved. So I hope maybe I help you a little bit. I don't know but hopefully I did and you know thank you very much and have a nice day.


Similar Solved Questions

1 answers
'.0Show that f(x) Vx satisfies & Lipschitz condition o [a,0),a > Prove" that Vx is uniformly continuous on [0. 0) Show that does not satisfy Lipschitz condition on [0, 0)
'.0Show that f(x) Vx satisfies & Lipschitz condition o [a,0),a > Prove" that Vx is uniformly continuous on [0. 0) Show that does not satisfy Lipschitz condition on [0, 0)...
5 answers
Point? McKTigaHolcsAsk Your TeacherUnless otherwise stated, answers that need to be rounded should be rounded to three significant digits.For the following, 0 is a central angle in circle of radius r. Find the length of arc cut off by 0. (Round your answer to two decimal places:) 0 = 309 r = 2 mmmm
point? McKTiga Holcs Ask Your Teacher Unless otherwise stated, answers that need to be rounded should be rounded to three significant digits. For the following, 0 is a central angle in circle of radius r. Find the length of arc cut off by 0. (Round your answer to two decimal places:) 0 = 309 r = 2 m...
5 answers
The Ksp of Cu3(P04)2 is 1.4x10^-37. What is the minimum [Cu2+] thatyou can have to just start precipitation of the copper(Il) phosphate from a solution that is 0.0035 M in the phosphate?
The Ksp of Cu3(P04)2 is 1.4x10^-37. What is the minimum [Cu2+] thatyou can have to just start precipitation of the copper(Il) phosphate from a solution that is 0.0035 M in the phosphate?...
5 answers
Tha polynomial of derree 3, P(z). 6. Thc y Interceot i y Find fornula Pls) P{-)root of mutiplicity 2at >and qoot of multiplicity
Tha polynomial of derree 3, P(z). 6. Thc y Interceot i y Find fornula Pls) P{-) root of mutiplicity 2at > and qoot of multiplicity...
5 answers
#*" @Use the given transformation LF - , 4) Let evaluate the u =*+- and v integral: L =Xt =y - 642 U=t f f (+y) sin '(y -x) dx dy SS usV dudv where R is the V= region bounded by the lines y=X y=x+5, Y =-X Y =-Xt A) 4(1 + cos 5 ) B) 4(1 cos 5 C) 8(1 cos 5 )
#*" @ Use the given transformation LF - , 4) Let evaluate the u =*+- and v integral: L =Xt =y - 642 U=t f f (+y) sin '(y -x) dx dy SS usV dudv where R is the V= region bounded by the lines y=X y=x+5, Y =-X Y =-Xt A) 4(1 + cos 5 ) B) 4(1 cos 5 C) 8(1 cos 5 )...
5 answers
Vo Lincor Fegrss; & c) 5)Time (h) Compared to Radiation Level (%)shaasrad BlednJ
Vo Lincor Fegrss; & c) 5) Time (h) Compared to Radiation Level (%) shaasrad Bledn J...
5 answers
If 2 = € + iy, 2 # 0 and 2 = i, write the complex expression in the standard form a + ib_ 1 _ zi
If 2 = € + iy, 2 # 0 and 2 = i, write the complex expression in the standard form a + ib_ 1 _ zi...
5 answers
Question 22 ptsFind the coefficient of determination: (Round your answer to three decimal places )
Question 2 2 pts Find the coefficient of determination: (Round your answer to three decimal places )...
5 answers
Consider the following clementary reaction NO(g) Nz(g) +O(g)Suppose wc let k, stand for the Nte conslant of this reaction, and stand for the rate constant the ruverse reaclun_ Write an expression that gives the equilitxiumn concentratlon of N, in terms ofkj' k_ and the equllibriumn concontrations OfNzO and _ [n] ()Fal 0j
Consider the following clementary reaction NO(g) Nz(g) +O(g) Suppose wc let k, stand for the Nte conslant of this reaction, and stand for the rate constant the ruverse reaclun_ Write an expression that gives the equilitxiumn concentratlon of N, in terms ofkj' k_ and the equllibriumn concontrati...
5 answers
Logic proofPvQ:(PvR)v(QvR) (8)
Logic proof PvQ:(PvR)v(QvR) (8)...
5 answers
The suitable substitution toevaluate the integral fvtan (2x) dx is COS 4(2x)0 U = cot(2x)0 u=tan(2x)@ U= sec(2x)OD noneVy u = csc(2x)
The suitable substitution to evaluate the integral fvtan (2x) dx is COS 4(2x) 0 U = cot(2x) 0 u=tan(2x) @ U= sec(2x) OD none Vy u = csc(2x)...
5 answers
Consider the following reaction. Which are conjugate acid/basepairs? HNO2(aq) + HS-(aq) ----> H2S(g) +NO2-(aq) Group of answerchoices H2S & NO2^- HNO2 & HS^- HS^- & NO2^- HNO2 &NO2^- HNO2 & H2S
Consider the following reaction. Which are conjugate acid/base pairs? HNO2(aq) + HS-(aq) ----> H2S(g) +NO2-(aq) Group of answer choices H2S & NO2^- HNO2 & HS^- HS^- & NO2^- HNO2 & NO2^- HNO2 & H2S...
5 answers
Find an equation of the parabola that has : (2,-10). vertex at (5,-1) and whose graph passes through the point y=-(r-S)' - 1 ve(r-1)+5 ye(r-1) -5 ve(r+5)' - 1 y=-(r+1)' -5
Find an equation of the parabola that has : (2,-10). vertex at (5,-1) and whose graph passes through the point y=-(r-S)' - 1 ve(r-1)+5 ye(r-1) -5 ve(r+5)' - 1 y=-(r+1)' -5...
5 answers
# Graph pobutston V 8 the Proctorad Placament raph the parabola Assossmnent the 1 B 0 two points R the left of
# Graph pobutston V 8 the Proctorad Placament raph the parabola Assossmnent the 1 B 0 two points R the left of...
5 answers
Mosi nonenve Ioped human viruses lyseikill tne cell during release stalernen: CORRECT? Yes ecauseNor Lenvelajed viruses exit the cell via exocylosi: which ccesn lyse Ihe cell. Yes because when the vmus non-eMvl DjCc means ess Iax c and can exil Ihe ce Witnouc lysing AlI the viruses general must lyse the cel "hen Ihe; ale eased: No, because nonenvelcped virses do not nave exlernal Hcmbrane dificult easec withou: lysing the cell:
Mosi nonenve Ioped human viruses lyseikill tne cell during release stalernen: CORRECT? Yes ecauseNor Lenvelajed viruses exit the cell via exocylosi: which ccesn lyse Ihe cell. Yes because when the vmus non-eMvl DjCc means ess Iax c and can exil Ihe ce Witnouc lysing AlI the viruses general must lyse...
5 answers
50 part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below:#of Courses Frequency Relative Frequency Cumulative Frequency 24 0.48Complete the table_What percent of students take exactly two courses?
50 part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below: #of Courses Frequency Relative Frequency Cumulative Frequency 24 0.48 Complete the table_ What percent of students take exactly two courses?...

-- 0.021839--