algorithm

Texture coordintes for a polygon and a square texture

basically I have a texture. I also have a lets say octagon (or any polygon). I find that octagon's bounding box. Let's say my texture is the size of the octagon's bounding box. How could I figure out the texture coordinates so that the texture maps to it. To clarify, lets say you had a square of tin foil and cut the octagon out you'd be ...

top-k selection/merge

I have n sorted lists (5 < n < 300). These lists are quite long (300000+ tuples). Selecting the top k of the individual lists is of course trivial - they are right at the head of the lists. Example for k = 2: top2 (L1: [ 'a': 10, 'b': 4, 'c':3 ]) = ['a':10 'b':4] top2 (L2: [ 'c': 5, 'b': 2, 'a':0 ]) = ['c':5 'b':2] Where it gets mor...

Algorithm for finding similar users through a join table

I have an application where users can select a variety of interests from around 300 possible interests. Each selected interest is stored in a join table containing the columns user_id and interest_id. Typical users select around 50 interests out of the 300. I would like to build a system where users can find the top 20 users that have ...

How to determine item at a index in pattern

I have the following elements in a list/array a1,a2,a3 and these elements are used to build another list in a predictable pattern example a1,a1,a2,a2,a3,a3,a1,a1,a2,a2,a3,a3... The pattern may change but I will always know how many times each element repeats and all elements repeats the same number of times. And the elements always ...

jump search algorithm

i am doing jump search algorithm but it show me that element is not in array while it is here is code import java.math.*; public class jamp { public static int min(int a,int b) { return a<b?a:b; } public static void main(String[]args) { int a[]=new int[]{3,7,9,12,14,15,16,17,18}; int l=14;...

Why does this Quicksort work?

I find this Quicksort partitioning approach confusing and wrong, yet it seems to work. I am referring to this pseudocode. Note: they also have a C implementation at the end of the article, but it's very different from their pseudocode, so I don't care about that. I have also written it in C like this, trying to stay true to the pseudoco...

Solving the problem of finding parts which work well with each other

Hi, I have a database of items. They are for cars and similar parts (eg cam/pistons) work better than others in different combinations (eg one product will work well with another, while another combination of 2 parts may not). There are so many possible permutations, what solutions apply to this problem? So far, I feel that these are ...

Java - Collections.sort() performance

Hello, Im using Collections.sort() to sort a LinkedList whose elements implements Comparable interface, so they are sorted in a natural order. In the javadoc documentation its said this method uses mergesort algorithm wich has n*log(n) performance. My question is if there is a more efficient algorithm to sort my LinkedList? The size...

Search algorithm (with a sort algorithm already implemented)

Hello, Im doing a Java application and Im facing some doubts in which concerns performance. I have a PriorityQueue which guarantees me the element removed is the one with greater priority. That PriorityQueue has instances of class Event (which implements Comparable interface). Each Event is associated with a Entity. The size of that p...

Algorithm for dividing very large numbers

I need to write an algorithm(I cannot use any 3rd party library, because this is an assignment) to divide(integer division, floating parts are not important) very large numbers like 100 - 1000 digits. I found http://en.wikipedia.org/wiki/Fourier_division algorithm but I don't know if it's the right way to go. Do you have any suggestions...

Lists Hash function

I'm trying to make a hash function so I can tell if too lists with same sizes contain the same elements. For exemple this is what I want: f((1 2 3))=f((1 3 2))=f((2 1 3))=f((2 3 1))=f((3 1 2))=f((3 2 1)). Any ideea how can I approch this problem ? I've tried doing the sum of squares of all elements but it turned out that there are ...

Re-adjusting a binary heap after removing the minimum element

After removing the minimum element in a binary heap, i.e. after removing the root, I understand that the heap must be adjusted in order to maintain the heap property. But the preferred method for doing this appears to be to assign the last leaf to the root and sift it down. I'm wondering why we don't take the lesser child of what used ...

What does ZIP stand for (the compression format, not the postal codes)

Does anybody know for what the acronym ZIP stands for which was and is used in programs like PKZIP and GZIP? There is a compression algorithm named Lempel-Ziv-Welch-Algorithm (LZW) maybe the guy named Ziv invented together with other people ZIP? I cannot find anything about it, maybe its not an abbreviation but instead it just means "to...

Implementing Naïve Bayes algorithm in Java - Need some guidance

hello stackflow people As a School assignment i'm required to implement Naïve Bayes algorithm which i am intending to do in Java. In trying to understand how its done, i've read the book "Data Mining - Practical Machine Learning Tools and Techniques" which has a section on this topic but am still unsure on some primary points that are...

[C++] std::string manipulation: whitespace, "newline escapes '\'" and comments #

Kind of looking for affirmation here. I have some hand-written code, which I'm not shy to say I'm proud of, which reads a file, removes leading whitespace, processes newline escapes '\' and removes comments starting with #. It also removes all empty lines (also whitespace-only ones). Any thoughts/recommendations? I could probably replace...

LaTeX package for writing algorithms

Hi all, which package would you use for writing algorithms in LaTeX? I know about algorithm, algorithmic and algorithms packages. Thanks ...

Balanced Search Tree Query, Asymtotic Analysis..

Hi, The situation is as follows:- We have n number and we have print them in sorted order. We have access to balanced dictionary data structure, which supports the operations serach, insert, delete, minimum, maximum each in O(log n) time. We want to retrieve the numbers in sorted order in O(n log n) time using onl...

Algorithm reductions

If I have a algorithm A that i have proven belongs to P can this algorithm also belong to the NPC class or is it strictly P? What about NP? P Belongs to NP right? Thx for any help! /Marthin ...

Algorithm Question.. Linked List..

Hi, Scenario is as follows:- I want to reverse the direction of the singly linked list, In other words, after the reversal all pointers should now point backwards.. Well the algorithm should take linear time. The solution that i have thought of using another datastructure A Stack.. With the help of which the singly linked list would ...

Writing a program to check if a graph is bipartite

Hi. I need to write a program that check if a graph is bipartite. I have read through wikipedia articles about graph coloring and bipartite graph. These two article suggest methods to test bipartiteness like BFS search, but I cannot write a program implementing these methods. Any help would be appreciated! ...