An algorithm is a precise plan (in the format of a sequence of steps) on how to solve a particular problem.

learn more… | top users | synonyms

5
votes
1answer
23 views

Algorithm to calculate semi perfect integers, lack of effeciency

I'm working on an algorithm to calculate weird numbers, and to do so there are several properties that needs to be calculated, one of them being, if it is NOT a semi-perfect/pseudoperfect number. My ...
5
votes
2answers
63 views

Binomial coefficient

I wrote a C++ function to calculate the binomial coefficient, trying to avoid overflows as much as possible. ...
6
votes
1answer
54 views

Implementing Karatsuba Multiplication Algorithm in Python

I am trying to implement Karatsuba multiplication algorithm for binary (base 2) numbers. A requirement is that the intermediate / final results must also be in binary so as to assist in educative ...
4
votes
1answer
39 views

Create thumbnail in the original ratio without empty space

I need to make thumbnails without empty space and in the original ratio. Please help me check this algorithm to improve it. ...
0
votes
0answers
24 views

Optimizing TSP branch and bound algorithm in C [on hold]

I implemented this Branch and Bound algorithm below but I can't get optimal results, not even with 5 points. It just works on the right child but not on the left. ...
-3
votes
1answer
73 views
4
votes
2answers
73 views

Getting the unique factors of a number recursively

I have written the below code to get the unique factors. Please offer suggestions for better results. ...
3
votes
1answer
65 views

Determining maximum profit to be made from selling shares

Question Your algorithms have become so good at predicting the market that you now know what the share price of Wooden Orange Toothpicks Inc. (WOT) will be for the next \$N\$ days. ...
8
votes
4answers
166 views

Adding two sides of an array

The purpose of the program is to add 2 sides of an array starting from the bottom and top of both ends and to find the lowest difference at equal decrements of iteration. The program functions but ...
1
vote
0answers
34 views

Deepest left leaf node in a binary tree

Given a Binary Tree, find the deepest leaf node that is left child of its parent. This question is attributed to GeeksForGeeks. Looking for code-review, optimizations and best practices. ...
6
votes
2answers
79 views

Flatten a multilevel linked list

Given such a structure the output should be ...
2
votes
2answers
41 views

Calculating the number of prime numbers to solve the puzzle

How can the following program execution time improved? I have used dynamic programming in both "recursive" as well as "prime" function, but I'm not getting the efficient execution time. There is ...
3
votes
1answer
42 views

Reverse values of alternate nodes of the tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
0
votes
0answers
23 views

Return the next right node

Given a binary tree, return the next right node. This question is attributed to GeeksForGeeks. For example, consider the following Binary Tree. Output for 2 is 6, output for 4 is 5. Output for 10, 6 ...
5
votes
2answers
62 views

Possible combinations following a rule

The problem is the following: We have a number of months to buy a number of supplies. The sooner we finish buying them, the better, but we don't know how much we can buy per month and would like to ...
0
votes
0answers
32 views

Add two numbers represented by linkedlist

Given two numbers represented by two linked lists, write a function that returns sum list. The sum list is linked list representation of addition of two input numbers. It is not allowed to modify the ...
4
votes
1answer
57 views

Seeking improved Objective-C permutation algorithm

This algorithm seeks to find all of the possible permutations of a word: ...
7
votes
1answer
63 views

Response to an answer: Solution to maxMirror problem

Garrett Openshaw had an okay answer to Improvements on solution to Codingbat maxMirror problem? But there were a couple of issues with the code he gave, so I decided to review it and make it a little ...
0
votes
1answer
32 views

Using Comprehensions to Handle a Large Dataset in Python 2.7

I have a Python 2.7.6 script parsing large files (~60MB to ~2GB) containing lines of the following format: componentA componentB < floating point value > My goal is to sum the floating point ...
1
vote
1answer
66 views

Get the levels of a binary tree

Given a binary tree, return a list of each level. I'm looking for a general review and a mention on best-practices, optimization, and verification of my complexities. Time complexity: \$O(n)\$ ...
5
votes
5answers
97 views

Improving efficiency for two sum

I am trying to solve this problem: Given an array of integers, find two numbers such that they add up to a specific target number. and this is my strategy: For each ...
1
vote
2answers
49 views

Binary Insert Method - handling edge cases

I've created a function that uses binary search to insert an element into an array (similar to this question). I haven't benchmarked it, but based on my knowledge it should get \$O(1)\$ in the best ...
2
votes
0answers
22 views

C code for hash-consing: how could its performance be increased?

I've isolated this function, cons, for hash-consing in C. It is where the bottleneck of my program is. How could its performance be improved? ...
3
votes
1answer
16 views

Bit compressing in JavaScript

I have an bit array var data = []; ... and I have the following function: jsPerf ...
12
votes
4answers
203 views

I'm not sure if I still love Fibonacci, but my code is getting better. How much better?

Technically, this is a follow up to these two questions, but I have taken a radically different approach. Everybody Loves Fibonacci Does everyone still love Fibonacci I finally allowed myself to ...
-1
votes
0answers
35 views

Followup to BigInteger Cube Root Optimization

