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.

learn more… | top users | synonyms (2)

0
votes
0answers
4 views

Excel VBA How to make code more efficient and take less time

I have the following code below. I would like advice and suggestions on how it can be improved / rewrote to minimize; 1) Time taken 2) Number of operations Presume all variables in code can be very ...
0
votes
1answer
17 views

Building MST from a graph with “very few” edges in linear time

I was at an interview and interviewer asked me a question: We have a graph G(V,E), we can find MST using prim's or kruskal algorithm. But these algorithms do not take into the account that there are "...
0
votes
0answers
10 views

Linearly reading a multi-dimensional array obeying dimensional sub-sectioning

I have an API for reading multi-dimensional variables that has a read method. For simplicity, I define these in a pseudo-Scala language here, but the question is really about the algorithm not the ...
2
votes
1answer
24 views

Preferred Sequence Algorithm in T-SQL

EXPLANATION I'm using SQL Server 2012. I need to write algorithm to decide sequence of producing products depending on their setup times. What I mean: for example we need to produce 4 products: A B ...
29
votes
4answers
26k views

What exactly is augmenting path?

When talking about computing network flows, the Algorithm Design Manual says: Traditional network flow algorithms are based on the idea of augmenting paths, and repeatedly finding a path of ...
4
votes
5answers
74 views

What is the best algorithm to solve this puzzle?

So I came across this question: How many numbers are there from 1 to 1000 which are not divisible by the digits 2, 3 and 5? It seems pretty easy at first, so I wrote a quick python program to solve ...
0
votes
0answers
12 views

Reader-writer lock

I just read deeply the example of second reader writers problem- prefering writers over readers, mentioned here. I have a very specific question regarding the solution implementation mentioned there. ...
0
votes
0answers
16 views

Searching if trie set is contained in a word

Say I have 2 sets: Set A: ['hi, 'there', 'hire', 'hih', 'hih543'] Set B: ['hihow', 'himan, 'fsdko45'] Now, these sets in reality each contain close to million elements each. What I need to do in a ...
1
vote
3answers
504 views

Questions about heaps in coursera's open course

Here are two questions that I got the wrong answer but I don't know why. 1.Suppose you implement the functionality of a priority queue using a sorted array (e.g., from biggest to smallest). What is ...
-1
votes
4answers
66 views

What is the best way to find the first occurrence of an item in a collection and update it

