algorithm

Simple/efficient text compression

What's the simplest, but efficient compression algorithm? Deflate, lzma, etc. aren't valid options. I need something that compiles really small, like: RLE, LZX, Huffman, etc.. Note: The data is 95% ASCII text Edit: Data is ~20kb at the moment, but i expect it to grow up to 1mb ...

Anyone Know a Great Sparse One Dimensional Array Library in Python?

I am working on an algorithm in Python that uses arrays of int64s heavily. The arrays are typically sparse and are read from and written to constantly. I am currently using relatively large native arrays and the performance is good but the memory usage is high (as expected). I would like to be able to have the array implementation not ...

Find three numbers appeared only once

In a sequence of length n, where n=2k+3, that is there are k unique numbers appeared twice and three numbers appeared only once. The question is: how to find the three unique numbers that appeared only once? for example, in sequence 1 1 2 6 3 6 5 7 7 the three unique numbers are 2 3 5. Note: 3<=n<1e6 and the number will range from 1 ...

Five unique, random numbers from a subset

I know similar questions come up a lot and there's probably no definitive answer, but I want to generate five unique random numbers from a subset of numbers that is potentially infinite (maybe 0-20, or 0-1,000,000). The only catch is that I don't want to have to run while loops or fill an array. My current method is to simply generate ...

question abouut string sort

i have question from programming pearls problem is following show how to use Lomuto's partitioning scheme to sort varying length bit strings in time proportional to the sum of their length and algorithm is following each record in x[0..n-1] has an integer length and pointer to the array bit[0..length-1] code void bsort(...

Formula for popularity? (based on "like it", "comments", "views")

I have some pages on a website and I have to create an ordering based on "popularity"/"activity" The parameters that I have to use are: views to the page comments made on the page (there is a form at the bottom where uses can make comments) clicks made to the "like it" icon Are there any standards for what a formula for popularity w...

Getting plane slices from array data

Greetings all, I read 3d grid data (from multiple TIF images) into a structure as follows : typedef struct VolumeData{ int nx; int ny; int nz; unsigned char *data; // size is nx*ny*nz } Now I want to get the plane slices from this 1-D grid data: eg: unsigned char* getXYPlaneStack(VolumeData *vol,int z); I could implement ab...

clique number of a graph

I would like to know a fast algorithm to find only the clique number(without actually finding the clique) of a graph with about 100 vertices. I am trying to solve the following problem. http://uva.onlinejudge.org/external/1/193.html ...

Move all zero values in a big array to its front portion in a Time Efficiency way

You're given a big array with Integral type value, How do you move all zero values within it to the front portion of the array in a Time Efficiency way? e.g. 0,1,72,3,0,5,9,0,6,51,0,3 ---> 0,0,0,0,1,72,3,5,9,6,51,3 Regards! ...

elastic / snaking line algorithm

Hi everyone I am making a graphics application in which I can edit a polyline by dragging the control point of it. However, I'd like to make it a bit easier to use by making it elastic; When dragging a control point, instead of moving a single point, I'd like the points within a certain distance of that point to be moved as well, depend...

Reduce text length to fit cell width in a smart manner

Hello, I am in project where we are building a simple web calendar using Java EE technologies. We define a table where every row is an employee, and every column represents an hour interval. The table width and column widths are adjustable. In every cell we have a text retrieved from a database, indicating what the employee is doing ...

Aligning music notes using String matching algorithms or Dynamic Programming

Hi I need to compare 2 sets of musical pieces (i.e. a playing-taken in MIDI format-note details extracted and saved in a database table, against sheet music-taken into XML format). When evaluating playing against sheet music (i.e.note details-pitch, duration, rhythm), note alignment needs to be done - to identify missed/extra/incorrect/...

What is a "Decentralized Uniqueness Algorithm"?

The function in COM to create a GUID (CoCreateGUID) uses a "Decentralized Uniqueness Algorithm", but my question is, what is it? Can anybody explain? ...

How to prove worst-case number of inversions in a heap is Ω(nlogn)?

I am busy preparing for exams, just doing some old exam papers. The question below is the only one I can't seem to do (I don't really know where to start). Any help would be appreciated greatly. Use the Ω(nlogn) comparison sort bound, the theta(n) bound for bottom-up heap construction, and the order complexity of insertion sort to show ...

How to optimize this simple function which translates input bits into words?

I have written a function which reads an input buffer of bytes and produces an output buffer of words where every word can be either 0x0081 for each ON bit of the input buffer or 0x007F for each OFF bit. The length of the input buffer is given. Both arrays have enough physical place. I also have about 2Kbyte free RAM which I can use for ...

Finding the closest match

I Have an object with a set of parameters like: var obj = new {Param1 = 100; Param2 = 212; Param3 = 311; param4 = 11; Param5 = 290;} On the other side i have a list of object: var obj1 = new {Param1 = 1221; Param2 = 212; Param3 = 311; param4 = 11; Param5 = 290;} var obj3 = new {Param1 = 35; Param2 = 11; Param3 = 319; param4 = 211; Pa...

java random percentages

I need to generate n percentages (integers between 0 and 100) such that the sum of all n numbers adds up to 100. If I just do nextInt() n times, each time ensuring that the parameter is 100 minus the previously accumulated sum, then my percentages are biased (i.e. the first generated number will usually be largest etc.). How do I do t...

Split String into smaller Strings by length variable

I'd like to break apart a String by a certain length variable. It needs to bounds check so as not explode when the last section of string is not as long as or longer than the length. Looking for the most succinct (yet understandable) version. Example: string x = "AAABBBCC"; string[] arr = x.SplitByLength(3); // arr[0] -> "AAA"; // ...

How to "smart resize" a displayed image to original aspect ratio

I have an application in which end-users can size and position images in a designer. Since the spec calls for the image to be "stretched" to the containing control, the end user can end up with an awkwardly stretched image. To help the user with image sizing I am thinking of implementing a smart resizer function which would allow the th...

Gradient algorithm produces little white dots

I'm working on an algorithm to generate point to point linear gradients. I have a rough proof of concept implementation done: GLuint OGLENGINEFUNCTIONS::CreateGradient( std::vector<ARGBCOLORF> &input,POINTFLOAT start, POINTFLOAT end, int width, int height,bool radial ) { std::vector<POINT> pol; std::vector<GLubyte> pdata(width *...