An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

learn more… | top users | synonyms

-1
votes
0answers
19 views

knapsack problem using greedy

I have a code for knapsack problem using greedy but is is not the best optimal option and does not work very well. Can someone give me an optimal idea for this? ...
-2
votes
0answers
25 views
0
votes
0answers
8 views

A code to evaluate what date it will be after n days [on hold]

I've been trying to implement a program that, given a date \$a\$ and a integer \$n\$, returns the date \$b\$ which is \$n\$ days after \$a\$. For example, if \$a\$ 3/4/2015 and \$n=2\$, we should get ...
2
votes
1answer
120 views

Labeling alternating max/mins based on a user defined delta

Given a set of values (points on a graph) find all the max/min points such that there is no max is followed by a max (i.e. the max and min points alternate) there is some minimum amount of change ...
4
votes
2answers
39 views

Implementation of Graham Scan algorithm in Haskell

Here is an implementation of Graham Scan algorithm for computing the convex hull of a finite set of points: ...
3
votes
1answer
55 views

Removing duplicates in a char[] O(n)

We're given a char[] containing characters A-Z. (For more characters this can easily be extended). Now we're asked to remove all ...
3
votes
2answers
31 views

Program to evaluate powers of complex numbers

I'm trying to develop a simple program to evaluate integral powers of a complex number \$z\$ , that is, \$z^n\$, where \$z\$ is in the algebrical form \$a+i b\$ and \$n \in \mathbb{Z} ^{*} _{+}\$. ...
3
votes
1answer
32 views

Spending a target sum, preferably split equally

