Recursion in computer science is a method of problem solving where the solution to a problem depends on solutions to smaller instances of the same problem.
3
votes
1answer
44 views
A recursive function that performs a binary search
I created a recursive function that uses binary search to just return true if it finds the value and false if it does not.
I'm new to recursion and binary search so please let me know where I can ...
0
votes
1answer
25 views
What efficiencies can I make to my recursive binary search function? [on hold]
I'm trying to use recursion and learning about binary search at the same time. So I created a binary search function:
...
1
vote
2answers
35 views
Find all subsets of a list whose sums equals to elements in another list
Problem statement: Given two list of integers find all subsets in first list whose sum is equal to element in another list and print the remaining items in both list
Example:
Input: Big List= {250, ...
0
votes
0answers
17 views
Height of all nodes in a binary tree [on hold]
My code only show the height of all tree but i m lost with print all height nodes.
...
0
votes
0answers
26 views
Ternary tree preoder traversal (recursive implementation)
Problem statement:
Print out to console the ternary tree preorder traversal. Suppose that the tree can have at most 3 children, left, middle and right. Preorder traversal is to visit the middle ...
3
votes
2answers
36 views
Print all possible codes for a given string
My question is to print all possible codes for the string.
Assume that value of a=1, b=2, c=3, d=4, .... z=26.
E.g. for “1123” possible codes are aabc, kbc, alc, aaw, kw
Here's what I could come ...
1
vote
0answers
73 views
Hackerrank > Woman's CodeSprint 2 > stone division, Revisited ( recursive function)
Problem statement
You have a pile of n stones that you want to split into multiple piles, as well as a set, S, of ...
0
votes
0answers
24 views
KnapSack Solution using recursion and Arrays [closed]
I would like to know the best possible way to modify this code. Instead of adding the integers to an array in the code itself, I would like the user to input the different weights and the capacity via ...
3
votes
2answers
51 views
Get value from dictionary given a list of nested keys
I would like to get a deeply-nested value, for example {"a":{"b":{"c":"myValue"}} by providing the keys to traverse. I tried chaining together .get() but that didn'...
7
votes
3answers
249 views
N-Queens Recursive Implementation in C++11
I created a recursive, optimized, N-Queens implementation in CPP. Any suggestions for improvement?
...
3
votes
0answers
25 views
JavaScript Recursive Filtering With AND and OR
I am doing the #JavaScript30 challenge and challenge 06 is to write a "type ahead" application for searching for cities/states. The basic challenge of filtering based on a simple string was rather ...
-1
votes
0answers
19 views
F# tree-building function causes stack overflow in Xamarin Studio [migrated]
I'm trying to build up some rules in a tree structure, with logic gates i.e. and, not, or as well as conditions, e.g. property x equals value y. I wrote the most obvious recursive function first, ...
3
votes
2answers
70 views
Recursive Contains Method
The method below recursively checks if a string contains another string. Example: contains(hello, lo, 0) should return true, ...
4
votes
1answer
66 views
String permutations
So I have tried the famous string permutation algorithm.
Example for those who are not familiar with the algorithm:
ABC -> ...
3
votes
1answer
69 views
Pizza ordering program recursion on the GUI
This program is a basic pizza ordering program with seven topping options, four size options, and five crust options. It pulls the options from a database and populates the GUI on start.
I connected ...
2
votes
1answer
40 views
Search for layers in Adobe Illustrator by name
I am looking for some advice on some speed increases on my Adobe Illustrator (AI) script. Just so you know, the script runs fine and is at a decent speed (couple seconds to maybe a minute max for ...
2
votes
0answers
33 views
Recursive function to get unique properties
I just wanted to share my newly created javascript code. This code is responsible to pass back only a the unique elements for a given array. This one is quite useful when you have a huge array and ...
2
votes
3answers
181 views
Project Euler: Longest Collatz Sequence
The Collatz Sequence is an iterative sequence that is defined for all positive integers as such:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
If 13 were to be entered into this sequence, the result ...
2
votes
2answers
72 views
Pascal's Triangle without using combinations
I wrote this code for Pascal's Triangle using recursion. Can someone please help me to review it for better performance?
...
9
votes
8answers
2k views
Counting number of eights
I was doing a few basic Java recursion problems to refresh my memory with recursion (honestly never had to use it in a long, LONG, time), along with using it as a useful way to prepare for any ...
8
votes
2answers
873 views
Python traverse a directory recursively and print contact numbers
I am writing a python code to recursively traverse a directory containing only text files and then print the 10 digit Indian phone number and all its variants. I am very new to python and I have ...
0
votes
1answer
58 views
Javacript code to flatten JSON via recursion with conditional logic
I'm flattening a JSON structure where objects have their interaction type appended at the end, for use in an HTML/PDF generated file. I have variable names for Checkboxes, Text inputs, TextCheck is a ...
3
votes
1answer
142 views
Request for memory optimizations for solution to Google FooBar challenge, “ion_flux_relabeling,”
I just finished one of the Google FooBar Challenges.My Python is super rusty. I did the challenge in Haskell first and then attempted to covert the code. I am guessing that led to some bad Python ...
2
votes
1answer
77 views
Flattening a nested map [closed]
We're migrating our streaming ETL application from Python into Clojure,
the hottest part of the code isn't yet performing as well as our existing
implementation. This looks to be down to the ...
2
votes
0answers
17 views
Converting a source XML to a target desired XML format
I have been able to create an XSLT (included) to convert a source XML to a target desired XML format (included). However, I am sure this can be optimized leveraging some built in XSLT capabilities ...
6
votes
2answers
109 views
Building a set of all subsets recursively in C++
Here is my recursive implementation of a power set function in C++. One thing that concerns me is that I am iterating over the set of sets while modifying its size. The code nevertheless functions as ...
3
votes
3answers
107 views
Saving complex business objects with reflection and recursion
In our application we have complex objects with many nesting levels, each with various properties that are important to the business. We currently serialize and persist these objects along with their ...
1
vote
0answers
37 views
UVA: Y2K Accounting Bug
The Challenge
Accounting for Computer Machinists (ACM) has sufferred from the Y2K bug and lost some vital data for preparing annual report for MS Inc. All what they remember is that MS Inc. posted ...
1
vote
1answer
74 views
Tower of Hanoi: graphical representation of optimal solution
I wrote a program to show graphically the solution of the problem of the Tower of Hanoi. Here is a video of an example run.
The logic of the solving is taken from StackOverflow (see links in ...
-1
votes
1answer
52 views
3
votes
1answer
42 views
Rust recursion pattern in simple cat program
I'm trying to get my head around recursion in Rust. I've put together a basic implementation of cat here to play with the basics.
Here's my recursive version:
<...
2
votes
0answers
30 views
Generalizing work orders
I am working on designing tables for work orders.
The problem:
There is different work order models (from now on called WOM)
The WOMs share some attributes (Num, Date, Description, ... etc)
The WOMs ...
5
votes
1answer
78 views
Find paths whose sum equals a target value in a binary tree
You are given a binary tree in which each node contains an integer value (which might be positive or negative). Design an algorithm to count the number of paths that sum to a given value. The path ...
1
vote
0answers
112 views
HackerRank university codesprint array construction
Problem statement
Professor GukiZ has hobby — constructing different arrays. His best
student, Nenad, gave him the following task that he just can't manage
to solve:
Construct an \$n\$-...
6
votes
1answer
109 views
Filter Duplicate Elements in Haskell
I'm working on HackerRank to try to improve my Haskell skills along side with reading Haskell Programming from first principles. I wrote a program that works, but it seems to time out on large input ...
1
vote
1answer
45 views
Add 1 to a number represented as an array of digits, using recursion
Given a non-negative number represented as an array of digits, plus one to the number.
The digits are stored such that the most significant digit is at the head of the list.
Explanation for using ...
1
vote
1answer
96 views
Cons List in Python
It make sense to not allow links to external code hosting, so I restated my question. This is classical cons list in python using Abstract Base Class interface. Constructor is in fact out of the Cons ...
3
votes
2answers
252 views
Java exhaustive solution
This is a take on Pebble Solitaire. The user inputs n number of games and after that inputs a strings of length 23 that contains a combinations of only 'o' (pebble) and '-' (empty space). If there are ...
2
votes
1answer
65 views
Groups/colors/removes cells
Based on the value of what is in column B (column A is hidden) it groups/colors/removes the corresponding node(s). "R - " values are nodes that need to be grouped. The rows are 6 cells apart before a ...
3
votes
1answer
90 views
Return path to a value in a nested object
Description:
Its not a programming challenge but I though to write a small utility which will return the path to a primitive value in a possibly nested object. The idea is not original.
Code:
...
3
votes
2answers
64 views
Get subsets of a set given as a list
This code is meant to create a list of subsets of a given set which is represented as a list.
I'm doing this to improve my style and to improve my knowledge of fundamental algorithms/data structures ...
7
votes
2answers
105 views
Recursive higher-order function
I have implemented a through function for myself in a project.
Since I am still quite new in python and want to learn it correctly, I would be happy about any ...
1
vote
2answers
64 views
Pascal's triangle in mit-scheme
As suggested by the name of source file (ex1.12.scm), I just started learning mit-scheme by reading SICP. In Exercise 1.12, I'm asked to "compute elements of Pascal'...
5
votes
1answer
107 views
Interleaving of two strings
I have written this recursive code to find all interleaves of two strings, where the order of strings are preserved. For example:
s1="abc" s2="1"
a1bc
ab1c
abc1
...
1
vote
0answers
68 views
Optimizing Python Code in terms of Time - Recursive Function [closed]
I wrote the following code but it takes a lot of time, about 20 seconds. The code has recursion and the recursion depth doesn't exceed 100 in any case. When it is run a sufficient amount of times ...
4
votes
0answers
133 views
Assembling and traversing a tree, given a list of items and parent pointers
I've written a function which takes input such as this:
...
2
votes
2answers
63 views
Binary Tree Inversion
I solved this problem.
Invert a binary tree.
4
/ \
2 7
/ \ / \
1 3 6 9
To this
...
4
votes
2answers
172 views
Migrating data using entity framework, linq and recursion
I have a piece of code to migrate data from an old app to a new app. The data represents the user's websites.
In the old app the user only had one section for websites, on which you could add any ...
1
vote
0answers
15 views
Greedy recursive search [closed]
So I am trying to implement a groupSize method and a helper functions.
Here is one idea: set up a local Set of Spots to hold spots you’ve found so far in the cluster. From the current spot-position, ...
7
votes
2answers
132 views
Split string to space-separated words based on dictionary
This program is based on as old retired Google interview question where you're supposed to create a program that will split a string into space-separated words, if the string is composed of valid ...