An algorithm is a precise plan (in the format of a sequence of steps) on how to solve a particular problem.
2
votes
0answers
29 views
How can I improve my algorithm?
This is a problem from Interview Street in Dynamic Programming section.
https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb
Billboards(20 points)
ADZEN is a very ...
5
votes
3answers
104 views
Removing duplicates from an unsorted linked list
Does the code below look correct and efficient for removing duplicates from an unsorted linked list without using extra memory?
An object of type Node denotes a LL node.
void removeDuplicates()
{
...
9
votes
3answers
113 views
Reversing a linked list
I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
2
votes
3answers
71 views
Prime numbers, Prime Factors and LCM
I am trying to generate LCM by prime factorization. I have already done the other way around to generate LCM using GCD but I am trying to achieve it using prime factorization.
I am getting right ...
2
votes
0answers
31 views
Scala: Disjoint-Sets
I would like to get some feedback on the following implementation of disjoint sets, based on disjoint-sets forests (Cormen, et.al., Introduction to Algorithms, 2nd ed., p.505ff). It should have the ...
2
votes
1answer
77 views
Attempt at Merge Sort: Is this correct?
I am trying to write a merge sort algo. I can't tell if this is actually a canonical merge sort. If I knew how to calculate the runtime I would give that a go. Does anyone have any pointers? Thanks.
...
3
votes
1answer
89 views
Need an algorithm to optimize grouping python dictionaries in hierarchical form
Previously I asked a question on how to group dictionaries in a list in a hierarchical structure.
Initially I wanted to group a list of dictionaries that looks like the following, using multiple ...
2
votes
2answers
91 views
the number of connected component
Compute the number of connected component in a matrix, saying M. Given two items with coordinates [x1, y1] and [x2, y2] in M, M(x1, y1) == -1 && M(x2, y2) == -1 && |x1-x2|+|y1-y2|=1 ...
4
votes
1answer
71 views
Partitioning Array
Problem: Given a randomly ordered array of n-elements, partition the
elements into two subsets such that elements <=x are in one subset and
elements > x are in the other subset.
one way to do this ...
8
votes
5answers
312 views
Write a function to print numbers
I would like to write a python or c++ function to print numbers like the following examples (with n as input parameter):
When n = 3, print:
1 2 3
8 0 4
7 6 5
When n = 4, print:
4 5 6 7
15 0 1 ...
1
vote
2answers
66 views
Improve the space and time complexity
I'd written this code:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.StringTokenizer;
/**
*
* @author Mohammad Faisal
*/
...
3
votes
0answers
20 views
How can I improve this 31-bit SuperFashHash implementation in VBA?
I'm implementing a variation of the SuperFastHash in VBA for use in Excel (32-bit version, so no LongLong available) to hash strings.
To get around the limitations of signed 32-bit Long values, I'm ...
2
votes
2answers
74 views
want to cache 1600 integers, but caching and searching from treeSet takes lot of time
Set<Integer> set = new TreeSet<Integer>();
//some logic to populate 1600 numbers
for (int cases = 0; cases < totalCases; cases++) {
String[] str = br.readLine().split(" ");
...
4
votes
1answer
92 views
Java implementation of the longest monotone increasing subsequence
Problem: Given a set of n distinct numbers, find the length of the longest monotone increasing subsequence.
For example, let's take this array [1,2,9,4,7,3,11,8,14,6]
The longest monotone increasing ...
2
votes
0answers
32 views
How to increase efficiency of matrix operation in C?
I have a N*N upper triangular matrix with property such that, all its diagonal elements are a1,a2,a3,...,aN. I want that a[i][j] (for all j>i) should be
(a[i][j-1] + a[i+1][j]) / 2.
I have many ...