I have a strange programming prompt. I managed to complete an algorithm to solve smaller test entries (which i'll post). One of my test cases has to complete a 200,000 int input and my algorithm isn't ...
-1
votes
0answers
20 views

how to set bucket sort to sort negative numbers in c++ [on hold]

I just finished the bucket sort, it works fine without a for function: ...
3
votes
1answer
34 views

Acquiring indices for anagrams of an input string

I am working on an interview question from Amazon Software: Design an algorithm to take a list of strings as well as a single input string, and return the indices of the list which are anagrams of ...
6
votes
2answers
191 views

Finding pairs of numbers within A that add up to N

I am working on an interview question from Amazon Software Interview: Given an integer N and an array of unsorted integers A find all pairs of numbers within A which add up to N I have a working ...
3
votes
2answers
35 views

Converting from base-10 to word

The following code is used to convert a base-10 number to a base-N number, where N is a length of a given alphabet that contains characters of which a base-N number ...
6
votes
1answer
70 views
+100

Generating a histogram efficiently from the datasets in a Map

I have a map in which I store total bytes as the key and count of users as the value: ...
2
votes
1answer
29 views

Calculating top position of elements based on their heights

I have a data representing several elements (that could be rendered at some point as div), composed of y position (property top) and its height (property height). ...
2
votes
1answer
38 views

Path from the root to a given node in binary tree

Based on the solution provided in this question , I have written non-recursive Java code to find the path form to a given element in a binary tree. This code is working for all the elements except ...
2
votes
1answer
50 views

Bucket sort implementation

I want to optimize my code for performance and fine-tuned logic. ...
1
vote
0answers
27 views

Traversing game state space : more search leads to bad results [closed]

I am trying to solve a problem which i think is TSP on a 2-D grid. So, i am trying to get the best result that i can. However, looking ahead 1 step is producing ...
6
votes
2answers
269 views

Sum the exponents of the prime factors of a number

My goal is to find the sum of the exponents of the prime factors of an integer. I wrote the code below with the complexities specified here (I am not 100% sure of the complexities though): Runtime ...
4
votes
4answers
105 views

Extremely simple character manipulation

Given a string, this code Multiplies odd numbers Subtracts even numbers, do nothing if only one even number is found Turns uppercase letters to lowercase and vice versa I think this code is too ...
5
votes
3answers
75 views

Line passing the most number of points

Given points on a two dimensional graph, find a line that passes the most number of points. Any comments please? ...
7
votes
3answers
165 views

Return list of common email ids from a list of lists

Input: ArrayList of ArrayLists with email ids. Output: Return ArrayList of email ids which appears in each inner ArrayList. Ex: Input: [[abc@gmail.com, ...
4
votes
0answers
226 views

Quicksort async vs serial

I am playing with async and I figured I'd write a parallel implementation of Quicksort while trying to look at various optimizations. I want to keep the generics ...
4
votes
3answers
96 views

Merge sort implementation and improvements

I would like your opinion on my Java implementation of the merge sort algorithm on an integer array, since I'm not really into algorithms I'd like to know from you if this is a correct implementation ...
4
votes
2answers
72 views

Averaging lists of values with duplicate keys

I have gene expression data that I represent as a list of genes and a list of lists of values. I average the expression data for any genes with the same name. For example: ...
5
votes
1answer
104 views

Minimum number of coins - (dynamic programming solution - topdown approach)

This is a problem from topcoder tutorials Given a list of N coins, their values (V1, V2, ... , VN), and the total sum S. Find the minimum number of coins the sum of which is S (we can use as many ...
6
votes
2answers
72 views

Find element in sorted matrix

Find an element in a MxN matrix where each row and column is sorted in ascending order. Any comments on my code? (I added some test cases on non square matrices which I did not copy here) ...
1
vote
0answers
46 views

Minimum amount of edges that needs to be traversed to visit all vertices… or something like that

So I have this problem, where I'm given m connections over n vertices. The vertices are labeled ...
1
vote
1answer
38 views

GCD calculation - A cross of the Euclidean and the Binary algorithm

I was reading Knuth's The Art of Computer Programming - Volume 2 (Seminumerical Algorithms) Third Edition. I saw the two algorithms (A and B). A method (due to V. C. Harris) was mentioned (in page ...
6
votes
5answers
551 views

Number of distinct elements in an array

This is my solution to find the Number of distinct elements in an array. Is there away fast way to do this? It run-time is O(N). ...
6
votes
2answers
92 views

Grouping An Array of Strings into Anagrams

Ok, so this code works perfectly, however, I've not coded in Java for a long time, so I'm worried about breaking Java conventions, but even more important, I would appreciate any comments on making ...
2
votes
1answer
43 views

HackerEarth Crazy kangaroo challenge

I want to find the lowest hop count from source to destination. The challenge, in summary: The first line contains the number of test cases T, 1 ≤ T ≤ 100000. The next T lines each contains ...
2
votes
2answers
86 views

Project Euler - Smallest multiple

Here's Problem 5 - Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly ...
13
votes
2answers
237 views

“ACM ICPC Team” challenge on Hackerrank… Easy?

This challenge took me awhile to figure out, and it's characterized as "easy," so I'm sorta wondering what I missed. Problem Statement You are given a list of N people who are attending ...
3
votes
1answer
41 views

Generalized Suffix Tree implementation

I've started to write a Generalized Suffix Tree implementation. The overall code is still in an experimental state, though I think it's mature enough to ask for a little review. I'd like to know how ...
5
votes
3answers
175 views

A partition algorithm for positive integers

I have encountered the following problem that I found very interesting to solve: Given an array of positive integers {a1, a2, ..., an} you are required to partition the array into 3 ...
4
votes
2answers
85 views

Removing duplicates for both values

My special case: home project, automatic downloader for podcasts. Overall algorithm is: Download a list of available podcasts hash the podcasts load metadata + hash of downloaded podcasts from ...
2
votes
0answers
29 views

Search/sort/create functionality, implements bubblesort and sequential search

I've moved my main() to the bottom of the code block in order to fit it all in one class for this submission. If there is a better way to do it? ...
3
votes
2answers
74 views

Radix sort with integer divisions

Here's a perhaps naive but simple implementation of Radix sort in Java. It works with any radix, and both positive and negative numbers. ...
0
votes
1answer
45 views

Generic list heapsort in Java

This is an implementation of heapsort as seen on Programming Pearls, adapted for java List collections. It is working on a copy of the list passed-in on purpose at the moment. ...
1
vote
1answer
52 views

Performing Gauss-Jordan elimination on a matrix in Java

I have this small "framework" for representing matrices with entries of primitive type double, and performing Gauss-Jordan elimination (for solving systems of ...
5
votes
1answer
56 views

Exchange system of numbers

I've got the following task: Keeping in mind Horner's Scheme, write an application that converts a given number x in ...
5
votes
3answers
84 views

Check if a binary tree is balanced

Looking for code-review, optimizations and best practices. This question is attributed to geeksforgeeks. NOTE: Please help me verify space complexity, as I am creating ...
5
votes
1answer
60 views

TCP Server using NIO to save data from IoT clients

I've built a small single threaded TCP server using NIO. This server is used by small client devices to report things like temperature, when the device has been switched on, when it switches off, and ...
2
votes
1answer
45 views

K-means clustering algorithm in python

Here is my implementation of the k-means algorithm in python. I would love to get any feedback on how it could be improved or any logical errors that you may see. I've left off a lot of the ...
6
votes
4answers
135 views

Pi-calculating program

I saw this question and answer about calculating pi on Stack Overflow, and I decided to write my own program for calculating pi. I used Python and only integers (I didn't want to use floating point ...
3
votes
4answers
169 views

Count the ways to partition an array into two equal sets

I need to count the number of ways to partition an array into two contiguous arrays such that those arrays contain exactly same set of items. Suppose ...
3
votes
2answers
72 views

Removing duplicates from an array

I recently wrote this JavaScript algorithm for removing duplicates from an array as part of a job interview process, but was turned down for the position after submitting the code. I didn't receive ...
3
votes
2answers
71 views

Premium palindromic primes

Challenge: Write a program which determines the largest prime palindrome less than 1000. The answer is 929, and my program correctly finds and prints this, but actually ended up being more complex ...
5
votes
1answer
81 views

Paint fill function

Implement the "paint fill" function of image editing programs: Given a screen point and new color fill the surrounding area. Any comments on the code below? Time complexity: ...
9
votes
1answer
127 views

Reading, processing and counting an array setting limits

Last weekend my teacher asked me to create code to solve a problem: Giving a dynamic array, we want to pass the array elements from a file. The first number in the file N gives us the array ...