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.
0
votes
1answer
20 views
How can I input text from a web page and apply enctyption algorithm written in Javascript to text and output it?
Hello everybody,
First of all, I am building a web page in which a game (which I'll create) will be incorporated, and I'm trying to learn how to take input from a page and apply to that text a ...
-1
votes
0answers
4 views
Codingbat Logic-2 > roundSum answer is not very optimise
It looks like I have answered the question here correctly: http://codingbat.com/prob/p186753
But my code seems too long to me and not very optimised. Can anyone suggest what can I do to make my code ...
3
votes
2answers
39 views
run for random numbers and keep state
I use the following code to get random value from specifed range
var provideRanges = function(){
var aa = [];
_.times(3, function(i) {
console.log(i);
let num = _.random(10, 20)
...
0
votes
0answers
27 views
Kmeans in C++ vs Kmeans in Python [on hold]
I'm working on a dataset of 30,000 points having 4096 dimensions of integers. I have to use this dataset to run k-means for k=100, 500 and 1000. The current code that I have is in matlab, and takes ...
-1
votes
0answers
8 views
Developing a car sharing scheme website
I am in my final year of university and i'm doing a computing project which i need some advice/help on as i am not the most confident in coding.
there are already some website that exist similar to ...
2
votes
1answer
21 views
Java Tree Data Structure Implementation
Can someone point me to the standard, tested, simple Tree implementation in Java?
For example, all StackOverflow searches on Java Trees lead to this topic,
Tree implementation in Java (root, parents ...
0
votes
3answers
33 views
Program to find pairs in array that XOR to a given value
I am given an array and a value x.
Input example:
2 3
1 2
Where n (length of array) = 2, the value x = 3, and the next line (1, 2) contains the values in the array. I have to find the pairs of ...
0
votes
0answers
9 views
Permuting Entries in main Diagonal
If i have 8*8 matrix. Having the following values
Want it to permute like following
Such that diagonal is divided into two part Top and Bottom. First entry 1 is filled at first location of Bottom ...
2
votes
1answer
19 views
Adapting matrix array multiplication to use Numpy Tensordot
I'm trying to speed up my code to perform some numerical calculations where I need to multiply 3 matrices with an array. The structure of the problem is the following:
The array as a shape of (N, 10)
...
0
votes
0answers
57 views
Can't figure out the QuickSort Algorithm [on hold]
I've read like 3-4 different articles (each having few pages, maybe more) about QuickSort but I still can't figure out how to implement it, even if I understood the idea behind it. What am I doing ...
-1
votes
2answers
63 views
Refresh the list data while iterating over it in java
I want to refresh/change the data contained in ArrayList while iterating over it.
Here is what I have written :
List<Message> msgList = getList();
if (msgList != null && msgList.size(...
0
votes
3answers
44 views
What is the benefit of using a stack versus just a doubly linked list
As an assignment, I have to implement quicksort iteratively rather than recursively. In doing this, I need to use stacks. What is the benefit of using stacks in this scenario versus just a singly or ...
2
votes
1answer
37 views
Choose rectangles for maximizing the area
I've got a 2D-binary matrix of arbitrary size. I want to find a set of rectangles in this matrix, showing a maximum area. The constraints are:
Rectangles may only cover "0"-fields in the matrix and ...
1
vote
2answers
44 views
Possible paths of NxN array traversing from (0, 0) to (N, N) in a positive direction only?
We have an NxN array. I have got the solution to finding out the number of possible paths moving from (0,0) to (N,N) in a positive direction only. You can not move diagonally or backwards.
And the ...
-3
votes
0answers
19 views
I want to store data of flights routes in hash tables how is this possible? [on hold]
I am making a project in which i am using hash-tags data-structures. How to retrieve data from hash-tags
0
votes
1answer
43 views
Matrix Inverse in Swift
Actually I am trying to implement PageRank Algorithm in Swift. I am using Swix and Accelerate framework.Actually for getting the pageRank I need to solve Linear Equation.I am trying to do this by ...
-3
votes
0answers
32 views
In how many ways can you factorize n! into two numbers such that they have different parities? [on hold]
In how many ways can you factorize n! into two numbers such that they have different parities? 1<=n<=10^9.This is a sub-problem to a question I am stuck here.Please help.
-1
votes
0answers
9 views
how to make hybrid scheduling based on dynamic priority on hadoop?
I'm doing research on hadoop, but I am a little confused about the scheduling algorithm. I want to ask about hadoop scheduler. According to this paper "A Hybrid Scheduling Algorithm for Data Intensive ...
0
votes
0answers
30 views
Explanation of FIFO algorithm in cache memory
I am writting a C program to read the memory and calculate the miss rates in the memory. I have to use the Write Through technique along with the FIFO algorithm... Actually I am stuck with using the ...
2
votes
1answer
42 views
Shortest path between 2 co-ordinates, through set of co-ordinates - Javascript
I need to write a JavaScript algorithm to find the shortest path between 2 co-ordinates. I have looked at using a few route finding algorithms, such as the A* algorithm.
The difference in my ...
0
votes
2answers
29 views
Why is my Seive of Eratosthenes Algorithm implementation running into infinite loop?
I was implementing Sieve's Algorithm for finding Prime Numbers up to n. I am unable to find out why is it running into infinite loop.
Here I'm giving the code snippet. Please help.
for(int j=2;j<...
-3
votes
0answers
24 views
Algorithm to convert 4 letters to 4 digit number and reverse
I am looking for algorithm for converting 4 letters to 4 digit number and reverse. For example, if string is "A2BQ", I should be able to get 4 digit number and with reverse algorithm I should be able ...
0
votes
2answers
33 views
Reduce array by adding elements
I came across this question in a test.
Given an array, reduce the array to a single element with minimum cost. For reducing, remove two elements from the array, add those two numbers and keep the sum ...
0
votes
0answers
36 views
Reverse a subsequence resulting in no negative partial sums
Given an array of numbers, I need to find the indices of a continuous subsequence such that after reversing it in the original sequence, no prefix sum is negative. If there are multiple answers, the ...
0
votes
1answer
35 views
Calculating the number of perfect squares, perfect cubes,etc in a given range?
I know that we can use the formula math.floor(b**(1.0/i))-math.ceil(a**(1.0/i))+1
to calculate the number of squares in a given range, Does it hold when I want to find the number of perfect cubes,etc?
...
0
votes
2answers
22 views
Time Complexity of 3 sum
I have provided a snippet of the code for solving the 3 sum problem below.
int N = 10;
for (int i = 0; i < N; i++)// this line gets executed N times
for (int j = i+1; j < N; j++)/...
-1
votes
0answers
11 views
extract value from a matrix based on some constraint
I have a Nx2 matrix (call it A) and a number K. I need to find the row such that the value in the first column is maximum and the value in the second column is < K
i.e. Maxi A[i,1] s.t. A[i,2] <...
1
vote
1answer
21 views
Algorithms to backtrack the usage and dependencies of a variable
I'm extending LLVM for experiments. Therefore, I want to track a variable usage and its dependencies.
For example after finding a conditional branch which is caused by a comparison of two operands, ...
-3
votes
0answers
8 views
php time managment : fill slot time
I'm working on a time managment problem. I would like to sort tasks and find the best organization for my
planning.
Here is the problem. In a day I have two time slots of 4 hours each. in the ...
1
vote
1answer
28 views
override function push in Scala
The problem is from cracking-coding-interview, problem 3.2
Stack Min: How would you design a stack which, in addition to push
and pop, has a function min which returns the minimum element? Push,
...
0
votes
0answers
15 views
Judgecode — Sort with swap (3)
http://judgecode.com/problems/1012
Given a permutation of integers from 0 to n - 1, sorting them is easy. But what if you can only swap 0 with any other integer in each operation.?
Please calculate ...
2
votes
1answer
38 views
Printing values using loop
How can print following values using loop.
Basically i am taking size of array and adding first entry to middle of array if array is of size odd. If it is of even then taking first entry to below to ...
1
vote
1answer
36 views
Finding a pair with a given sum in a sorted array - is there a correctness proof?
I saw the 2 pointer algorithm in dozens of posts, i.e:
l = 0;
r = n - 1;
while (l < r)
sum = A[l] + A[r];
if (sum == expected) return true;
elif (sum < expected) l++;
else r--;
...
-1
votes
0answers
14 views
Dynamic programming to find maximum number of plots inside a rectangle
We have a rectangle R with sides: a,b (parallel to coordinate system) and a set P of points inside that rectangle (integers). A plot in the rectangle is a rectangle D:
1) that is inside of the ...
0
votes
0answers
7 views
Looking for solutions to SOP [on hold]
I am looking for a solution to Sequential ordering problem.
Does anyone have an easy solution for SOP. I have read some papers but the solutions that they present are rather extensive or difficult to ...
0
votes
1answer
49 views
How to generate non-guessable numerical ID in python [on hold]
I've been reading articles all day to find a way to generate non-guessable numerical ID.So auto increment id is not a good way for me,and also UUID is not suitable for me.Because I need a friendly id ...
-2
votes
2answers
53 views
Java if statement doesn't work with this situation? [duplicate]
I'm trying out a few contest problems and of course, rushing through them without logic to see my fastest time. However, this is the one I just can't get to work...
import java.util.ArrayList;
...
2
votes
0answers
15 views
Pseudo code for a greedy algorithm for the influence maximization under the independent cascade mode
I understand the concept behind a greedy algorithm but am still confused about the influence maximization under the independent cascade model and how I would implement the greedy algorithm.
read in ...
0
votes
0answers
44 views
Reduce time complexity from n^3 for following:
<?xml version="1.0" encoding="UTF-8"?>
<Module name="Data">
<Group name="PAR">
<HEALTHSTATUS>OK</HEALTHSTATUS>
</Group>
<Group name="SYSTEM">
...
-3
votes
1answer
41 views
Algorithm to find all sundays on given a range year
how to find all sundays from given date between march 2016 - march 2018. with looping, there are 3 loops : looping for year, month, and date, then use if.
But im confuse about looping. can you help me ...
1
vote
1answer
26 views
Simple ordering for a linked list
I want to create a doubly linked list with an order sequence (an integer attribute) such that sorting by the order sequence could create an array that would effectively be equivalent to the linked ...
1
vote
0answers
19 views
azure sql database intelligent search algorithm suggestions needed
I have a sql database in Azure. The search algorithm would proceed more or less as follows:
It would consider a text field in Table_A, Field_A1, which contains a varying amount of text (nvarchar(max)...
2
votes
0answers
40 views
spimi algorithm misunderstanding
I'm trying to implement a single-pass in-memory indexer in C++
But in the algorithm, I think there is something wrong or ( most probably) I have misunderstanding
SPIMI-INVERT(token_stream)
...
-2
votes
0answers
43 views
How to create a sequence of integers in Java with each digit occuring equally often without triples? [on hold]
I need to create a large random sequence of integers (0-9). With large I mean longer than 300. And I need every number from 0 to 9 to occur exactly 30 times.
Now I want to avoid that a number appears ...
1
vote
1answer
44 views
How to approach routing path with Dynamic Programming
there is N x N sized array filled with random number (-100 <= x <= 100)
starting from A[0][0],
it moves to adjacent indices by stages.
Restriction.
Can't move to visited index.
Can't go ...
0
votes
1answer
26 views
Does minimax count as ai functionality in a tic tac toe game?
I was under the impression that it did, as I was told to write a tic tac toe program using minimax, however, I'm not 100% sure that's the case now. Is minimax more of a brute force approach or does it ...
-2
votes
1answer
24 views
Python, aim of this algorithm about binary?
I'm working on past exams in my school about algorithms, and i fond this one,
but I do not understand the meaning of the returned value. Without k and the while, i understand that is the sum of ...
-1
votes
0answers
19 views
representation of flow network
I wanted to know how in the Goldbergs implementation(HIPR) of the push relabel algorithm the flow network is represented. Unfortunately my C is not as good as it should be to understand the code.
Here ...
1
vote
1answer
39 views
Detect self intersection of a polygon with n sides?
I am using Google Maps SDK to allow a user to draw a polygon on the map by tapping. Everything works perfectly is the user is to draw a polygon following a path and continues on that path without ...
-1
votes
0answers
18 views
Squash game function
How can I ensure that the difference between points a and points b has to be 2. This follows the rules of the PARS squash game, where you have to win by 2 clear.
import random
def game(ra, rb):
...