Hi there. I've been trying to solve this problem for a few days now but it seems I haven't grasped the concept of recursion,yet.
I have to build a program in C (recursion is a must here but loops are allowed as well) which does the following:
The user inputs 2 different strings.For example:
String 1 - ABC
String 2 - DE
The program is ...
int Size(struct node* node)
{
if(node == NULL)
{
return 0;
}
else if(node != NULL)
{
return (Size(node->left) + 1 + Size(node->right));
}
}
Hi, can anybody please post the stack trace for the following piece of code.
Lets say if we insert the values 2, 1, 10, 5...
Then what could be the stack representa...
I'm relatively newcomer on programming as I'm educated a mathematician and have no experience on Python. I would like to know how to solve this problem in Python which appeared as I was studying one maths problem on my own:
Program asks a positive integer m. If m is of the form 2^n-1 it returns T(m)=n*2^{n-1}. Otherwise it writes m to t...
Most of the times, the definition of reentrance is quoted from Wikipedia:
A computer program or routine is
described as reentrant if it can be
safely called again before its
previous invocation has been completed
(i.e it can be safely executed
concurrently). To be reentrant, a
computer program or routine:
Must hol...
Hi,
I would like to get all combination of a number without any repetation.
Like 0.1.2, 0.2.1, 1.2.0, 1.0.2, 2.0.1, 2.1.0.
I tried to find an easy scheme but couldn't find so I drawed a graph/tree for it and this screams to use recursion.
But I would like to do it without, if this is possible.
So could anyone please help me how to do th...
I am practicing recursion and I can't see why this method does not seem to work.
Any ideas?
public void fact()
{
fact(5);
}
public int fact(int n)
{
if(n == 1){
return 1;
}
return n * (fact(n-1));
}
}
Thanks
...
I've got some Javascript code which uses fairly deep recursion and I'd like to find out what the recursion limits in the various browsers are (i.e. the point at which the error "too much recursion" will happen).
Anyone have any solid numbers on this, by version?
...
Are there examples of recursion using only heap area?
...
Say that you are several levels deep into a recursive function. The function was originally called in main. Is there a way for you to break out of the recursion and go straight back to main without having to go through all the other functions above?
...
I have a StaffLookup table which looks like this.
UserSrn | UserName | ManagerSrn
===============================
ABC1 | Jerome | NULL
ABC2 | Joe | ABC1
ABC3 | Paul | ABC2
ABC4 | Jack | ABC3
ABC5 | Daniel | ABC3
ABC6 | David | ABC2
ABC7 | Ian | ABC6
ABC8 | Helen | ABC6
The staff stru...
In C, is it possible to use recursion within the sprintf function ? For some reason I get a segmentation fault when I do it:
inline char *TreeNode_toString(const TreeNode *node)
{
char *out;
if(TreeNode_isExternal(node)) // If the node has no children...
{
sprintf(out, "%s:%.2f", node->name, node->distance);
}
else // The...
here i wrote a function , it's general purpose is to get an array of the depIds under the parent root $depId.
i use recursion method to get the array:
public function getEmpsByDep($depId){
$query = "select * from ".SQLPREFIX."department where id_parent=".$depId;
$stmt=$this->db->query($query);
while(($row=$this->db->fe...
If I have a common table expression for a family with mother & father, how can I increment the 'Generation' counter? A family should have the child as generation zero, parents as generation 1, and the four grandparents as generation 2. But the loop is performed twice, one for each set of grandparents.
;WITH FamilyTree
AS
(
SELECT ...
I have a class Group. In the class I have two fields, idGroup IdGroupGroup. Groups may be part of other groups. My class Group is defined in a HashMap<Integer,Integer>; the key is IdGroupGroup and value is idGroup. I want to search the map for a particular idGroup; can I use recursion to do this?
class Group
{
int idGroupe
Stri...
I am having extreme difficulty constructing a query which returns an XML style hierarchy.
We have a database table which contains a hierarchy of URLs for our website. The table contains the columns: ID, URL, DisplayName, ParentID, ItemOrder
The parent ID forms a recursive relationship between the current item and it's parent. The item ...
Our professor gave us the following assignment:
A "correct" series is one inwhich the sum of its members equals to the index of its first member.
The program is supposed to find the length of the LONGEST "correct" series within a series of n numbers.
for example: if the input series would be arr[4]={1, 1, 0, 0}
the output (long...
I have a response from remote server like this:
/home/computer/Downloads
|-- /home/computer/Downloads/Apple
| `-- /home/computer/Downloads/Apple/Pad
|-- /home/computer/Downloads/Empty_Folder
`-- /home/computer/Downloads/Subfolder
|-- /home/computer/Downloads/Subfolder/Empty
`-- /home/computer/Downloads/Subfolder/SubSubFolder
...
I am working with an implementation of merge sort. I am doing C++ Visual Studio 2010. But when I took a array of 300000 integers for timing, it is showing an unhandled stackoverflow exception and taking me to a readonly file named "chkstk.asm". I reduced the size to 200000 and it worked. Again the same code worked with C-free 4 editor (...
It takes about minute to achieve 3000 in my comp but I need to know the millionth number in the series. The definition is recursive so I cannot see any shortcuts except to calculate everything before the millionth number. How can you fast calculate millionth number in the series?
Series Def
n_{i+1} = \floor{ 3/2 * n_{i} } and n_{0}=2....
Currently in my application I have a single table that is giving me a bit of trouble. The issue at hand is I have a value object that is mapped to this table. When the data is returned to me as an array of value objects, I have to then loop through this array and begin my recursion by matching the ParentID to parent ObjectID's.
The col...