algorithm

Uncrossed Sequence Calculation

From http://discuss.joelonsoftware.com/default.asp?interview.11.794054.1 The sequence A is defined as follows: Start with the natural numbers 1,2,3,... Initialize count = 1; while(there are uncrossed numbers) { pick the first uncrossed number say n. set A[count] = n. Cross out the number count+n. Cro...

Permutation of an arraylist objects

Hello friends, I have an arraylist which contains some objects and i have to get permutation of that objects?How can i do that? Suppose MyList is an arraylist which contains 4 objects. ArrayList myList = new ArrayList(); myList.Add(1); myList.Add(2); myList.Add(3); myList.Add(4); so arraylist count is 4 so i want 4!=24 I want 24 per...

How to automatically exclude items already visited in recommendation algorithm?

I'm now using slope One for recommendation. How to exclude visited items from result? I can't do it simply by not in (visited_id_list) to filter those visited ones because it will have scalability issue for an old user! I've come up with a solution without not in: select b.property,count(b.id) total from propertyviews a ...

fast index for "contains string"

I n my application i have upt o millions of short strings (mostly shorter than 32 characters). I want to implement a search box with a attached list that contains only elements that contain the whole string entered in the search box. How can i prebuild a index to find such strings fast? All sorted STL containers check the whole string. ...

How did you practically use recursion?

How did you practically use recursion? I mean practical problems you had to solve in day to day programming, be that for work or for pleasure. Not school tasks/homeworks but something you did for yourself or others. The ones where I used it myself are: drawing some fractals traversing directory tree to search for a file traversing the ...

Is there any Algorithm for converting Image histograms into original image?

So we have Histograms... Is there any algorithm to generate original image from them? ...

Nearest point on concave surface from point

Given a union of convex objects and a point p inside this union, how does one find the closest point on the (concave) surface of the union from p? For what it's worth I can easily find the closest point on the surface of a single convex object, it's the union of several that's giving me problems. EDIT: I'm terribly sorry, I meant the u...

Algorithm for Gift Card Codes

I recently posted this question about codes for a gift-card-like voucher that users can redeem online. I wanted to find the best tradeoff between large keyspace, low guessability, and human readability. Now that I'm into implementation I realize I've got another problem altogether, more of an algorithmic challenge. Let's assume I adop...

Student Time scheduling algorithm

Hello, I need to find an algorithm to find the best time to meet up for lets say a study group. The system has information about a group of students and their class schedules. The system should give a time for meetup, where there is no conflict with anyone's class schedules. what would be the best way attack this problem. I was looking f...

How can I get all possible permutations of a list with Common Lisp?

I'm trying to write a Common Lisp function that will give me all possible permutations of a list, using each element only once. For example, the list '(1 2 3) will give the output ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 1 2) (3 2 1)). I already wrote something that kind of works, but it's clunky, it doesn't always work and I don't even real...

How to Seek Audio/Video Data with Variable Bitrate (VBR)?

This might be a way too generic question, but what is the general approach for seeking within media files (video or audio of any kind/format) if the data has variable bitrate (VBR)? It seems an easy thing to do if the stream has a constant bitrate (CBR). E.g. if you know it is 256 kbit/s and you want to seek forward/backward by 30 secon...

Algorithm for finding potential matches

I need to find and algorithm to find the best matches in a social network. The system is a college student social network, and basically the main idea is to find a study partner for a class. The idea it's to suggest to the user what are the potential best partners based on different criteria, such as common class, GPA, rating, common sch...

Non axis-aligned rectangle intersection

I'm trying to find an algorithm that will compute the intersection between 2 rectangles, which are not necessarily axis-aligned, and return the resulting intersection. This question describes finding whether an intersection exists. I'd like to have the resulting shape of the intersection, if it exists. My application of the algorithm w...

Word Wrap algorithms for Japanese

In a recent web application I built, I was pleasantly surprised when one of our users decided to use it to create something entirely in japanese. However, the text was wrapped strangely and awkwardly. Apparently browsers don't cope with wrapping japanese text very well, probably because it contains few spaces, as each character forms a w...

Algorithm for Generating Symmetric Pictures

Hi I just joined and have a simple question. You know the patterns that we get when we join? Does anyone have an algorithm or program to generate them? I am also interested in progrms or algorithms that can generate "Mandalas" (Tibetan or Buddhist). I am nor sure what makes a picture a mandala, except that usually they are approximately ...

Algorithm to layout rectangle windows in 2D display

I'm seeking for an algorithm to layout rectangle windows, the requirements are like below: All windows to be layout can be seen as small rectangles. All windows must be layout in a rectangle 2D display, and the display width and height is given. There are several dozen windows to be layout. Each window has an initial position (x,y) and...

What is the most clever and easy approach to sync data between multiple entities?

In today’s world where a lot of computers, mobile devices or web services share data or act like hubs, syncing gets more important. As we all know solutions that sync aren’t the most comfortable ones and it’s best not to sync at all. I’m still curious how you would implement a syncing solution to sync between multiple entities. There ar...

Creating a composite Shape in Java 2D

Using Java 2D I've patched several Bezier curves (CubicCurve2D) together to create a "blob". The problem I now face is how to: Efficiently fill the blob with a given colour. Efficiently determine whether a given point lies inside the blob. I noticed thst CubicCurve2D implements Shape which provides numerous contains methods for dete...

What is the algorithm for parsing expressions in infix notation?

I would like to parse boolean expressions in PHP. As in: A and B or C and (D or F or not G) The terms can be considered simple identifiers. They will have a little structure, but the parser doesn't need to worry about that. It should just recognize the keywords and or not ( ). Everything else is a term. I remember we wrote simple ari...

optimizing byte-pair encoding

Noticing that byte-pair encoding (BPE) is sorely lacking from the large text compression benchmark, I very quickly made a trivial literal implementation of it. The compression ratio - considering that there is no further processing, e.g. no Huffman or arithmetic encoding - is surprisingly good. The runtime of my trivial implementation ...