Questions for algorithm


Reversing a sub-array of an array , in less than O(n) time

how can we reverse a subarray ( say from i-th index to j-th index ) of an array ( or any other data structure , like linked-list ( not doubly )), in less than O(n) time ? the O(n) time consumption is

Programming Challenge: Easiest way to code this grid?

Made It! Look at bottom of the post!!!

Efficient algorithm to find all the paths from A to Z?

With a set of random inputs like this (20k lines):

How to design a latest recently used cache?

How to design a latest recently used cache?

Algorithm for determining which words make a phrase popular

Suppose I had a list of slogans (short, multi-word phrases), and people had voted for the ones they liked best, and I wanted to assess which words, if any, made some slogans more popular than other...

How does the Google “Did you mean?” Algorithm work?

I've been developing an internal website for a portfolio management tool. There is a lot of text data, company names etc. I've been really impressed with some search engines ability to very quickly

SQL query to get neighbours from table with two dimensional data

I have a table, that contains partitioning of world map. Partition is done by splitting all area into rectangles, called 'tile'. As usual, rectangle has bottom-left and upper-right corners, both re...

Knapsack problem with all profits equal to 1

There is a variation of knapsack problem when all profits are equal to 1. It seems it can be solved much faster than classical discrete (0-1) knapsack problem, but how? Will just greedy algorithm w...

What is exactly mean log n height?

I came to know the height of Random-BST/Red-Black trees and some other trees are O(log n).

Same result from K-means and sequential K-means?

Do we obtain the same result if we apply K-means and sequential K-means methods to the same dataset with the same initial settings? Explain your reasons.

How does “Find Nearest Locations” work?

Nowadays most of the Restaurants and other businesses have a "Find Locations" functionality on their websites which lists nearest locations for a given address/Zip. How is this implemented? Matchin...

Algorithm to determine the “usual” cash payment amounts for a given price

You walk into a store, select several products, then go to the counter to pay your bill. The total is some amount (A). You reach into your wallet, purse, or pocket and put down some cash (P), where...

How to search common passwords from two given files of size 20GB?

i have two files of size 20GB. i have to remove common passwords from either of one file.

How can i diff two trees to determine parental changes?

I've got a tree structure that I need to rearrange (drag and drop) and then submit the changes.

Balancing a ternary search tree

How does one go about 'balancing' a ternary search tree? Most tst implementations don't address balancing, but suggest inserting in an optimal order (which I can't control.)

What algorithm can be used to find the optimal solution for this?

I have accounts with positive and negative balance and a pledge relationship between some. A pledge gives accounts with negative balance the right to retrieve money from the pledging account to cover

Problems with an Algorithm

I have the following 5 lines of string:

Sort numbers by sum algorithm

I have a language-agnostic question about an algorithm.

data structure for Graph in java

i am looking to implement a algorithm for the Travel Salesman Problem. I want to model the solution using the graph , in this a vertex will represent a city and edge will represent the cost from on...

How would rating system be done for users in a web application?

I am implementing a web application that has many users and I would give the users rating based on their activities and based on other users liking their activities. How would I implement such an

What algorithm does Excel use to recalculate formulas?

Are the formulas represented in a syntax tree then recalculated using a design pattern like the Visitor pattern? How would you go about reproducing the recalculation process in code?

Algorithm: array of arrays in Cocoa Touch (perhaps using NSCountedSet)

This one is a bit tedious in as far as explaining, so here goes. I'm essentially populating a tableView on the iPhone with multiple sections, and potentially multiple rows per section. To my

Find max sum of elements in array

Write a program which by given array of integer values (containing negative integers) finds the maximum sum of successive elements in the array.

Algorithm to partition a number

Given a positive integer X, how can one partition it into N parts, each between A and B where A <= B are also positive integers? That is, write

Plain English explanation of Theta notation?

What is a plain English explanation of Theta notation? With as little formal definition as possible and simple mathematics.

Which Data Mining Algorithm is the best?

Long time listener, first time caller.

How to keep a random subset of a stream of data?

