Tagged Questions

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

4
votes
2answers
52 views

Finding the weight of the heaviest path in a binary tree

I'm fairly new to Java, arriving in the "future" from C and returning to type safety from Python. I've programmed an algorithm to return the weight of the heaviest path from the root of a binary tree ...
2
votes
2answers
44 views

Optimizing name highlighting

I have created a set of functions, that when given a struct of structs full of names, it will highlight those names that appear in a body of HTML based text. Is this the best method of doing this? ...
6
votes
1answer
68 views

Excel VBA binary search class module [on hold]

I have a long list of sorted strings in a Workbook, and I have to find a lot of values in it. I was hoping to build a binary search Class Module that will find them for me faster than Excel's built-in ...
1
vote
0answers
22 views

Extract logic applied in a sequence of integers

I've done it in C# before but thought that a functional language would be a good fit for this kind of thing. From this ascending list of integers: [100,103,106,112,118,121] I had to calculate ...
9
votes
4answers
2k views

Brute force password cracker

I wrote this script for a proof of concept JavaScript password cracker: ...
5
votes
2answers
236 views

Tremaux Algorithm

I am trying to implement Tremaux Algorithm for a 2D maze. So far the robot works well however I have some problems with retraceStep(). I'm not asking how to ...
4
votes
0answers
30 views

Mostly portable 128 by 64 bit division

I wrote this out of curiosity. It is based on the theory behind Knuth's Algorithm D, and intended to emulate the behavior of the x86 div instruction (though the ...
10
votes
2answers
133 views

Validating a Binary Search Tree

This is an implementation of a function to check the property of a Binary Search Tree, that is: the key in any node is larger than the keys in all nodes in that node's left subtree and smaller ...
4
votes
3answers
69 views

Finding strings inside of other strings in order in C

A question on Stack Overflow recently intrigued me to the point of me implementing the functionality in C. Can you critique this algorithm and tell me what is good and bad about it? This program will ...
2
votes
1answer
37 views

Binary Search in C

The standard C library function bsearch wasn't giving me correct results, apparently. So I decided to implement a binary searching function in place of it. It ...
0
votes
2answers
59 views

Optimizing Dijkstra implementation using PriorityQueue in Java

I am trying to make Dijkstra implementation more efficient. Below is the code for class Node which implements Comparable so it ...
3
votes
1answer
50 views

Improving efficiency of Prim's Algorithm

I have implemented Prim's Algorithm in Java. I am wondering how it can be made more efficient. Below is the class Node for vertices. ...
13
votes
4answers
397 views

Array alive/dead entity “refresh” algorithm

I have an Entity class that can be either dead or alive. I store entities contiguously in a resizable array. During an ...
9
votes
2answers
88 views

Min triangle path - bottom-up

I got a bit intrigued with the recent question DP solution to min triangle path and after a certain chat message I decided that I wanted to implement my solution. Given a triangle, find the ...
6
votes
5answers
145 views

DP solution to min triangle path

I am studying for interviews for various companies. I wrote a solution to this problem, but if an experience programmer looks at it I am sure there are certain areas the code can be made in to a more ...
5
votes
1answer
41 views

Formatting database like table

The goal of my program is take some headers and fields and display a nicely formatted table like this: ...
2
votes
2answers
39 views

has_cycle in directed and undirected graphs

