473,503 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please Help

2 New Member
Could I please have the solutions to the following problems


1. (4 points) Your friend has to write code to make sure that the parentheses in an arithmetic expression are balanced, i.e. for every left parenthesis there is a matching right parenthesis. She wants to use a tree to do this. You argue that if all you want to do is match parentheses, then a stack will work fine. How will you use a stack to do this?

2. (6 points) A palindrome is a string that reads the same forwards as backwards.
Describe how you would implement a function that, given a string, determines whether it is a palindrome. Your function can use only one stack and one queue. Your function should return true if the string is a palindrome and false otherwise.
For example:
palindrome( “abba”) true
palindrome( “bbba” ) false

3. (20 points) For this question you are to implement a two-ended stack of ints. We will define a two-ended stack as a list in which entries can be pushed or popped from either the first or last position of the list, but no changes may be made elsewhere in the list. We will define the fundamental operations on a two-ended stack to be:
push_front – pushes an item on the front of the two-ended stack
push_back - pushes an item on the back of the two-ended stack
pop_front – removes and returns an item from the front of the two-ended stack
pop_back – removes and returns an item from the back of the two-ended stack
Your assignment is to implement the TEStack (two-ended stack) methods listed below using a singly-linked list. You should use the header file provided below. You do not need to implement copy constructors, destructors, or operator= for these classes, but otherwise the routines you implement should handle memory management appropriately.

a) (2 points) Implement the constructor for TEStack.
b) (6 points) Implement your push_back method.
c) (6 points) Implement your pop_back method.
d) (6 points) Implement your pop_front method:

4. (12 marks) Recursion
Consider the following recursive program.
//n is any positive integer
//m is a positive integer between 2 and 9
void fun(int n, int m)
{ if (n<m)
cout << n;
else { fun(n/m, m);
cout << n%m;
}
}
a) (3 marks) What is the output for fun(15, 2)?
b) (3 marks) Given the following recursive code. Point out the possible errors in the code.
//num is a positive integer
int fac(int num)
{ if (num_1)
return 1;
else {return num*fac(num+1);
}
}

c) (6 marks) Given the following function which computes Fibonacci numbers using recursive function, write a non-recursive version of function fib.
//num is a positive integer
int fib(int num)
{ if (num==0) return 0;
if (num==1) return 1;
return (fib(num − 1)+fib(num − 2));
}

5. a) (3 points) Draw the binary search tree created by inserting these values in this order:
3 4 0 2 8 6 5 1 7 9

b) (2 points) Give a pre-order traversal of your tree shown above:
c) (2 points) Give a post-order traversal of your tree shown above:
d) (3 points) Delete the root of the tree shown above using one of the two methods described in class. Draw the new tree.

6. (20 points) Tower of Hanoi

We are given a tower of n disks, initially stacked in decreasing size on one of three pegs, say A.





The objective is to transfer the entire tower to one of the other pegs, say C, using the other, say B, as a temporary peg, and obeying the following two rules of the game:
• only one disk at a time can be moved
• a larger disk can never be moved onto a smaller one
Implement the Towers of Hanoi using recursive data structures in C++. State all the assumptions you may decide to make.
Sep 16 '07 #1
4 1883
Ganon11
3,652 Recognized Expert Specialist
The experts on this site are more than happy to help you with your problems but they cannot do your assignment/program for you. Attempt the assignment/program yourself first and post questions regarding any difficulties you have or about a particular function of the code that you don't know how to achieve.

Please read the Posting Guidelines and particularly the Coursework Posting Guidelines.

Then when you are ready post a new question in this thread.

MODERATOR
Sep 16 '07 #2
rumbylove
2 New Member
I really need the solutions to the problems.Please, if you cannot provide all the solutions it's fine. Even if it is just one solution you provide, I don't mind. I really need your help because all this is jargon to me. The level at which we are taught and the level of difficulty of these questions do not coincide. If I were to show you my lecture notes and you can compare them with thesse questions you would understand what I mean.

these questions were taken off the internet from an American college's website. Now the thing is I am in Africa at a university where facilities are limited. This is a research I am conducting PLEASE HELP








I really need the solutions to the problems.Please, if you cannot provide all the solutions it's fine. Even if it is just one solution you provide, I don't mind. I really need your help because all this is jargon to me. The level at which we are taught and the level of difficulty of these questions do not coincide. If I were to show you my lecture notes and you can compare them with thesse questions you would understand what I mean.

these questions were taken off the internet from an American college's website. Now the thing is I am in Africa at a university where facilities are limited. This is a research I am conducting PLEASE HELP
Sep 16 '07 #3
sicarie
4,677 Recognized Expert Moderator Specialist
Rumbylove-

The contributors of this forum will not do any of your homework for you. Please read Ganon11's reply. You can try it yourself, and we can help you with it, but right now you have copied and pasted your homework and asked for us to give you answers, twice.

You must show that you have attempted the problem. It looks like your first two problems don't even require any code, just an algorithm (instructions of how to solve the problem without a computer). And your third, you are given many of the function names you need to implement - that shows you how your teacher wants it implemented. Try working on one at a time and posting what you have tried.
Sep 16 '07 #4
ndekaspecial
1 New Member
spoonfeeding removed
Oct 1 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1679
by: Kurt Watson | last post by:
I’m having a different kind of problem with Hotmail when I sign in it says, "Web Browser Software Limitations Your Current Software Will Limit Your Ability to Use Hotmail You are using a web...
7
3570
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title>...
7
3249
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
23
3232
by: Jason | last post by:
Hi, I was wondering if any could point me to an example or give me ideas on how to dynamically create a form based on a database table? So, I would have a table designed to tell my application...
13
4296
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
1
9584
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
1
54451
PEB
by: PEB | last post by:
POSTING GUIDELINES Please follow these guidelines when posting questions Post your question in a relevant forum Do NOT PM questions to individual experts - This is not fair on them and...
0
3034
by: 2Barter.net | last post by:
newsmail@reuters.uk.ed10.net Fwd: Money for New Orleans, AL & GA Inbox Reply Reply to all Forward Print Add 2Barter.net to Contacts list Delete this message Report phishing Show original
6
3280
by: jenipriya | last post by:
Hi all... its very urgent.. please........i m a beginner in oracle.... Anyone please help me wit dese codes i hv tried... and correct the errors... The table structures i hav Employee (EmpID,...
5
2287
by: tabani | last post by:
I wrote the program and its not giving me correct answer can any one help me with that please and specify my mistake please it will be highly appreciable... The error arrives from option 'a' it asks...
0
7199
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4667
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3161
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.