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)

1
vote
2answers
18 views

Not able to merge Sorted Linked Lists using Auxiliary Linked List

Please give a simple solution to problem. I have used the algorithm like mergesort but I am not able return head of the auxiliary Linked list, I created. I have seen other example on stack overflow. ...
5
votes
5answers
102 views

Need to Optimize the function

I'm working on this function that has to return all possible values of adding a and b n times for example if n = 1 then possible values would be a + a a + b and b + b. function below works but it's ...
2
votes
1answer
13 views

Finding where to start counting in a Calendar application

My Calendar Hello, I'm new here and couldn't quite find an answer to this specific Javascript question--Basically, I have a Calendar application made in HTML that's made up of 7 rows and 6 columns, ...
1
vote
3answers
26 views

Base case for Karatsuba Multiplication

Just wondering why the base case for Karatsuba multiplication ( shown here: http://www.sanfoundry.com/java-program-karatsuba-multiplication-algorithm/) is chosen to be "N<= 10"? I found "N<= 4, ...
0
votes
0answers
15 views

Converting vertex co ordinates into pixel coordinates in c++

I want to compute the z value of a triangle using z buffer algorithm in c++. My projection plane is a square of length two and divided into a two dimensional grid of screen_width x screen_height (720*...
-2
votes
0answers
21 views

Number of subsets of an array (size n) of size k having difference between maximum and minimum elements at most x

I came across this question during a test. Given an array of size n find number of subsets of size k having difference between maximum and minimum element at most x. Constraints 1<=a[i],n,k,x<=...
0
votes
3answers
137 views
+50

Efficent way to find overlapping of N rectangles

I am trying to find an efficient solution for finding overlapping of n rectangles where rectangles are stored in two separate lists. We are looking for all rectangles in listA that overlap with ...
0
votes
1answer
28 views

How to implement 3Sum in Java?

I want to implement a 3Sum and came across the following implementation, why why does it do 0 - num[i] for sum? Say the first index has an integer 5 in the array num, wouldn't it be -5 then how can ...
0
votes
1answer
7 views

ZIO 2012: Toy Set

A toy set contains blocks showing the numbers from 1 to 9. There are plenty of blocks showing each number and blocks showing the same number are indistinguishable. We want to examine the number of ...
0
votes
1answer
35 views

Finding nearest non-coprime number

Given an array, I need to find the indices of nearest non-coprime number (i.e. GCD(Ai, Aj) > 1 , for any Ai and Aj in the array, i != j ) Example, let the array be [2 17 4 6 10] The answer will be ...
17
votes
10answers
9k views

How to sort three variables using at most two swaps?

The following algorithm can sort three variables x, y and z of type K which are comparable using operator<: void sort2(K& x, K& y) { if(y < x) swap(x, y); } void sort3(K&...
0
votes
0answers
39 views

Find the most efficient grouping of a series of intervals

I have an application where I have a series of non overlapping fixed width intervals, each of which have a given key. Each interval has the same width, and there may be contiguous intervals. ...
0
votes
5answers
316 views

Relevance of Quicksort, Heapsort and Bubblesort

I'm currently enrolled on a 1 year masters course in Applied Computing that is intended to take people without a background in computing and give them a crash course in a software development and ...
1
vote
0answers
28 views

Not getting the colored triangles during the implementation of z-buffer algorithm in c++

I am doing a work on clipping and hidden surface removal on a list of triangles in 3D. Say, I have got a list of triangles after clipping and projection transformation applied on them. Now I want to ...
3
votes
1answer
29 views

Very slow minesweeper recursive algorithm in Swift

I'm working with Swift 3 and Xcode. I'm creating an iOS game that is basically a Minesweeper, but there are no squares but hexagons, so each hexagon can have up to 6 mines in their surrounding. I ...
1
vote
1answer
8k views

Using Extended Euclidean Algorithm to create RSA private key

This is for an assignment I'm doing through school. I am having trouble generating a private key. My main problem is understanding the relation of my equations to each other. To set everything up, we ...
0
votes
0answers
13 views

Find all the nodes which can be reached from a given node within certain distance

Multiple nodes can also be traversed in sequence to create a path. The problem is I can't use a graph since all nodes are connected to each other. All the data is just an array of nodes with their ...
-2
votes
2answers
20 views

Split 1 ArrayList into multiple ones based on condition

I have a big ArrayList containing strings. I want to split it, based on a condition that an element meets. For example, it could be the string length if ArrayList contained String. What is the most ...
0
votes
1answer
39 views

Convert a rating scale

I have a website where people can evaluate some subjects. Here is the scale [1-4]. However I probably have a problem in terms of readability of the overall rating. The most common scale is [1-5] in ...
0
votes
1answer
15 views

Connect 4 Minimax Implementation

i'm having troubles thinking of the implementation of the minimax algorithm for the game Connect 4. My main questions are these: How should this algorithm be implemented? like, which are the main ...
3
votes
4answers
4k views

How binary search is used in database indexing

I know how binary search works but I wanted to know practical uses for binary search... I searched through the internet and I found that the main use is data base indexing,but I couldn't understand ...
2
votes
1answer
29 views

ZIO 2013: Dolls

Your shop sells several different types of dolls. Each doll has a suggested price, and no two types of doll have the same price. You would like to fix an actual selling price for each doll so that ...
-2
votes
0answers
44 views

Boyer-Moore program doesn't work correctly

In learning was faced with the task based on the algorithm of Boyer-Moore. The decision found the following: #include "stdafx.h" #include <iostream> #include <cstring> #include <...
0
votes
1answer
32 views

What is the time complexity of the following nested loops in Big-Theta notation?

for (int i = 0; i < n; i++) for (int j = i; j < n; j *= 2) for (int k = j; k < n; k *= 2); I know time complexity is O(n.log2(n)), but I want it in Big-Theta notation.
0
votes
3answers
80 views

Generating Diffie-hellman parameters (generator)

I'm trying to implement a diffie-hellman key exchange. Let's say I found a large prime number p - how can I find a generator g? Restricted by the multiprecision library that I have to use, only a few ...
-7
votes
0answers
26 views

C5 programming in R - Decision tree modelling [on hold]

I am new to R and C5.0 used in R. Does anyone know of a user manual for C5.0? Currently I can create a simple decision tree but would like to weightings to different variables and get the best use ...
0
votes
0answers
18 views

Print the solution to the MEMOIZED-ROD-CUT [on hold]

I'm reading about the "rod-cut" problem presented in the 15th chapter of the "Introduction to Algorithms" book (3rd ed.) by CLRS. There's an exercise, 15.1.4, which asks us: Modify MEMOIZED-CUT-ROD ...
-1
votes
1answer
36 views

Encode string “aaa” to “3[a]”

give a string s, encode it by the format: "aaa" to "3[a]". The length of encoded string should the shortest. example: "abbabb" to "2[a2[b]]" update: suppose the string only contains lowercase letters ...
-1
votes
0answers
14 views

Java: evolutionary programme to test objects effectiveness in running a race

this isn't really a technical question related to syntax to java but I cannot find any information anywhere else. I am making a programme that see's how far an object would travel related to how many ...
-1
votes
1answer
16 views

Algorithm for scaling image based on another image size and also preserve its aspect ratio

I have 2 images, Image 1 and Image 2. Image 1 has a size of 512(width) x 515(height). Then Image 2 with size of 256(width) x 256(height). Image 2 is will be used as a watermark and will be placed ...
2
votes
1answer
31 views

Different behaviors algorithm when working with a UTF8 on different operating systems

Simple code of algorithm: #include <iostream> #include <string> std::string::size_type GetLengthWithUTF(std::string &sValue); int main() { std::string sTestValueUTF8 = "\xD0\xB6\...
-1
votes
1answer
50 views

Travelling Salesman (TSP) Performance - many possible stops [on hold]

I must calculate shortest possible path between X number of stops and in worst case scenario it includes 350-400 stops and I am wondering if there is any existing solution/algorithm to solve this ...
15
votes
9answers
21k views

Depth vs Height of a tree. Refreshing the fundamentals

I am doing a refresher an algorithms and data structures. I am confused on the concept of depth vs height of a tree. In many cases, especially on sites focusing on interview quizes, it seems to me ...
-3
votes
0answers
41 views

predict an ascending series

I have Series where "the number n repeats f(n) times". I'm a beginner in c++ and its been quit a challenge in past few weeks. for n=1 and n=2 the default f(1)=1 and f(2)=2 which means 1 repeats 1 time ...
0
votes
1answer
33 views

How to judge the contour is line or curve by opencv?

Guys. This image have two contours. I can find both with opencv findcontour function. What I want to know is how to judge which contour is line and which contour is curve ? Can anybody please tell how ...
-1
votes
0answers
31 views

Consider a min-priority queue with limited range of key values so there are only k possible k

Consider a min-priority queue with limited range of key values so there are only k possible key values. Describe a priority queue data structure that supports extract-min, minimum and increase key in ...
1
vote
2answers
44 views

Sum of zeros and ones in a Binary De-Bruijn sequence

I need to prove/ disapprove whether in every binary De-Bruijn sequence there is equal amount of zeros and ones. From several examples I did with n=3 and n=2 I saw that there is the same amount of 0s ...
64
votes
11answers
37k views

How to efficiently build a tree from a flat structure?

I have a bunch of objects in a flat structure. These objects have an ID and a ParentID property so they can be arranged in trees. They are in no particular order. Each ParentID property does not ...
30
votes
2answers
500 views

`std::list<>::sort()` - why the sudden switch to top-down strategy?

I remember that since the beginning of times the most popular approach to implementing std::list<>::sort() was the classic Merge Sort algorithm implemented in bottom-up fashion (see also What ...
0
votes
0answers
9 views

Node.js implementation of resize image algorithms with results identical to java Graphics2D

I am looking for Node.js implementation of resize image algorithms (e.g. nearest neighbor). And major requirement is the output image have to be identical with image processed on Java using Graphics2D ...
0
votes
0answers
44 views

to convert given number 'a' into a number that contains a single 1 in its binary representation (i.e. a power of two)

We need to convert a given number 'a' into a number that contains a single 1 in its binary representation (i.e. a power of two). I got a c++ code for the same but could not understand the logic as ...
2
votes
1answer
32 views

Excess (-1) in base 4 representation

I've been trying to wrap my head around this one problem for the last couple of days, and I can't figure out a way to solve it. So, here it goes: Given the base 4(that is 0, 1, 2, 3 as digits for a ...
2
votes
3answers
64 views

Cartesian product with specific criteria

I am attempting to find the cartesian product and append specific criteria. I have four pools of 25 people each. Each person has a score and a price. Each person in each pool looks as such. [0] =&...
1
vote
1answer
28 views

Convert Integer to Generic Base Matlab

I'm trying to convert a base-10 integer k into a base-q integer, but not in the standard way. Firstly, I'd like my result to be a vectors (or a string 'a,b,c,...' so that it can be converted to a ...
-4
votes
1answer
31 views

Element uniqueness algorithm [on hold]

For my class, I am asked to solve an element uniqueness problem. I have a sample of code here which I have to implement. I need to perform an experimental analysis to determine the largest number of n ...
1
vote
1answer
643 views

Calculate the convex hull of a star polygon in O(n) time

A polygon P is star-shaped if there exists a point p in the interior of P that is in the shadow of every point on the boundary of P. The set of all such points p is called the kernel of P. For ...
8
votes
3answers
6k views

Understanding the bottom-up rod cut implementation

In Introduction to Algorithms(CLRS), Cormen et al. talk about solving the Rod-cutting problem as follows(page 369) EXTENDED-BOTTOM-UP-CUT-ROD(p, n) let r[0...n] and s[0....n] be new arrays r[...
0
votes
0answers
39 views

How to keep track of a specific choice values in java

I am doing the shortest path first algorithm(Floyd and Warshall), and it is working, except I am not sure how to keep track of the path I went through, since I am visiting multiple paths first before ...
-1
votes
0answers
16 views

L-system based Roadnetworks for a city

Hi stackoverflow community, i'm new here and in the current work for the university i am trying to implement a procedural roadnetwork generator in unity(with an L-System). This generator can receive ...
-2
votes
0answers
12 views

How to apply merge sort if we divide the array into different parts not same? [duplicate]

How can we apply merge sort if we split the array into different parts like 1/4 and 3/4 etc. E.g we have array 27 14 55 22 11 22 89 23 21 19 23 90 29 39 28 37 1) Dividing data into two ¼ and ¾ ...