I wrote a program that can tell if a graph has_cycle or not. Can you please suggest more elegant and eloquent ways for this program? (Perhaps better ways to represent a graph with vertices and ...
6
votes
5answers
582 views

Given a String, return a boolean if it is a number

Yesterday in an online interview, the interviewer asked me this question: If I give you a string, you have to return if a string is number or not. You are not allowed to use any parse function ...
6
votes
3answers
90 views

Making backtracking Knight's Tours solution more efficient

This was a previous homework assignment I was required to do. While I did the assignment and turned it in for credit, I am not completely satisfied with the result I have. The rule for the assignment ...
2
votes
2answers
42 views

Collatz Conjecture in Python

The Collatz's Conjecture states that any number can either be halved (if it is even) or multiplied by three and added one to (if it is odd) and eventually reach 1. I was wondering if there was a more ...
7
votes
1answer
40 views

Joining collections… because it's fun

I'm working on a LinqEnumerable class (reviewable here), and I'm no Big-O expert and I'm pretty bad with algorithms, so I wonder what the complexity is for what ...
0
votes
0answers
60 views

Skyline problem solved by sweep line

Can you please suggest more elegant and eloquent ways for this problem? (Perhaps better ways to represent a graph with vertices and edges?) Skyline problem is described here. ...
5
votes
2answers
102 views

More optimized approach of Dijkstra's algorithm

I need a graph-search algorithm that is enough in our application of robot navigation and I chose Dijkstra's algorithm. We are given the gridmap which contains free, occupied and unknown cells where ...
2
votes
2answers
113 views

Max path sum algorithm

This is for Project Euler question 18 and I'm looking for feedback on whether my algorithm is incorrect or whether I've just implemented it wrong (which I don't think is the case after some testing). ...
4
votes
2answers
249 views

Finding 10-unique-digit number with i-first-digits divisible by i

I was posed this question by a friend: I am a natural number written with 10 different digits such that for all \$i ∈ {1, . . ., 10}\$ the number formed by my \$i\$ first digits (from left to ...
6
votes
4answers
97 views

Efficient prime factorization for large numbers

I've been working on a little problem where I need to compute 18-digit numbers into their respective prime factorization. Everything compiles and it runs just fine, considering that it actually works, ...
5
votes
2answers
191 views

Random song playing app improvements

I have a substantial music collection, which will not load entirely in any music program. So I wrote this quick program, to play a random song in a subfolder of my music directory. I'm just ...
3
votes
1answer
99 views

Finding the longest unique sub-string in a string

I recently interviewed with a company for software engineering position. I was asked the question of finding the longest unique sub-string in a string. My algorithms was as follows: Start from the ...
5
votes
1answer
128 views

Iterative Fibonacci sequence using standard library functions

We're all aware of Fibonacci sequence calculators but they look like C-style code. I want to avoid that and take advantage of the standard library. This code is very short, so I'm focusing on ...
2
votes
3answers
70 views
4
votes
1answer
76 views

Filling a container with objects using pointers / iterators

I have a series of nested objects that I need to serialize into a byte (unsigned char) array to send out to another computer over UDP. Right now I each object ...
0
votes
2answers
56 views

Populate inorder successor for all nodes

Given a binary tree where each node has following structure, write a function to populate next pointer for all nodes. The next pointer for every node should be set to point to inorder ...
6
votes
1answer
83 views

Breadth First Search not SOLID enough v2.0

Here is a link to my original question: Breadth First Search not SOLID enough Here is my first attempt at refactoring. Instead of using a Tuple, I used a ...
3
votes
3answers
125 views

Miller-Rabin Recursive Primality Test

I'm working on a primality test and have written a recursive function that returns the value of the function \$b^{q-1} \bmod q\$ where \$3<= q <= 32000\$ Is there any way to speed up ...
7
votes
1answer
72 views

Sorting algorithms with utility functions and iterators

My implementation of insertion, merge, and quick sort, with some utility testing functions. I just wanted to know how I can improve the efficiency and general cleanliness of my code. (note: I know ...
8
votes
1answer
155 views

Breadth First Search not SOLID enough

The following code has a modified version of the Breadth First Search algorithm. It not only visits the nodes, but keeps track of the paths, so I can output various messages later. I would like to ...
4
votes
1answer
433 views

Maximizing XOR HackerRank challenge

I know that there are combinatoric libraries for this kind of thing. However, with me being new to C# and coding in general I found that I couldn't understand the code well enough to implement it in ...
6
votes
4answers
838 views

Karatsuba C++ implementation

I've written an algorithm for integer multiplication using the Karatsuba method in C++. This implementation is far from ideal, so any comments are welcome. ...
1
vote
1answer
65 views

Create a complete binary tree

Write a program to create a complete binary tree, which includes an addItem method such that an individual element can be inserted into the tree to maintain the ...
4
votes
2answers
180 views

Printing element combinations that make a neutral compound

An array is given with the element name and their respective pH values. Print the combination of 2 elements which make a neutral compound Here is the solution that I came up with but uses a ...
5
votes
2answers
219 views

Re-arrange a string into a { consonant, vowel, consonant, vowel … } sequence

I was prompted to give someone advice about the following problem: Given a string with equal amount of vowels and consonants, re-arrange it so that it follows the sequence { consonant, vowel, ...
3
votes
3answers
84 views

Multi-replacement in a string, independently and prioritized

I need a shorter way to do this. input: an ordered list of string pairs L; and a string s task: for each pair ...
2
votes
1answer
102 views

Nsum problem: find all n elements in an array whose sum equals a given value

I am implementing the algorithm for the following problem with Python. I am pretty new to Python, so I want to listen to any advice that improve my coding style in a "pythonic" way, even about naming ...
3
votes
1answer
79 views

Count frequency of words in a string returning list of unique words sorted by frequency in descending order

I have the following solution but I am trying to optimize it to run in O(n) time, any thoughts? I first split the string removing any non-alphanumeric characters, then split the words using spaces ...
2
votes
1answer
66 views

Ruby on Rails Method ActiveRecord Query Optimizations

So I have three methods and I'm not sure how to optimize them. I will be working on this and updating this post while I do but basically running these three methods is central to some parts of my ...
7
votes
1answer
62 views

Merging lines of an array

I've got an array like this, which is a result from a Google analytics request. I asked for the amount of visits for the last three months. ...
11
votes
1answer
349 views

Steganography for images

For a school project I'm working on a small library to do steganography. I've just finished the first method of steganography and thought I'd get some feedback. This steganography method works by ...
0
votes
2answers
104 views

Fastest way to find maximum deviation

I acknowledge that this exact question was asked here. I was working on the same problem from the same website. I had the same question and consulted the above as a reference, however with respect ...
3
votes
3answers
312 views

Determine if a string has all unique characters

I'm practicing algorithms (for future interviews) while learning about Big O notation and was wondering if there's a faster or more optimal way of writing an algorithm to see if a string has all ...
14
votes
4answers
670 views

Count number of ways to paint a fence with N posts using K colors

A friend sent me this question, and I'd love somebody to review this and give his opinion. Write an algorithm that counts the number of ways you can paint a fence with N posts using K colors ...