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
1answer
14 views

sorting of words in lexicographic order

Given n words, is it possible to sort them in lexicographic order with o(n) time complexity?? Well i found a method like creating a trie data structure and an inorder traversal of the trie would ...
-2
votes
2answers
26 views

Using subset-sum oracle to determine which numbers are members of the subset

I am having trouble starting off this particular homework problem. Here is the problem: Suppose that you are given an algorithm as a black box – you cannot see how it is designed – it has the ...
1
vote
2answers
38 views

Logic of ternary operator in C?

I'm studying some AES implementation C code. The encryption code needs to get the password passed as argument, and so the encrypted and the output file. I understand it reads the password and that ...
2
votes
5answers
117 views

how to calculate modulus division

I am stuck in a program while finding modulus of division. Say for example I have: ((a*b*c)/(d*e)) % n Now, I cannot simply calculate the expression and then modulo it to n as the multiplication ...
2
votes
1answer
65 views

Best way to check a lot of check boxes in a checkboard game

I have in a game a lot of check boxes, that needs a set of rules. There is a rule, which is a one cross check box only should be there in one row of the whole matrix. I pictured the problem as a 2D ...
0
votes
1answer
27 views

Double pointer indirection when passing an array to a function

I wanted to brush up on my knowledge of algorithms and I've been using the following book: Algorithms in a nutshell At page 65 they print an algorithm for insertion sort. The algorithm is pretty ...
2
votes
2answers
81 views

Random number that averages a particular number

Seems simple, but I'd like a formula (.net preferably) which: For a given number- say, 1.5 - the formula will output a random number which taken over a series will average around 1.5... so it could ...
2
votes
0answers
45 views

maximum sum subrectangle in a sparse matrix

Finding the maximum sum subrectangle in an NxN matrix can be done in O(n^3) time using 2-d kadane's algorithm, as pointed out in other posts. However, if the matrix is sparse, specifically O(n) ...
1
vote
3answers
97 views

How to efficiently implement array element lookup and removal in Java?

Given a sorted array of objects, while the order is based on some object attribute. (Sorting is done via a List using Collections.sort() with a custom Comparator and then calling toArray()). ...
3
votes
4answers
45 views

what is the best way to implement a double ended priority queue?

needs to be implemented in a fixed size array..say 100 elements..if new elements need to be added after the array is full, the oldest needs to be removed need maximum and minimum in O(1) if possible ...
0
votes
1answer
10 views

Create Sparse Matrix with Coordinate Storage System?

I am writing a java program which involves working with a 1058 X 1058 matrix containing float values. This matrix contains many zero values and so I need to store this as a sparse matrix and later use ...
1
vote
1answer
44 views

C++ Algorithm for Sorting Connected Triangles Into Groups

I have a triangle mesh that has distinct groups of triangles e.g. a group of 15 connected triangles followed by another group (not connected to the first) of 25 triangles. The number of groups of ...
4
votes
4answers
119 views

How to obtain the index permutation after the sorting

