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.
-3
votes
1answer
64 views
How to get the n if I know the result of 1+2+3+..+n=n*(n+1)/2?
If you know the result of 1+2+3+..+n, which is n*(n+1)/2.
For example, if the result is 5050, then I can know n is 100. How can I obtain the n. However, you can only calculate the n by only addition ...
0
votes
2answers
29 views
Maximum Subarray detection in Java using recurrsion
I am trying to implement the maximum subarray problem in Java using recursion but my code keeps throwing exception. I am unable to figure out what is causing the problem, I believe that this might be ...
0
votes
0answers
34 views
All possible partitions (clusters) of Tree
Let's say the tree has n vertices and n-1 edges. All nodes are connected. I want to divide the tree into parts, where each part must contain at least 2 vertices.
In how many possible ways I can do ...
-5
votes
0answers
33 views
Adapting algorithm to users taste [on hold]
I'm making a project in c++, and i need too know what optimizing algorithm to use to adapt to a number that a user inputs. Where would i start to do this? I have already tried to look this up but don'...
0
votes
1answer
17 views
How to Achieve a checkerboard pattern combining two lists of items
I have users and posts, and I wish to display them in a checkerboard pattern on a web page, like this (where P is Post and U is User):
P - U - P - U
U - P - U - P
P - U - P - U
U - P - U - P
...
0
votes
1answer
30 views
Find least colorful path in a graph
The problem i'm trying to solve is this:
Given a graph G = (V,E) such that every edge is colored in one of 10 colors, and two vertices: s, t.
I need to find an algorithm that produces a (shortest) ...
1
vote
2answers
33 views
Implement a method for ordered_vowel_words
I've been going over some of the many coding interview questions. I was wondering about implementing an ordered_vowel words method. I'm working on algorithm question to implement this method for ...
0
votes
1answer
32 views
Algorithm: How to find the number of solutions to SAT?
Assume that the number of variables N and the number of clauses K are equal. Find an algorithm that returns the number of different ways to satisfy the clauses.
I read that SAT is related to ...
2
votes
1answer
31 views
Is it possible to build a binary tree and keep track of the median, still with O(log(n)) insertion?
I'm trying to figure out whether this is possible.
My attempt at an algorithm:
m1,m2 are the middle 2 elements (If the size of the tree is odd, then m1=m2).
Here's what building the tree might ...
-4
votes
0answers
23 views
How will I solve this Microsoft Internship coding test Q?
Input: Sorted array of size ’n’ and an integer ‘k’.
Required Output: Of all possible sub-sequences of the input array of size ‘k’, output the subsequence of size ‘k’ in which the minimum difference ...
0
votes
1answer
13 views
Effectively immutable array-backed sequence with linear concatenation and appending
Probably most courses of algorithm and data structures include a growable array buffer with amortized cost O(1) for appending an element by growing the underlying array by a factor. In imperative ...
1
vote
0answers
20 views
Find All the Pairs of Node having a required sum
I am giving a Graph G and having E numbers of weighted edges , I have to find the all the pairs of nodes (x,y) such that sum of edges between path x and y ends with digit {0,1,2,3,4,5,6}
We ...
-3
votes
0answers
20 views
Sorting with O(nloglog(n)) expected time with flip operation?
Given an array of positive and negative integers, design an algorithm that sort the array such that the positive elements are in front of the negative elements. The only operation allowed is a flip ...
2
votes
2answers
42 views
Can dynamic programming be used with recursion?
I understand why DP is more efficient over than simple recursion.
However, I understood that DP is recursion using memoization technique.
For Fibonacci, like this :
int DP[10000]; //initalized by ...
1
vote
1answer
20 views
Sprites sequence control through DeltaTime
Previously in my main loop of the game, the time was managed at 60 FPS and the respective Delay for the time delay.
The Sprite sequence was animated as follows:
<pre>
if(++ciclos > 10){
...
-1
votes
0answers
19 views
Multilayer Perceptron algorithm [on hold]
I try to make program to find a set of weights and biases for the network.
Here is the architecture of network.
And all of the hidden units and the output unit use a hard threshold activation ...
-1
votes
0answers
10 views
Adding numbers open kattis
The code is failing on the second test case the website does not give
us what the test cases are after first one this is the link
https://open.kattis.com/problems/addingwords . At the second test ...
0
votes
0answers
9 views
MC/DC Unique-Clause Coverage Confusion
I've recently been reading a paper (http://ieeexplore.ieee.org/document/7356490/ (below image can also be found here)) that discusses a number of techniques for generating MC/DC test cases. One such ...
2
votes
2answers
44 views
How do I write the code for dividing an even number with biggest equal odd numbers
I have a set of numbers to check. if the number is even, the program will check the biggest odd dividers of it which are equal. For example, if the number is 12, program will return an array like [3,3,...
2
votes
1answer
39 views
The greatest sum in part of matrix array
I am stuck at a simple problem, I am looking for a better solution than my.
I have an integers matrix array (tab[N][M]) and integer (k) and I have to find the smallest rectangle (sub matrix array) ...
0
votes
1answer
11 views
Primitive operation for nested for loop
I am confused in how to calculate total number of primitive operation.
I did this by my own but this is not correct.
for (i: 1 to n) --------- n
for (j: 1 to i) -------- n ( i - 1 )
for (...
0
votes
2answers
44 views
Simple inquiry: Does SortedSet<T> have an easy way of finding the median element?
Looking at the documentation on https://msdn.microsoft.com/en-us/library/dd412070(v=vs.110).aspx and I don't see a way. Ideally I would like to be able to find the median (middle element or sum of ...
1
vote
0answers
30 views
Minimum rounds for rebalancing laundry
I am looking for linear time algorithm for the below Laundry assignment.
There are N machines in a laundry. They have infinite capacity. Now a truck of cloths is unloaded for washing and randomly ...
-1
votes
1answer
38 views
CUDA: cascaded summation of all vector elements
I have implemented a cascaded addition function for a large vector of float values on my GPU and my CPU. That simply means that all elements of this vector shell be summed up into one result. The CPU ...
0
votes
2answers
106 views
Does C#.NET have any data structure that satisfies the following properties?
I'm trying to solve a problem and I realized that the complexity of my solution was higher than anticipated due to the fact that Insert for List<T> is O(n) (source: https://msdn.microsoft.com/en-...
0
votes
2answers
41 views
Writing own kmeans algorithm in R
I am trying to write my first own kmeans algorithm in R. I am new in this field, so please don't judge me for don't seeing the obvious.
In its current state, the algorithm takes two vectors x, y, ...
0
votes
2answers
64 views
Array[0] is changing while entering the “for” loop, can't figure out why
I'm doing a challenge on HackerRank got the method figured out but there's a slight error I cannot figure out. Further information if needed is https://www.hackerrank.com/challenges/sparse-arrays
...
-2
votes
1answer
19 views
How to calculate the required time for this algorithm? [on hold]
How much time does an algorithm take to solve a problem of size n if this algorithm uses 2*n^2+2^n bit operations, each requiring 10^(-9) second with the following values of n? n=10, n=20, n=50 and n=...
-5
votes
0answers
54 views
Needing help for recursive function [on hold]
I'm working on a basic application to calculate mathematic functions.
The iterative version was rather slow, and I had a more efficient recursive algorithm in mind, but it does not work as expected
I ...
0
votes
1answer
39 views
Non-recursive 0/1 Knapsack algorithm using Breadth-first Search
I came across an interesting problem called Knapsack. You have a list of items, which all have a value and a weight. Then you have to find the combination of items that maximize the value of the ...
1
vote
1answer
67 views
Algorithm: How to find the number of independent sets in a tree?
I'm thinking that there are two cases for each sub-tree: the root is in the independent set and the root is not in the set. How to write a recursive algorithm for finding the number of independent ...
0
votes
0answers
53 views
Arrange strings in alphabetical order
//code with problem (maybe)
numberArray = NameNumEquv;
listStringArray = NamesArray;
string[] sortedArray = new string[NamesArray.Length];
for (int arrayItemCounter = ...
1
vote
3answers
70 views
Proving Big O notation
Prove 5n^2+ 2n -1 = O(n^2).
This is what I have attempted so far:
5n^2 + 2n -1 <= 5n^2 + 2n^2 -n2 for n>1
5n^2+ 2n -1 <= 6n^2 for n>1
5n^2+ 2n -1 = O(n^2) [ c = 6n^2, n0 = 1 ]...
3
votes
2answers
68 views
Fastest way to compute (n + 1)^j from (n^j)
I need to compute 0^j, 1^j, ..., k^j for some very large k and j (both in the order of a few millions). I am using GMP to handle the big integer numbers (yes, I need integer numbers as I need full ...
0
votes
1answer
33 views
Worst case complexity for this python code
What is the worst case time complexity of the following:
def fun(n):
count=0
i=n
while i>0:
for j in range(0,i):
count+=1
i/=2
return count
-3
votes
0answers
23 views
Which Algorithm to use in WEKA
I want to classify data in WEKA. I am a beginner. The data consists of the 10101 64bits pattern and a class_label. Which algorithm shall I use?
I have 64 elements in one row of (0,1 series) and one ...
1
vote
1answer
99 views
C# has no SortedList<T>?
I'm trying to solve a problem in which it would be useful to have a data structure like
var list = new SortedList<int>();
list.Add(3); // list = { 3 }
list.Add(1); // list = { 1, 3 }
list....
0
votes
0answers
54 views
Maximum difference between two indices of the same number [on hold]
I have recently applied for a job, and the online test was composed of a problem similar to the following (The test has ended) :-
Given an array of numbers, find the maximum difference between two
...
0
votes
2answers
41 views
Trouble implementing a counting sort algorithm
I'm trying to teach myself a few sorting algorithms in python and I'm having a little bit of trouble with the output. I'm attempting to implement a counting sort algorithm and I've gotten this far:
...
0
votes
1answer
28 views
How to detect the precise sampling interval from samples stored in a database?
A hardware sensor is sampled precisely (precise period of sampling) using a real-time unit. However, the time value is not sent to the database together with the sampled value. Instead, time of ...
1
vote
0answers
23 views
high-level algorithm for converting RSA public keys from JWK to PEM
I'm writing an nginx module in LUA and I'm finding very sparse documentation on a specific topic. I need to convert an RSA public key stored in JWK format to PEM. I need to do this almost entirely ...
2
votes
3answers
59 views
Why is the maximum sum subarray brute force O(n^2)?
The maximum subarray sum is famous problem in computer science.
There are at least two solutions:
Brute force, find all the possible sub arrays and find the maximum.
Use a variation of Karanes ...
2
votes
1answer
33 views
Is it possible to find the closest point to all points in subquadratic time?
An algorithmic question.
Input:
A list of data points X
A metric function for data points dist(x,y) that takes O(1) time to evaluate and obeys the triangle inequality
Is there an algorithm that can ...
5
votes
1answer
156 views
Big-O analysis of two algorithms
I created two solutions for leetcode problem 17 in which it asks you to generate all possible text strings from a phone number combination, e.g. "3" results in ["d","e","f"].
My first solution uses ...
-1
votes
1answer
51 views
Colouring a tree with two colour
I am having a tree and i want to color each node black or white. A tree is said to be valid colored if For every node N there exist at least One neighbor with the same color as of N
My Approach:
let ...
-1
votes
0answers
13 views
Job scheduling at specified intervals with constraints on how much a job can move [on hold]
Suppose I have items of type y_1,...,y_n which need to be inspected every x_1,...,x_n days. That means that the first inspection for item j occurs after x_j days, the second inspection at 2*x_j, etc. ...
1
vote
1answer
25 views
Smallest cost in weighted directed graph with combinations
I am trying to develop an algorithm that can traverse a graph with intermediary/all or nothing(?) nodes.
The problem is that there are companies B, C and D that are bidding on projects X, Y and Z. ...
0
votes
0answers
40 views
Is it possible to create an algorithm for the Control Room Riddle? [on hold]
I have been banging my head against the wall trying to create an algorithm to solve this riddle. I can solve it with a piece of paper and pen, but I'm not seeing an easy way to create an algorithm to ...
0
votes
1answer
39 views
Quasi-Simple computation in program
I did not know whether I should post this in mathSE or stackoverflow, but since it involves code and some basic algorithms I went for SO.
My question comes from a program that I have to do based on ...
-5
votes
0answers
30 views
merge two containers of same type [duplicate]
I want to merge two containers of the same type.
this is the structure of the classes. im getting the following error:
/cygdrive/C/Users/USER/AppData/Roaming/NetBeans/8.1/bin/nativeexecution/...