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
18 views
How to Traverse a N-Ary Tree
My Tree/Node Class:
import java.util.ArrayList;
import java.util.List;
public class Node<T> {
private T data;
private List<Node<T>> children;
private Node<T> ...
2
votes
0answers
14 views
I want to calculate the difference between two values in a “distance_table = []” with permutations, how can I use permutations correctly in this case?
I want to calculate the difference between two values in a distancetable which is read in from a file, a csv file with a number of cities with distances between them. In the .csv-file I have the first ...
1
vote
0answers
12 views
Matching data based on multiple parameters and certain limits
I've been looking into the k-nearest neighbors algorithm as I might be developing an application that matches boxers in the near future.
The reason my for question, is to figure out which would be ...
1
vote
2answers
20 views
Sorting multimap with both keys and values
I am tryin to sort a multimap that have set of pairs in it using standard sort function by writing a compare function for it, but I am getting some error in it. I am trying to sort the map with values ...
0
votes
0answers
8 views
Quickselect vs “keeping track” to find second smallest element?
I recently had a tech interview with a big company where one of the questions was "design an algorithm to determine the second smallest element of an array."
Immediately I said "Oh, let's just do a ...
3
votes
1answer
45 views
Recursive(?) algorithm design
I have a requirement to allow my end users to input formula much like a spreadsheet. I have an array like this:
$table = array(
1=>array(
"id"=>1,
...
4
votes
0answers
19 views
Randomly Select a Node from N-ary Tree
My Node Class:
import java.util.ArrayList;
public class Tree<T> {
private Node<T> root;
public Tree(Node<T> root) {
this.root = root;
}
public boolean ...
0
votes
0answers
16 views
Voronoi cells algorithm can return the same value twice?
Can voronoi algorithm can return the exact same value for two differents cells even very far away from each other ?
I don't think that depends on the implementation but here is the code I use.
2
votes
1answer
71 views
Queries on Array
You are given an array of N positive integers, A1,A2,…,An. You have to answer Q queries. Each query consists of two integers L and K. For each query I have to tell the Kth element which is larger than ...
1
vote
2answers
22 views
Using an insertion sort algorithm using more than one field from an array of objects
I have to sort an array with state objects and sort it by region number, and population. I have imported this information from a text file so these are strings. I can sort using one of the fields ...
0
votes
1answer
15 views
How to solve equations using asymptotic notations?
I'm stuck on whether or not the asymptotic notations (options 1-5) are correct or not.
The big-O notation rule I got (from a YouTube video) was that for O(f(n)) is the set of all functions with ...
3
votes
3answers
77 views
What is the runtime complexity (big O) of the following pseudocode?
I recently had a very, very intense debate about the runtime complexity of a super simple algorithm with a colleague of mine. In the end we both agreed to disagree but as I've been thinking about ...
-1
votes
0answers
18 views
Count comparisons and swaps in HeapSort in Java
I searched a little and couldn't find a reliable answer for HeapSort, but QuickSort. Below is a code snippet and I want to know where comparisons and swaps counters should be calculated.
How can I ...
-3
votes
1answer
43 views
Fastest algorithm for finding the number which occurs the most without sorting?
Hello I am working on an assignment and I have to find the fastest algorithm to find the number which occurs the most. I am not allowed to sort or use hash-table mappings. The array I am working with ...
-1
votes
1answer
18 views
Big-Theta(Θ) of the recursive function g(N) = (1/c)g(N/2)
I'm trying to analyse the recursive function g(N) = (1/c)g(N/2), for N >= 2, with the terminating case being g(1) = 1, and then find the big-theta bounding it. Bare in mind, this problem treats n as ...
0
votes
1answer
37 views
How to divide a set into K subsets such that the sum of the elements in the subsets are minimal?
I'm studying DP and this problem came up to me when I was reading the Balanced Partition algorithm. In this algorithm we can divide a list in two lists such the sum of the elements of these lists are ...
-4
votes
3answers
61 views
Max Sum Of Integers
Here is the challenge description: https://www.codeeval.com/open_challenges/17/
I keep getting a partially solved score. I want to know why. As in my eyes, this code works. And I believe that it is ...
-1
votes
2answers
30 views
Tree Walks With Weighted Nodes
Given a tree, where the nodes have a value(can be negative), find the path that maximizes the sum of nodes in the path.
I have tried using to get a solution using Dynamic programming techniques, but ...
0
votes
1answer
36 views
Traversal of cities - is this case missing from the solution?
Warning: this question requires some initial effort to be understood
This question is not exactly a duplicate of dynamic programming : traversal of cities. Let's suppose I have the following graph ...
0
votes
0answers
21 views
QuickSort - Pivot Selection , Random Element Vs. Random Index
I have an array of size n which contains number from 1 to 10 ( floating point numbers included). Which strategy is better to pick up a pivot for Quicksort:
Picking a random element between 1 and 10.
...
0
votes
0answers
25 views
Fastest algorithm to determine if matrix has maximum rank
What is the fastest algorithm to determine if an N x N matrix has rank N?
In my case, I need an algorithm that is optimal for N around the order of 30. Is there any better way than computing the ...
0
votes
1answer
21 views
Why is Topological Sorting to find the shortest path O(V+E)
I am confused to why topological sorting for shortest path is Big-O of O(V+E).
Here is the algorithm:
1. Topologically sort G into L;
2. Set the distance to the source to 0;
3. Set the distances to ...
-1
votes
3answers
50 views
Determine if two rectangles are overlapping
I am working on an algorithm problem to try to determine whether two rectangles overlap with each other.
Assume L1 and R1 are the top-left and bottom-right of the first rectangle, and L2 and R2 as ...
1
vote
6answers
72 views
Python: Choose random line from file, then delete that line
I'm new to Python (in that I learned it through a CodeAcademy course) and could use some help with figuring this out.
I have a file, 'TestingDeleteLines.txt', that's about 300 lines of text. Right ...
4
votes
2answers
28 views
TI-84 Plus Random Number Generator Algorithm
Edit: my main question is that I want to replicate the TI-84 plus RNG algorithm on my computer, so I can write it in a language like Javascript or Lua, to test it faster.
I tried using an emulator, ...
-1
votes
1answer
29 views
How to find if number 2^n is in sum of 2^1 - 2^m
Let's say that in some system users' statuses are assigned to a numbers that are a powers of 2.
1 - New Member
2 - Member
4 - Friend
8 - VIP
16 - Admin
32 - System Owner
So if System Owner got ...
0
votes
1answer
24 views
Where is the flaw in my implementing a firstOrDefault function in Javascript?
I'm trying to practice my Javascript chops and am trying to figure out the flaw in my attempted implementation of a firstOrDefault function like exists in C#.
HTML:
<div ...
1
vote
3answers
41 views
PHP Getting all unique board results for poker
I am currently trying to make a poker algorithm that determines the chance of winning a hand. It needs to be extremely fast because it will have to loop through hundreds of thousands of different ...
0
votes
1answer
16 views
Implementing Neville's Algorithm in MatLab
I'm attempting to implement Neville's algorithm in MatLab with four given points in this case. However, I'm a little stuck at the moment.
This is my script so far:
% Neville's Method
% Function ...
0
votes
0answers
22 views
Zhang-Suen thinning algorithm implementation
I have troubles with this kind of images in my implementation of ZS alghorithm:
........
.xx.....
..xx....
...xx...
....xx..
.....xx.
......x.
........
from description of ...
5
votes
1answer
42 views
Finding the intersection of two arrays in Javascript [duplicate]
This was an Amazon interview question I had an my answer was
function intersection ( A , B )
{
var C = [];
for ( var a in A ) if ( B.indexOf(a) != -1 ) C.push(a);
return C;
}
and he ...
0
votes
1answer
48 views
HackerRank The Maximum SubArray
So I am attempting to go through the Dynamic Programming track on HackerRank.
Problem prompt is as follows.
Given an array A={a1,a2,…,aN} of N elements, find the maximum possible sum of a
...
0
votes
0answers
31 views
Function to place x in a list
I'm trying to make a function.
There is a doubly linked list where the list (A) of integers is sorted, has been split into 3 pieces where squareroot of n is the number of pieces it has been split into
...
0
votes
0answers
11 views
what is the learning process of recurrent temporal restricted machine (RTRBM)?
RTRBM is a propababilistic graph model. It can be modeled for sequential data,such as videos. Recently, I focus on such model. But, I don't know how to get the gradients of the parameter about the log ...
1
vote
1answer
29 views
Random Tree in Racket
I am trying to create a random tree from lists in Racket.
The tree is made from a list of operators and a list of terminals.
The output will look like this:
'(* (+ 2 4) 2)
So the list can be ...
-1
votes
0answers
51 views
Need a way for real-time scoring 100000 items based on 30 criteria [on hold]
I want to build recommendation website for choosing most suitable City for living.
I have plenty of data sources, for example:
National parks:
╔═══════╦══════════════════╗
║ City ║ Distance, ...
5
votes
1answer
97 views
How to Union two collections efficiently?
I have the following algorithms to find union of two collections.
IEnumerable<IGroup> labelGroups = _agents.Where(x => settings.LabelIds.Contains(x.Id));
IEnumerable<Guid>labelAgentIds ...
0
votes
1answer
34 views
Dijkstra's algorithm implementation for undirected cyclic graphs without priority queues
How can i implement the Dijkstra using only queues instead of priority queues
.Is this possible ? if not,why ? This is My Code in java.. whats my mistake ?
"S" is the starting node "W" is the weight ...
-1
votes
0answers
51 views
Luis Torgo - Case Study, Wrong function
I am doing Luis Torgo Case study - Predicting Stock Market Returns
and I have a problem when I use the function trading.simulator in the package DMwR
t2 <- ...
0
votes
1answer
52 views
What is the most efficient way to find union of two collections?
public IEnumerable<SummaryItem> GetSummaryData(SummarySettings settings)
{
return GetSummaryReportData(startTime, endTime, settings.AgentIds);
}
After I wrote my code I realized that I need ...
3
votes
2answers
32 views
manipulate bytes down to binary levels in python
I am trying to start learning about writing encryption algorithms, so while using python I am trying to manipulate data down to a binary level so I can add bits to the end of data as well as ...
-3
votes
0answers
22 views
Minimum distance of a node in tree where more source nodes are added in queries
N=10^5 nodes and E = n-1 edges in a tree.there are Q = 10^5 queries.
Initially node 1 is source node.
source set = { 1 } where distance d = 0.
in each query two integer : type V
two type of queries ...
-2
votes
1answer
28 views
Count total subsequences whose sum is divisible by k
I am trying to write a DP solution for the problem: count total number of sub-sequences possible of an array whose elements' sum is divisible by k.
I have written the following solution. But it is ...
1
vote
1answer
23 views
Constrain connection/rope/line to avoid stretching
We've been developing a game (2d) in which an object can be connected to static points. Each connection (which is a rope in our case) has a fixed length which can be changed (only one at the time). ...
0
votes
1answer
93 views
Insert a linked list to a linked list
I wrote this function that inserts another linked list to the existing linked list. The output is correct when I print out the value of "this" object in the function. However, the program encounters ...
-1
votes
2answers
27 views
Find all permitation for list or word list in very long text
Given the word list = { w1,w2,w3,w1,w2 }
Find all permutations of above word list in long text.
long text list = {This is long text w1 w2 w3 w4 and w1 w2 w1 w2 w3. This yet another long text ...
1
vote
1answer
40 views
How to optimize my Langford Sequence function?
This is my code for making a Langford Sequence out of an array of pairs of numbers (112233 -> 312132). I wanted to write a recursive function, because I wasn't able to find one online anywhere as a ...
2
votes
1answer
43 views
how to fetch content in web crawling
Hi! I am trying to implement this pseudocode for spider algorithm for exploring the web.
Need some idea for my next step of pseudocode : "use SpiderLeg to fetch content" ,
i have a method in ...
1
vote
1answer
52 views
Fitting a rectangle inbetween existing, non-overlapping rectangles
I have a problem that can perhaps best be illustrated with windows on a computer screen: create another window, as large as possible, not overlapping any of the existing windows.
In other words: ...
0
votes
2answers
40 views
NIM game and AI player using Minimax algorithm - AI makes losing moves
I've got an assignment to write a NIM game with a human player and an AI player. The game is played "Misere" (last one that has to pick a stick loses). The AI is supposed to be using the Minimax ...