I have a stream of events flowing through my servers. It is not feasible for me to store all of them, but I would like to periodically be able to process some of them in aggregate. So, I want to ...

Recording a maze path solution with a stack

I am to generate a solution to a maze using a linked list implementation of a stack in some way. The maze is read in from a .txt file and consists of 0's for open spaces and 1's for walls.

Chord detection algorithms?

I am developing software that depends on musical chords detection. I know some algorithms for pitch detection, with techniques based on cepstral analysis or autocorrelation, but they are mainly fo...

Point in vertex defined box algorithm?

How would I test if a point is within a 3D box that is defined by its 8 points only or by its 6 quads? (Dont have access to normal vectors)

Find phrase that has a specific length and is composed by certain letters

Suppose I have a list of 1 million words. I have the length of the phrase that I need to find, and I know that this word can be composed of at most 3 other words, for example Queen of England, has 14

Which one is the real Bubble Sort, and which one is better?

I had an argument with a friend about the real bubble sort of the following two algorithms, and about which one is better, no mention which one is mine, I just want to hear your answers on these two

time complexity of function in terms of Big-O notation?

1) Althoug i have studied about the big O notation i couldn't understand how we calculate the the time complexity of this function in terms of Big-O notation. Can you explain in detail.

C++ inserting a line into a file at a specific line number

I want to be able to read from an unsorted source text file (one record in each line), and insert the line/record into a destination text file by specifying the line number where it should be inser...

Loops in C challenge: can it be done another way?

Hi all C experts (please don't shoot, I'm no C programmer anymore but from time to time I have a question that pops in my mind)

Graph Paths Abstraction Algorithm Needed

I have a data structure holding a graph like the one in the following picture:

Find all possible subsets that sum up to a given number

I'm learning Python and I have a problem with this seems to be simple task.

How to choose randomly in a certain ratio

I want to choose randomly* between two alternatives with unequal probability.

How can I simplify this code? (Chess game obstruction testing)

I'm making a chess game in Java, and testing to make sure there are no pieces blocking the path of the piece being moved. The piece moves from (srcX,srcY) to (dstX,dstY).

Anomaly Detection Algorithms

I am tasked with detecting anomalies (known or unknown) using machine-learning algorithms from data in various formats - e.g. emails, IMs etc.

Artificial Neural Network Question

Generally speaking what do you get out of extending an artificial neural net by adding more nodes to a hidden layer or more hidden layers?

Algorithmical issue with point inside circle

I have a question [ silly - I admit ] about finding wherether the point is in the circle or not, I have a coordinates of the center of circle, and I know the equation, but I'm having the problem with

Tribonacci series with different initial values

How to find nth tribonacci number with matrix multiplication method if the initial values are some arbitrary numbers say 1, 2 3 i.e T(1) = 1, T(2) =2 and T(3) = 3.

Choosing an attractive linear scale for a graph's Y Axis

I'm writing a bit of code to display a bar (or line) graph in our software. Everything's going fine. The thing that's got me stumped is labeling the Y axis.

Range tree construction

Let us consider the following picture

If radix tries (or say HAT tries) are so good for storing & managing strings, why can't they be used just as well for integers?

I'm assuming they can, just treating a number by it's 32 (or 64) bit binary "string", for example. And in this case, are hash tables (say cache conscious hash tables) still on top of things when it...

Machine learning: Supervised learning to learn & predict next RSA code

I was going through Andrew NG's machine learning course. I am still at the beginning stages.

Avoiding dead-ends in Battleships random placement algorithm

I need some advice about building an algorithm for placing a number of ships on a board according to the rules that ships cannot overlap or touch (even diagonally). In what way could I ensure I still

What implementation of average is the most accurate?

Given those two implementations of the average function:

Determine if two rectangles overlap each other?

I am trying to write a C++ program that takes the following inputs from the user to construct rectangles (between 2 and 5): height, width, x-pos, y-pos. All of these rectangles will exist parallel ...

Improving counting of word frequencies with hashmap

For one of my applications, the following function has to be called very often. This function takes up a lot of CPU and hence I am wondering if you know how to improve the performance.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.