Followup to Followup: How do I optimize this Java cube root function for BigInteger? Here's my current code for this cube root approximation for BigInteger, which returns the integer part of the cube ...
1
vote
0answers
19 views

NGON (many polygons) on SPOJ - Time Limit Exceeded

I am trying to solve NGON problem. I am using bottom up dynamic programming here. Recurrence function is: ...
3
votes
1answer
35 views

How to generate valid number of combinations of datacenter and its host id?

I have a list of datacenters, which are dc1, dc2 and dc3. And each datacenter has six ids as ...
4
votes
1answer
66 views

Followup: How do I optimize this Java cube root function for BigInteger?

Followup to How do I optimize this Java cube root function for BigInteger? So I've tried several implementations of this algorithm. The version using only BigInteger sometimes results in a ...
2
votes
2answers
44 views

Merge N sorted list

Given n sorted lists, merge them. This is a fairly common question, attributed to plenty of interview question websites. I'm looking for code-review, optimizations and best practices. I'm also ...
9
votes
4answers
279 views

Threshed and Malachi'd: Sieve of Eratosthenes

I took a little bit from all the answers to my previous question Threshing: Sieve of Eratosthenes. This may be bordering on code-golfing, but I think that I have a pretty good piece of code here. ...
3
votes
1answer
42 views

SPOJ is giving TLE for this solution of ROCK

I am solving ROCK problem on SPOJ. I have used bottom up dynamic programming approach for this problem. Time complexity for this is \$O(n^3)\$. ...
6
votes
3answers
160 views

Iterator of iterator

Given an iterator of iterators, return all of the elements from the iterators in order. Looking for code review, optimizations, and best practices. Verifying complexity to be \$O(n)\$, where \$n\$ is ...
2
votes
1answer
88 views

Why are these functions slower than BigInteger's included methods?

I tried writing alternative functions to Java's BigInteger.add(BigInteger.ONE), BigInteger.add(BigInteger), and ...
5
votes
4answers
363 views

Threshing: Sieve of Eratosthenes

I would like a complete threshing of this code so that I can see what I did wrong and what I am using incorrectly. I made this super simple, trying to learn a little bit about ...
6
votes
1answer
57 views

Longest Common Substring solution for a string and a list

Recently I have discovered one thing, which makes me feel frustrated. The Perl is lack of syntax sugar for strings, to do the same things, those are applicable to lists. The implementation I posted ...
5
votes
2answers
166 views

How to generate valid number of combinations basis on the rules?

I have a list of datacenters, which are dc1, dc2 and dc3. And each datacenter has six ids as ...
3
votes
1answer
41 views

Automatically gravitate popover towards page center

I've authored a couple of plugins which show popovers on a given element. One of the objectives for both was no specification of plugin direction. So instead of the implementing dev having to specify ...
1
vote
0answers
35 views

Find K distant nodes

Find all nodes, which are at a distance of k from the input node. Input: target = pointer to node with data 8. ...
4
votes
0answers
51 views

Fibonacci number function: convert to tail-recursion?

I've been implementing a function for calculating the nth Fibonacci number in F#. So far the best implementation I could come up with is this: ...
6
votes
3answers
70 views

Searching all diagonals of a 2D M x M array

I've started writing a piece of code to help me search for an object in all the objects found in the diagonals of an M x M 2D array. Though the code works, I'd like to know if there is a way I can ...
4
votes
1answer
51 views

Product of corresponding elements in 2 arrays

Given two arrays A and B, of length N and length k ...
6
votes
1answer
50 views

Canonicalizing a large set of addresses using many regex substitutions

I have a script that is standardizing a large amount of data in the database. The standardization involves applying over 500 regular expressions to the data. Here is some quick pseudocode: ...
8
votes
5answers
747 views

Splitting company name into 3 strings

I wrote an algorithm which should cut a companies name into 3 strings. Input: 1 String Output: 3 String. Conditions: String 1 2 and 3 shall not be longer then 35 signs. If the Input ...
-2
votes
1answer
92 views

Given a BST, transform it into greater sum tree

Given a BST, transform it into greater sum tree where each node contains sum of all nodes greater than that node. Diagram is here. Looking for code review, optimizations and best practices. ...
1
vote
1answer
59 views

Solving the coin change algorithm using 10 coins

I'm solving the coin change problem having target of n and upper bound as n. Also the maximum number of coins is 10. For example. if the target is 11. then the possible outcomes are - ...
6
votes
2answers
137 views

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree

Given a Perfect Binary Tree, reverse the alternate level nodes of the binary tree. Given tree: ...
5
votes
1answer
84 views

Parallelizing scrypt key-derivation function

To review my use of multiprocessing, I don't think it is at all necessary to understand the algorithm, but it's the scrypt key-derivation function. This uses ...
6
votes
1answer
111 views

Finding all paths from a given graph

I need to find all paths from a given graph. I can do that for now, however my recursive code is not efficient and my graphs are very complicated, hence I need a better algorithm. ...
3
votes
1answer
115 views

Minimum number of letters removed, to make a string Peragram

Here is the link to the problem Peragrams. Peragrams: If a word is an anagram of at least one palindrome, we call it a Peragram. Problem: Given a string, find the minimum number of letters ...