250 Topics

Member Avatar for
Member Avatar for vibhu mishra

i have a c code for printing all permutation of string. I have a problem in understanding ,how recursion work in for loop and how backtracking is used in this code. Another question is that how stack work in recursion under for loop. my code--> # include <stdio.h> void swap …

Member Avatar for David W
0
352
Member Avatar for birinci2012

def isPrime(num,div=2): if(num==div): return True elif(num % div == 0): return False else: return isPrime(num,div+1)

Member Avatar for slate
0
995
Member Avatar for Schol-R-LEA

In most modern languages, there are two fundamental approaches to repeating an action: either *iteration*, in which an action is placed inside a special-purpose structure which causes the action to be repeated, or *recursion*, in which a general-purpose function calls itself (or another function which in turn calls the earlier …

Member Avatar for Ancient Dragon
1
2K
Member Avatar for mike_2000_17

Following up on a discussion on [this thread](http://www.daniweb.com/software-development/cpp/threads/470519/looping-using-recursion/), I did some tests on the performance of recursion vs. iteration, and some interesting things happened, so I thought I would share the results. I'm gonna structure this a bit like a lab-report, because that's really the best way to put it. …

Member Avatar for Tumlee
4
665
Member Avatar for CheerfulBiscuit

Hey everyone, I really need help in solving a problem that I have to use recursion for. I have a list of paper objects. Each paper object has its own author(s) objects. Each author object knows which paper(s) objects they belong to. I have to build a scholarly neighborhood for …

Member Avatar for JamesCherrill
0
240
Member Avatar for jackslv

This is just a piece of code I've found over the Internet, and I'm trying to understand why the output is 3 1 1 2 1 1 2 3. Could anyone explain using a stack representation or something else, I am really stuck on this one. #include <iostream> using namespace …

Member Avatar for jackslv
0
232
Member Avatar for kruschev

#include <iostream> using namespace std; int f(int i) { if(i == 1) { return (1); } else { return 2*f(i-1); } } int main() { cout << f(5) << endl; //<--- I don't understand why this is 16. return 0; } I am having trouble understanding why f(5) = 16 …

Member Avatar for kruschev
0
214
Member Avatar for woomar

Hi. I was wondering how I could replace objects in a list without using a single loop. Here's what I have in terms of algorithm; but, I don't know how to implement.: replace(List list, oldObject, newObject) 1. if the first element in list is not null 2 if the old …

Member Avatar for woomar
0
238
Member Avatar for MrHardRock

Hey guys I had an assignment to recursively write the Towers of Hanoi then test it. I did not have too much of an issue getting the program written But I am not sure what the book means by test the efficiency do they want the number of moves my …

Member Avatar for stultuske
0
899
Member Avatar for RounaqJJW

float det(float A[][10],int m) { float B[10][10],d=0; int i,a,b,x,y; if(m==2) return (A[0][0]*A[1][1])-(A[1][0]*A[0][1]); else { x=0;y=0; for(i=0;i<m;i++) { for(a=0;a<m;a++) { if(a==i) continue; else { for(b=1;b<m;b++) { B[x][x]=A[a][b]; x++; } } } if(i%2) d-=det(B,x); else d+=det(B,x); } } return d; } I tried to run the program, but it exits with error …

Member Avatar for ddanbe
0
187
Member Avatar for Stju

Let's use the basic example.. I have a table for tree representation with just 3 columns: ID, PARENT_ID,NAME. If I delete a record X, how can I delete all recursive records that refer as PARENT_ID of deleted record?

Member Avatar for Rahul47
0
125
Member Avatar for harde_1

Im trying to add Total function and isMono functions to this code. Did total already Need help with function ismono which returns whether a tree is mono (all the elements are unique aka no element appears more than one time) or not. Please this is the original program #ifndef T_H …

Member Avatar for deceptikon
0
306
Member Avatar for Labdabeta

Hello, First of all some background. My friend and I are having a bit of a competition over theoretically infinite number storage. We have agreed that the first person with a working arbitrary precision integer library with the theoretical ability to store an infinitely large number (IE: if the hard …

Member Avatar for Labdabeta
0
291
Member Avatar for Aethir

# This is an advanced guess the number game. import random # The very basis of this game. import math # Used for math.ceil import time # Used to split up long portions of text. def errorDisplay(errorCode): if errorCode == '1': print('\n\n\nError ' + errorCode + ': unlockedGameModes outside of …

Member Avatar for Aethir
0
277
Member Avatar for Griff0527

I am trying to write several different sorting algorithms in order to time the differences between them when reading a file of a half million integers. For testing purposes, I am only using a few hundred integers, but I am getting a stack overflow error. Also, for testing reasons, I …

Member Avatar for mike_2000_17
0
3K
Member Avatar for fatalaccidents

Hello all, I'm having trouble writing a spell checker as my recursive function isn't returning what I would like it to. It is meant to chop off the ends of words likes "baker" to bake and check against a predined dictionary. I used recursion for words like "baker's". I have …

Member Avatar for bguild
0
175
Member Avatar for amvx86

Hello all, I am trying to get a bunch of sub-keys and values from the registry in vb 2010 and i remember in vb6 this was quite easy. Can anyone share code to help? Or a link where I can go? I've been searching for nearly 8 hours on line …

Member Avatar for amvx86
0
2K
Member Avatar for newGains

i am trying to use recursion to find the occurence of a specific character in an array of characters public class CharacterCounter { public static void main(String [] args) { char test[] = {'a', 'b', 'a', 'c', 'd', 'a', 'e', 'a', 'f', 'g', 'h', 'a', 'i', 'a'}; char searchChar = …

Member Avatar for newGains
0
256
Member Avatar for HankReardon

Hello, Would someone be willing to take a look at this segment of code? I am trying to figure out how this segment of code operates. I can see how the program can evaluate a simple prefix statement like + 7 6. I cannot see how the program can solve …

Member Avatar for HankReardon
0
252
Member Avatar for tingwong

Hi everyone I am having trouble finding the nth node of a binary search tree in an inorder traversal. I am getting NullPointerExceptions for any numbers other than 2 and 3 and even those print out the wrong values. If anyone could help it would be greatly appreciated. The method …

0
129
Member Avatar for hous3aholik

Hi I'm working on the implementation of a boolean method to check if an expression has balanced parentheses using recursion. I cant figure out how to check if two elements of a given expression match i.e ( ). I was able to finish it without a problem using stacks, but …

Member Avatar for chuck.kollars
0
4K
Member Avatar for bleedsgreen33

I inherited a website here at work. The menu system uses a convoluted jquery / javascript structure. There are 8 different types of "users" for this website, from administrator to contractor or accountant, etc, and the person made 8 different versions of the menus covering nearly 80 different pages within …

Member Avatar for tokick4
0
3K
Member Avatar for cerealBoxx

Hi again, I have the simple code below, and I receive the error "best overloaded method match has some invalid arguments". I tried to return a string or an int and then it said that I can't implicitly convert void to string. Any ideas on how I can overcome it? …

Member Avatar for ddanbe
0
141
Member Avatar for cerealBoxx

Hi guys, I have this code - I am trying to find if a number is present in a given array using recursion. The thing is, I get the error "not all code paths return a value". I don't know how to fix this. Please advise. using System; namespace checkArrayForValue …

Member Avatar for aaa_78600
0
543
Member Avatar for somjit{}

this code gives the correct result upto size 6 (i'v run this a few times, and 6 seems to be the boundary), although the intermediate steps are all insane! then onwards, from size 7, it returns minimum value 0 /*minimum of an array using recursion*/ #include<stdio.h> #include<stdlib.h> int findMin(int* arr,int …

Member Avatar for somjit{}
0
361
Member Avatar for programmer007

Is it possible to convert a postfix expression to prefix expression using only recursion? If possible what's the algorithm?

Member Avatar for Taywin
0
117
Member Avatar for primzon

Hello, Does anyone know how to write recursive SQL statement for hierarhic output places from next table: TABLE PLACES: id-----place----------idParentPlace 1......World..........Null 2......Europe.........1 3......Mediterranean..2 4......North Europe...2 5......Italy..........3 6......Greece.........3 7......Island.........4 8......Norway.........4 I don't know if this is totally correct SQL recursive statement: WITH recursion AS (SELECT id, place, idParentPlace, 1 AS hierarhic …

Member Avatar for Biiim
0
215
Member Avatar for primzon

Hello guys, Do anyone know how to write recursive SQL statement for hierarhic output places from next table: id-----place----------idParentPlace 1......World..........Null 2......Europe.........1 3......Mediterranean..2 4......North Europe...2 5......Italy..........3 6......Greece.........3 7......Island.........4 8......Norway.........4 I was looking for alot of tutorials but didn't find anything useful. Any help is the most welcome! Regards, TP

Member Avatar for debasisdas
0
183
Member Avatar for sbharathind

public static void nonRecursiveInorder(Node node) { Stack<Node> st=new Stack(); st.push(node); Node temp; while(!st.isEmpty()) { temp=st.peek(); if(temp.left!=null && temp.left.visited==false) st.push(temp.left); else { if(temp.left==null && temp.right!=null && temp.right.visited==false) { System.out.print(" "+temp.value); temp.visited=true; st.pop(); st.push(temp.right); } else { if(temp.left!=null && temp.left.visited==true && temp.right!=null && temp.right.visited==false) { System.out.print(" "+temp.value); temp.visited=true; st.pop(); st.push(temp.right); } else …

Member Avatar for sbharathind
0
207
Member Avatar for tony75

Hi How can I create a recursive method that counts how many files with a certain file extension, which is in a directory and the directory's sub directories. Exceptions that can be thrown in the search of the file tree should be handled appropriately. The user of the program should …

Member Avatar for tinstaafl
0
188

The End.