473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Please Help

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 1874
Ganon11
3,652 Expert 2GB
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
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 Expert Mod 4TB
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
spoonfeeding removed
Oct 1 '07 #5

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

Similar topics

0
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
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
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
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
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
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
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
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.