I have a collection in Javascript/Typescript [ {"order":1,"step":"abc:","status":true}, {"order":2,"step":"xyz","status":true}, {"order":3,"step":"dec","status":false}, {"order":4,"step":"pqr","...
0
votes
0answers
9 views

Getting wrong amount of addition impressions on Bayesian Networks enumeration method for three hiddens

I got an assigment to count how many times we use addition and multipication in Basyen Networks with different methods. I have a Problem with the simplest method the enumeration method. Here on slide ...
0
votes
3answers
34 views

Find element of an array that appears only once in O(logn) time

Given an array A with all elements appearing twice except one element which appears only once. How do we find the element which appears only once in O(logn) time? Let's discuss two cases. Array is ...
4
votes
3answers
1k views

FPGrowth Algorithm in Spark

I am trying to run an example of the FPGrowth algorithm in Spark, however, I am coming across an error. This is my code: import org.apache.spark.rdd.RDD import org.apache.spark.mllib.fpm.{FPGrowth, ...
21
votes
2answers
13k views

Reason for 5381 number in DJB hash function?

Can anyone tell me why the number 5381 is used in DJB hash function ? DJB Hash function is h(0) = 5381 h(i) = 33 * h(i-1) ^ str[i] A c program: unsigned int DJBHash(char* str, unsigned int len) { ...
4
votes
8answers
6k views

Rotating an array

I'm trying to rotate an array such that given a number and an array, rotate the array by that amount. IE: abcdefgh given 3: fghabcde What is the best way to do this without using additional data ...
0
votes
2answers
58 views

Complexity of a pattern algorithm

I have been trying to find an algorith to determine the complexity of a pattern with this coordinate system on the left and the possible lines on the right handside of the picture: I am trying to ...
0
votes
2answers
65 views

Fastest way to walk from node A to node B in a red-black tree

Say I want to walk from node #154 to node #254 inorder the fastest posible: The best I can get is: get the first node in the range and walk inorder from this node: /* * Look for a node matching a ...
1
vote
0answers
17 views

How to smooth data of a line chart in PHP

I have a CSV data generated with PHP, coming from RRD data : timestamp,traffic_in,traffic_out 2017-01-23 16:35:00,-2268249.77,1907141.89 2017-01-23 16:40:00,-2268249.77,1907141.89 2017-01-23 16:45:00,...
1
vote
1answer
21 views

Sort array of positive integers in specific range in O(n)

How can we sort an array A of positive integers in range [0,n^2/2] in O(n) time? How can we sort the array if integers are in range [0,n^3/2] in O(n)? I am new to algorithms. I would appreciate if ...
0
votes
4answers
55 views

Finding a number lucky or not

I'm trying to solve a problem from hacker rank over here. The question is: So to solve this, I tried with a simple maths equation: 4x + 7y = lucky_number For example, to check 15 is a lucky_number ...
0
votes
1answer
16 views

Upgrade to latest Oracle JDK 1.8.0_121-b13 loses PBEWithMD5AndDES Algorithm

Getting: Caused by: java.lang.Throwable: java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available This worked with 1.8.0_111 -- what is the best workaround for backward ...
0
votes
0answers
12 views

how do I add Cg(n) to little Oh g(n)

The question is to prove if the following is true or false. f(n) = Θ(g(n)) => f(n) = cg(n) + o(g(n)), for some real constant c > 0. note: the o is little oh I was trying to do the following: ...
-2
votes
0answers
12 views
3
votes
3answers
208 views

How to compress a string

I had this question in one of my interviews: Given a string how would you compress it? Example input is not in the form of aabbccdd but like abcdgehrk. i.e. all chars in the string are different.(...
0
votes
2answers
102 views

Algorithm to find the most optimal match of multiple groups of objects

I apologize in advance for the long question, I tried to summarized it as much as I can. I am developing an application for a martial arts league. the first module of the application Requires to ...
0
votes
0answers
25 views

Compare Algorithm

What a newest, best Algorthm for Schedulling Campus I need paramater is lecture, time of schedulling, room, and capacity time of lecture. for againist Memetics Algorithm Im noob Thanks and sorry for ...
0
votes
0answers
24 views

What would be a good tree structure for this data?

I am building a kind of state machine in python. I have the following data #State is named tuple STATE_ACTIONS_MAP = {'state0' : [State('state1', 'action1'), State('...
-1
votes
0answers
31 views

Algorithm to find a possible correct filling of a matrix

I have a list of 2D object and for each one I have the row dimension and the column dimension. I need to find a good algorithm (I just done an algorithm, but is ultra exponential and it need a lot of ...
-3
votes
0answers
19 views

Creating an algorithm to predict probability for purchase

I run a website which is essentially SAAS. my head of performance told me that he would like to create an algorithm to predict the probability that a user will purchase our premium product. What type ...
-1
votes
0answers
11 views

What is the difference between video compression algorithm, image compression algorithm, audio compression algorithm and common compression algorithm

What is the difference between video compression algorithm, image compression algorithm, audio compression algorithm and common compression algorithm If all were Lossless compression algorithm. What ...
0
votes
1answer
24 views

median of two Sorted Array base case

I am trying to understand the base case for the median to two sorted arrays from below URL. http://www.geeksforgeeks.org/median-of-two-sorted-arrays-of-different-sizes/ I the above url the base case ...
3
votes
7answers
3k views

Detecting duplicate files

I'd like to detect duplicate files in a directory tree. When two identical files are found only one of the duplicates will be preserved and the remaining duplicates will be deleted to save the disk ...
1
vote
3answers
397 views

Dijkstra with Parallel edges and self-loop

If I have a weighted undirected Graph with no negative weights, but can contain multiple edges between vertex and self-loops, Can I run Dijkstra algorithm without problem to find the minimum path ...
1
vote
1answer
55 views

Minimum cops to catch all thieves in a given time

Given a Simple graph with N nodes and E edges. There are C thieves who can move on the graph with any speed (0 to infinite). We have to find the minimum number of cops required to catch all thieves in ...
-2
votes
0answers
44 views

list of all classification algorithms

I have a classification problem and I would like to test all the available algorithms to test their performance in tackling the problem. If you know any classification algorithm other than these ...
4
votes
6answers
154 views
+50

Prefix search against half a billion strings

I have a list of 500 mil strings. The strings are alphanumeric, ASCII characters, of varying size (usually from 2-30 characters). Also, they're single words (or a combination of words without spaces ...
0
votes
3answers
84 views

Quicksort - Hoare's partitioning with duplicate values

I have implemented the classic Hoare's partitioning algorithm for Quicksort. It works with any list of unique numbers [3, 5, 231, 43]. The only problem is when I have a list with duplicates [1, 57, 1, ...
-1
votes
1answer
20 views

find “for (i=1; i<=n; i++) for (j=1; j<=log(i); j++)” time complexity where n is given by user

i am new to algorithm and i would like to know . What will be the time complexity for nested loops for (i=1; i<=n; i++) for (j=1; j<=log(i); j++) time where n is given by user . Does ...
0
votes
0answers
18 views

Using treaps tp solve RMQ

I was trying to solve the following problem : problem It is basically an RMQ problem with dynamically added elements. Ive tried using treaps (random priorities and the keys representing the indexes ...
-1
votes
2answers
30 views

reducing simple special mod function to one line ( logically only , not tertiary operator)

I want a simple function that returns a mod of a number but in case of n%n I want value n instead of 0. my function goes: def special_mod(m,n): if m%n != 0: return m%n else ...
1
vote
1answer
50 views

rubiks cube rotation algorithm

I am currently working on an assignment to build a functioning Rubik's cube. The program does not need a GUI. But it must simulate a 3 X 3 cube with rotation behaviors and provide a graphical ...
0
votes
3answers
43 views

Fast response for subset queries

I have a database of 10,000 vector of integers ranging from 1 to 1,000. The length of each vector can be up to 1,000. For example, it can look like this: vec1: 1 2 56 78 vec2: 23 34 35 36 37 38 vec3: ...
0
votes
1answer
13 views

Glyph overlapping due to bearing considerations

Currently I'm working on a text rendering algorithm that samples pixels from a font atlas. The text is in a horizontal layout from left to right. Since true type fonts support left & right ...
0
votes
1answer
628 views

How to map a Product from Two Different Sites in Price comparison [on hold]

Suppose there are four websites selling the same product eg Samsung Galaxy S4. So there is one product with four different sellers; how can I make a product parent and list all prices of that product ...
0
votes
0answers
16 views

Min-Heap using 2 mins HELP Java

public class LAB2 { // TODO: document this method public static float heapAdd(float[] a) { // TODO: implement this method float min1 = 0; int min2 = 0; float sum = 0; int end = a....
0
votes
1answer
21 views

How to reduce a matrix with saving a the maximum element value?

Suppose I have a matrix int[][] matrix = { // 0 1 2 {0,0, 0,0, 0,0}, // 0 {0,1, 0,0, 0,0}, {1,1, 0,0, 0,0}, // 1 {0,0, 0,0, 0,1} }; int ...
0
votes
0answers
34 views

Writing a sorting algorithm from scratch in Python3.6

I am trying to create an original sorting algorithm for my home work for school but i can't get it to work and I don't understand why. def sa(x): print(x) i = 0 s_array = [] while x:...
1
vote
1answer
46 views

Longest Increasing Subsequences

For a digit N we define LIS Array as Longest strictly increasing subsequence of digits ending with that digit. For example, let us say 4-digit number is 1531, then the LIS array would be [1, 2, 2, ...
13
votes
5answers
5k views

The Maximum Volume of Trapped Rain Water in 3D

A classic algorithm question in 2D version is typically described as Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able ...
18
votes
3answers
803 views

Strange algorithm performance

For context, I wrote this algorithm to get the number of unique substrings of any string. It builds the suffix tree for the string counting the nodes it contains and returns that as the answer. The ...