Tagged Questions
An algorithm is a sequence of well-defined steps that defines an abstract solution to a problem. Use this tag when your issue is related to algorithm design.
2
votes
0answers
16 views
Why is my algorithm blowing up? Exercise 1.8 in SICP
I'm doing Exercise 1.8 from SICP and Scheme's interpreter freezes when I evaluate my algorithm. Does anybody know why?
Newton’s method for cube roots is based on the fact that
if y is an ...
0
votes
1answer
8 views
Converting pymysql Comment objects to tree recursively
I am trying to create a comment system as a part of a hobby project, but I cant figure out how to recursively sort the Comment object once they have been fetched from the database. I'm using a ...
0
votes
1answer
58 views
Merge sort failing to work in N logN
I have written a merge sort algorithm, but it fails to sort in N log N.
The code for sorting an array list is:
void merge(int start, int mid, int end) {
int i,j,q;
for (i=start; i<=end; ...
-4
votes
2answers
38 views
Print all permutation of length k that can be formed from a set of n characters?
public class PrintStrLenK {
public static void main(String[] args){
int k = 2;
char[] set = {'0', '1'};
char[] str = new char[k];
generate(k, set, str, 0);
}
...
0
votes
2answers
33 views
Playing random sound from raw folder with fisher yates shuffle algorithm on android
please help me, I want to play the sound of raw folder android studio random using yate fisher shuffle algorithm with a single button.
I use this code:
public void playSound() {
MediaPlayer mp;
...
-1
votes
2answers
32 views
how to find the second largest value in the tree
I am not getting the logic of how to find the second largest element in a tree.
public static int largestR(TreeNode<Integer> root){
if(root==null){
return Integer.MIN_VALUE;
}
...
-2
votes
1answer
5 views
check if given array can represent a postorder traversal of BST
guys i need an algorithm that can find if the given array represent post-order traversal of Binary Search Tree and thanks.
0
votes
2answers
41 views
Inversions in a binary string
How many inversions are there in a binary string of length n ?
For example , n = 3
000->0
001->0
010->1
011->0
100->2
101->1
110->2
111->0
So total inversions are 6
0
votes
1answer
29 views
How to implement merge operation in merge sort for sort.Interface data?
Suppose I want to implement a merge sort as a function which accepts a sort.Interface and then sorts it:
func MergeSort(data sort.Interface)
Internally I need to manage indexes of currently sorted ...
1
vote
1answer
15 views
Knapsack or similar with no values and with limits as to which items can be assigned where?
Say I have a number of weights which I need to spread out across knapsacks so that each knapsack has as even a distribution of weights as possible. The catch is that different weights can only be put ...
3
votes
3answers
81 views
Given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M
You are given two 32-bit numbers, N and M, and two bit positions, i
and j. Write a method to set all bits between i and j in N equal to M
(e.g., M becomes a substring of N located at i and ...
0
votes
2answers
72 views
Arrange the numbers by subtracting
I have a java problem that I don't know how to solve the program is :
two number must got from user n,k.
I need to find a permuation of numbers from 1 to N such that the difference between two items ...
0
votes
0answers
16 views
how to predict ecommerce sale by using google analytics' data [on hold]
since Google analytics is very powerful to show the web analysis and eCommerce activity. I would like to know that how to use the data from GA to do the sale forecasting.
such as build the sale ...
0
votes
0answers
34 views
Estimate stroke width from image [duplicate]
I have been working on handwriting recognition, I am thinking of an approach where if I get to know the average thickness of the marker used (pixels used), I will be able to segment characters from ...
1
vote
1answer
19 views
find all the local maximum for an array that is either increase or decrease by 1
How to find an algorithm that runs in O(k log n) times, Where k is the number of local maximum and n is the size of the array
for example:
[1,2,3,4,5,6,5,6,7,8,7]
0
votes
1answer
32 views
Backup algorithm for windows service
I have to design a backup algorithm for some files used by a Windows Service and I already have some ideas, but I would like to hear the opinion of the wiser ones, in order to try and improve what I ...
1
vote
0answers
28 views
Implement LOESS/LOWESS algorithm in Python/R
Some questions raised while trying to write a python/r version of LOESS. I searched the web but did not get satisfied answer. The original C version wrote by Cleveland which proposed and described in ...
0
votes
1answer
30 views
Why my code can't pass the test case from LeetCode 322 Coin Change?
Link to the problem: https://leetcode.com/problems/coin-change/
My code can't pass some test cases from LeetCode:
def coinChange(coins, amount):
"""
:type coins: List[int]
:type amount: ...
1
vote
1answer
37 views
c# Decrypt data which stored in sql server
In ms SQL server, I have a field text with data look like below:
"!"$$$$$$!#$$$$!!!!! !!!!!!!!!!!!!! "!! ! " !" ! !" !!!! ! !!"!".
I belive that from a plain text string, they using a Rijndael ...
3
votes
1answer
34 views
using heap helps boost performance for string rearrange
I'm working on the problem below and have posted my code. My question is, my current implementation is using a sort in Python - sorted(sorted_freq, reverse=True). I referred some other implementation ...
1
vote
1answer
54 views
What kind of algorithm is needed for this
I was asked to help make a basic materials calculator for a friend, but I'm not really sure what kind of algorithm this is since I only do some coding casually and my math skills are probably nowhere ...
2
votes
0answers
49 views
My dithering algorithm is super slow
So here's some context. I'm working on this game called ShiftOS which takes place in an OS that starts off as a bare-bones run of the mill 80s operating system with not many features.
I'm trying to ...
0
votes
1answer
28 views
Subset and Set Cover
We are given a number of locks and to open these locks we need exactly that set of people to open that lock. Given the number of people we have and the number of locks that needs to opened, we need a ...
0
votes
3answers
37 views
Merge two collections (with duplication) to one collection (without duplication)
I have problem with syncing data on multiple clients.
For simplicity, let's say I have two collections where may be duplications (name is the key):
"collection1": [
{
"name": "a",
"...
0
votes
3answers
26 views
Method to find location of a given string in a sorted string array interspersed with empty strings
The premise of this problem is a sorted array of strings that's interspersed (in no particular order) with empty strings, like so:
["at", "", "", "", "ball", ""]
My algorithm came down to finding ...
0
votes
1answer
27 views
Encoding of list of sum of 2 dice that has better compression. (byte restricted)
Imagine any game in which two six-sided dice are used.
It is needed to store the history of the game, we want to store the sums resulting from rolling the dice in the whole game.
In traditional ...
3
votes
1answer
79 views
std::sort algorithms memory usage
I'm wondering whether the standard libraries sorting algorithms (e.g. std::sort) are using the heap memory for sorting.
Is there any reliable source how to find out what kind (heap, stack) and how ...
-4
votes
0answers
17 views
calculate gap to best known solution of an algorithm in R [on hold]
I'm a beginner in R, but for this problem i didn't find an answer or topic yet on this forum.
I need to analyse 31 algorithms, knowing their solution value and running time on 1140 different ...
0
votes
2answers
84 views
Need to make my algorithm faster
I need to make my program faster, but I just can't figure out how. Here is the problem. I have a sequence of numbers sorted like this:
7
4 8
2 5 9
1 3 6 10
7
\
4 8
\ \
2 5 9
\ \ \
1 3 6 10
...
0
votes
0answers
50 views
Reverse a rope data structure [on hold]
I have created a rope of characters and I need to get a substring and then reverse it. I'am using substr() function to get substring and reversing that substring using reverse iterators
Code Snippet
...
0
votes
1answer
23 views
What is a good way to determine a fixed hash function for a hardcoded hash table?
Often I find myself needing a hash table whose values are known at compile time and are known to never change.
I want to know if there is a standard way to generate a tailor made algorithm that is to ...
-1
votes
1answer
32 views
How do I create a method that compares 2 integer arrays and get a percentage of how alike they are?
For a personal project I need to make a method, that compares two integer arrays and outputs how a percentage value of how alike they are. The arrays can be of different lengths from each other.
I.E. ...
2
votes
1answer
45 views
Way to group coplanar triangles in THREEJS mesh?
I'm working on a modeling tool that lets you directly manipulate meshes. For instance, you can grab a face and drag it around. The user's perception of the "face" could be of more than one coplanar ...
0
votes
0answers
27 views
Equal distribution based on multiple criteria algorithm
Let's say I have a database table that stores News records. Each News records will have a Category property. I would like to retrieve multiple News records and have an equal distribution of Category ...
0
votes
1answer
39 views
Make an array with sum of elements equal to a number k from an Vector of arrays
I have a vector with n arrays of integers (let's call it Arrays) and a number k. I must find a way to make a vector, let's call it Sol, with property that sum of all its elements is k and Sol[i] is ...
-2
votes
1answer
44 views
Space Complexity Analysis of Merge Sort (C++)
Since arrays are passed by reference in C++ does the space complexity of merge sort (recursive) still remain O(n) ? If yes then why?
(I argue that since elements of the array are not being copied so ...
4
votes
2answers
60 views
Smallest sum of triplet products where the middle element is removed using Dynamic Programming
I have given a sequence of N numbers (4 ≤ N ≤ 150). One index i (0 < i < N) is picked and multiplied with the left and the right number, in other words with i-1 and i+1. Then the i-th number is ...
0
votes
0answers
23 views
Goertzel Algorithm for IQ Data [on hold]
Does anyone know how to use this great single point FFT algorithm with a complex IQ tone?
My data consists of 4096 samples of I+Qj.
At the moment it works very well with either the I or Q data, but ...
-1
votes
1answer
24 views
Sobel Edge Detecting program in java
I am trying to write a sobel edge detecting program in java. But i am getting werid outputs. HELP. Here is my program.
import java.io.*;
import java.awt.*;
import javax.imageio.ImageIO;
import java....
-1
votes
1answer
22 views
Structured to do list with subheaders like “Today”, “Friday”, “Next Week”, “March” in JavaScript
I want to make a to do list in JavaScript which looks something like this:
NO DEADLINE
Be awesome
Live life
TODAY
Walk the dog
Buy food
Work out
THIS WEEK
Lorem
Ipsum
Dolor
NEXT WEEK
Dolor
Ipsum
...
0
votes
1answer
27 views
Clustering or Filtering points in WGS84 Coordinates
So I'm trying to solve a problem. I have a point which can be a player, and I have several objects around, some are farther some are near er. I want to exclude all points that are farther and include ...
0
votes
4answers
49 views
splitting tasks to categories
I have a class (lets call it checker) and diffrent kind of classes that execute tasks (lets call them tasks). each tasks belongs to several categories
each task runs and at some point asks checker if ...
-3
votes
0answers
44 views
Binary tree - breadth-first tree in c# [duplicate]
I have a problem with trees.
I want to create tree with more child, each node will have maximum 6 different child or minimum 0 child. This will be repeated until the condition stop loop. I have ...
-4
votes
1answer
67 views
Trying to find the number of x's that satisfies n + x = n ^ x fails with timeout
I'm trying to solve the following algorithm from the section Bit Manipulation at the Hacker Rank site using new features of Java 8 such as Streams.
The problem description:
Given an integer, n, ...
0
votes
1answer
45 views
Nth Tetrehedral number mod m? [on hold]
Hi i'm stuck on my assignment which partly requires me to find the nth tetrahedral number mod m. Tetrahedral numbers are the sum of the all the n previous triangle numbers and are denoted by the ...
0
votes
0answers
19 views
Are there any method which optimizes faster than grid search yet having greater than or equal accuracy to grid search
I am currently working on epsilon SVM with RBF kernel, and my program takes about 5-6 hours to optimize via grid search, which I think it is too slow,
So, as the title suggested, is there any search ...
0
votes
0answers
35 views
How to find the final savings from 5 different prices of a same product
I would like to know what is the formula to calculate the total savings of a product which has 5 different prices across 5 stores.
For instance, Product A price varies across stores in the market i.e....
0
votes
1answer
14 views
Applying solution for LCA in DAGs on cyclic graphs?
The answer to My question might be obvious, and I know that obvious answer on paper. I mean when it comes to some examples I understand why we aren't allowed to have loops to run the Lowest Common ...
0
votes
0answers
30 views
Calculating anti-aliasing on a grid of points
I'm representing an image by a list of integers representing the intensity of each pixel in an image. Each point is either 0 or 1. Given this data, how can I calculate the antialiased values so the ...
0
votes
1answer
17 views
Algorithm : Generate QuadKeys for different zoom
I want to know if there is an algorithm ready to use to generate quadkeys for different zoom.
A quadkey represents a unique picture in the globe and when we zoom in we split a quadkey into 4 other ...