Given an array arr = {5, 16, 4, 7}, we can sort it through sort(arr, arr+sizeof(arr)/sizeof(arr[0])). so now the array arr = {4, 5, 7, 16} and the permutation index for the sorted array is {2, 0, 3, ...
4
votes
3answers
71 views

size efficient dictionary(associative array) implementation

What algorithms are available for size efficient A dictionary or associative array? For example, with this key/value set, how can one avoid duplication "Alice" in values? { "Pride and ...
0
votes
3answers
109 views

Selection Rank Algorithm

Below is an implementation of the selection rank algorithm, which is used to find the elements before the Kth smallest elements in an array. Sometimes this program works well, but it sometimes fails ...
-3
votes
4answers
96 views

Sorting algorithm in general [on hold]

Which is the best sorting algorithm in general? Without any constraints and without any special conditions. I want to use it to sort a random list of around a million integers and the list is ...
1
vote
2answers
97 views

find center of cirle when three points are given

I studied this link and coded accordingly but getting Wrong Answer for the example explained in the link, During solving the equation, I subtracted equation 2 from equation 1 and equation 3 from ...
0
votes
1answer
22 views

A fast and accurate method for comparing similarity between text documents

I need to compare two groups of documents (e.g. one group might have 1000 documents) and determine which document of the second group is the most similar to the certain document in the first group. ...
0
votes
0answers
51 views

Calculate maxium average block points

I have an array with 30.000 integer values, and I need to calculate the biggest 60 consecutive elements block. I've done this, it works but I don't know if there is a better way to do that. Now it ...
1
vote
1answer
15 views

How to represent crosstab data in java memory to provide category movements?

I have a problem with both the loading and performing operations with crosstab(contingency table). I would like to load the data from a flat txt file (from crosstab) and store this in memory to print ...
3
votes
5answers
182 views

Metric Convertions Algorithm without “if-else” or “switch-case”

I want to write a program which can converts one unit to another unit. Let's say I have 2 methods.First method can do metric conversions, second method can do weight conversitons. For example; 1. ...
-3
votes
0answers
66 views

Efficient algorithm for counting distinct prime factors of an integer [on hold]

Looking for an efficient algorithm to count the number of prime factors of an integer . Integers<=100000 not a problem as integers are not big but need to find out for all of the integers till ...
1
vote
2answers
35 views

Weiszfeld algo for “highway” distance?

The problem is to find the point minimizing the travel distance for around 100 persons in different regions who want to meet in the same place. Travel is by car not by plane. Assuming that I get ...
1
vote
3answers
58 views

Why is performance of bubble sort and insertion sort same i.e O(n^2)

I did the below code to check the number of iteration and swaps required for bubble sort and insertion sort. Even though (referring to below code) insertion sort did literally half iterations and same ...
1
vote
3answers
77 views

Generate n colors between two colors

I'm trying to write function, which can generate colors between two colors based on a given value. An example would explain it better.. Input .. X : 1 Y : 0.5 Z : 0 The user gives any set of ...
7
votes
5answers
148 views

Find the first element that occurs only once [duplicate]

This was a Google interview puzzle. The problem is to find the first element in an array that occurs only once. For example, abaaacdgadgf is given. We need to output b. The simple solution seems to ...
0
votes
3answers
78 views

How to print a sorted column from matrix in C

I'm new in C programming language, and I try to practice my skills in this language. I'm coding an exercise about a matrix, where the user inputs the number of the column that wants to sort and print ...
0
votes
2answers
50 views

Find the 10 most frequently used words in a large book [duplicate]

I am aware that this has been asked on the forum a couple of times, I did not find any 'TAGGED' answer which could be considered the most appropriate soluion - so asking again: We are given a very ...
-5
votes
0answers
43 views

Find/Search and Replace Algorithm not using string/cstring class [on hold]

I am working on a ridiculous homework assignment that requires me to essentially create a search and replace program but I cannot use any string class or cstring functions such as .replace .find ...
3
votes
2answers
101 views

Find the first Triangular number which is having 50 factors?

-----Modification of code requested -------- Question : Count the Fast Triangular Series Number which is having 50 Factors ? Elaborated : Let's say there is a series 1 : 1 3 : 1+2 6 : ...
0
votes
1answer
49 views

Algorithm to compare source code

I came across a problem, in which I had to find the difference between two files containing PHP code (old-version and new-version). Since each of the files contained more than a thousand lines, ...
1
vote
0answers
39 views

What algorithms do you know for beltway reconstruction?

I've faced the beltway reconstruction problem and I've developed a simple backtrack algorithm, what algorithms do you know for this problem? Beltway Reconstruction Problem: Assume there is a set of ...
0
votes
3answers
69 views

Delete a last node of linked list given pointer to that node

I'm trying to delete the last node of the linkedlist, given pointer only to that node. I wrote the below implementation, but isn't working. I already visited majority of SO questions regarding ...
1
vote
0answers
37 views

Snake Algorithm - opencv active contour - not working so well

I'm actually working on a contour detection for head side. As pictures are taken in front of a white wall, I decided to run a snake (active contour model algorithm) on the picture processed with a ...
-8
votes
0answers
31 views

Can someone please explain median of medians using a set of integers as example? [on hold]

Please do not point me to some other url. I have read a lot of other links, but could not understand median of medians algorithm. Please use numbers as examples and explain. Thanks!!
4
votes
1answer
171 views

Do processors actually calculate multiplication by a zero or one? Why?

The Short Version In the following line: aData[i] = aData[i] + ( aOn * sin( i ) ); If aOn is 0 or 1, does the processor actually perform the multiplication, or does it conditionally work out the ...
1
vote
1answer
26 views

Isometric depth sorting

I've written the beginnings of a 2D isometric engine using Java. I've got most of the basics covered such as tiling orders and object depth sorting on the map. However, I've run into a problem which I ...
1
vote
7answers
92 views

Initialize entire array with a value in C

I was trying to initialise an entire int array and after searching through Stackoverflow, i found that the best way is to use std::fill_n from <algorithm> or <vector> header but including ...
3
votes
1answer
62 views

Searching through a partially sorted array in O(lgn)

I'm having a hard time solving this problem. A[1..n] is an array of real numbers which is partially sorted: There are some p,q (1 <= p <= q <=n) so: A[1] <= ... <= A[p] A[p] >= ... ...
2
votes
2answers
54 views

Which algorithm should I use to extract an array from a multidimensional array?

For example, I'd want to extract sub-arrays from an array like this, where arr is a 3-dimensional array, and "all" means that all possible values at that index position are selected: getSubArray(arr, ...
1
vote
1answer
65 views

Finding paths of length k

Given a graph with n nodes there are a number of serial methods of increasing sophistication and reducing complexity for finding simple paths of length k in a graph. The best known asymptotic ...
1
vote
0answers
48 views

radix sort to sort some words like dictionary?

How do I use radix sort to sort the the words like in dictionary if the words are of different length? If the words length are equal than its easy. But I cant figure what to do when it have different ...
5
votes
1answer
158 views

Bus travel capacity between two stops

If you have the full bus schedule for a country, how can you find out the maximum number of people that can be carried between between two specified stops in 1 day? I assume a bus schedule gives ...
1
vote
1answer
50 views

Algorithm for sorting an array of points on their concentration

I have array of coordinates, and I wish to sort it by concentration zone of points. I have tried using Graham algorithm, (shown below,) but I do not get the desired result. What algorithm can I use to ...
-6
votes
0answers
50 views

Timus Online Judge Ural Steaks [on hold]

I'm a noob at algorithm problems. I'm trying to learn by solving online judge questions. http://acm.timus.ru/problem.aspx?space=1&num=1820 I'm stuck at this. Can anybody explain me the layman ...
15
votes
5answers
363 views

Travelling by bus

If you have the full bus schedule for a country, how can you find the furthest anyone can travel in one day without visiting the same stop twice? I assume a bus schedule gives you the full list ...
1
vote
1answer
33 views

k-subset product algorithm in O(n^k) vs. O(n^(k-1)log(n))

I am very desperate about this question that I have to solve to be admitted for an exam in algorithm that is maximally important for my future. Unfortunately, I am superbad in computer science. Could ...
1
vote
1answer
40 views

Genetic algorithm chromosome generation

I need to develop a system to select a team out of a database. Is it possible to use a Genetic algorithm to get the initial population (chromosomes) representing players as some identifier. Each ...
0
votes
0answers
109 views

Number of anagrams which are palindromes for a word which is a palindrome [duplicate]

So here's the problem. I need to find out the number of anagrams possible which are palindrome for a word which itself is a palindrome. Then I have to calculate (the number of such possible possible ...
1
vote
1answer
41 views

Multiple TSP with a twist

A couple weeks ago I encountered a problem that I virtually broke down to a variation of the traveling salesman problem. The twists are: There are multiple salemen. The list of cities is dynamically ...

1 2 3 4 5 626