algorithm

A clean algorithm for sorting a objects according to defined dependencies?

Given a list of classes inheriting from this base: class Plugin(object): run_after_plugins = () run_before_plugins = () ...and the following rules: Plugins can provide a list of plugins that they must run after. Plugins can provide a list of plugins that they must run before. The list of plugins may or may not contain all pl...

What is the Average Big-Ο complexity of Gnome sort?

There is nothing about it in wikipedia. Anyone knows that? I only want to know the average Big-O Complexity of that algorithm. ...

time complexity of variable loops

hi, i want to try to calculate the O(n) of my program (in python). there are two problems: 1: i have a very basic knowledge of O(n) [aka: i know O(n) has to do with time and calculations] and 2: all of the loops in my program are not set to any particular value. they are based on the input data. ...

Efficient algorithm for detecting matches

I'm looking for an efficient algorithm for detecting equal values in an array of integers N size. It must return the indices of the matches. Alas, I can't think of anything more clever then brute force with two loops. Any help will be appreciated. Thanks! ...

Comparing a string with several different strings

I want to compare one string with many strings. How is that done in C#? ...

SQL Server, T-SQL is there a faster way to substring the following string in my question?

I have strings like OPEN SYSTEMS SUB GR (GM/BTIB(1111)/BTITDBL(2222)/BTVY(4444)/ACSVTYSAG) in my database under my GROUPS Column. What I want to do is to extract the 2222 from that string. The code I am using is like that. SELECT SUBSTRING(GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS, CHARINDEX('(',GROUPS,0)+1)+1...

Where can I find source or algorithm of Python's hash() function?

>>> hash("\x01") 128000384 >>> hash("\x02") 256000771 >>> hash("\x03") 384001154 >>> hash("\x04") 512001541 Interesting part is 128000384 x 2 is not 256000771, and also others I am just wondering how that algorithm works and want to learn something on it. Thanks in advance. ...

Finding three elements in an array whose sum is closest to an given number

Given an array of integers, A1, A2, ..., An, including negatives and positives, and another integer S. Now we need to find three different integers in the array, whose sum is closest to the given integer S. If there exists more than one solution, any of them is ok. You can assume all the integers are within int32_t range, and no arithme...

Reverse a singly-linked list with and without using recursion

I am new to data structures, and I know this is a very common question to ask. But I know LinkedList in .NET is doubly-linked, so how I will write code for a singly-linked list in C#. Could someone please write sample code? ...

Interview question: C program to sort a binary array in O(n)

I've comeup with the following program to do it, but it does not seem to work and goes into infinite loop. Its working is similar to quicksort. int main() { int arr[] = {1,1,0,1,0,0,0,1,0,1,0,1,0,1,0,1,0,1}; int N = 18; int *front, *last; front = arr; last = arr + N; while(front <= last) { while( (front < last) && (*front == 0...

Transmitting hand-written information over a network

A teacher is writing on a blackboard and we want to pass all the information on the blackboard over a low-bandwidth network in real-time. How do we do it? In one interview, I faced this question. ...

Write a function that compares two strings and returns a third string containing only the letters that appear in both

Hi All, I got this homework. And have solved it in following way. I need your comments whether it is a good approach or I need to use any other data sturcture to solve it in better way. public string ReturnCommon(string firstString, string scndString) { StringBuilder newStb = new StringBuilder(); if (firstString...

Open-form and Closed form

How can an open-form of recurrence be converted into its equivalent closedform. Furthermore, what are some commonly used closed-forms that are usually used efficiently. ...

write a function to divide a number by 3 without using /, % and * operators . itoa() avalable ?

I tried myself to solve but I could not get any clue. Please help me to solve this. ...

What is the best algorithm to find a doublet / word ladder?

Is there an efficient algorithm to find a doublet/word ladder? It can be done brute force, but there has to be a better way to do it. How? http://en.wikipedia.org/wiki/Word_Ladder ...

Big Numbers, Common Algorithms?

I was wondering what big numbers are, and what are some common algorithms used to handle them. I heard this term mentioned in Coders at Work, where one was asked in an interview to create a library to work with big numbers. ...

How can I verify lock-free algorithms?

In theory, it should be possible to at least brute force a verification of a lock-free algorithm (there are only so many combinations of function calls intersecting). Are there any tools or formal reasoning processes available to actually prove that a lock-free algorithm is correct (ideally it should also be able to check for race condit...

Network and Graph theory problem

You have N computers and [Ca, Cb] means a is connected to b and this connectivity is symmetric and transitive. The problem is to write a program which checks that all computers are interconnected and talk to each other. A time efficient algorithm is preferable. ...

C# help to set a Row Css class of a Grid View

Hello All, I need to alternate row colors in a grid, but not on every other row. I have a variable _AddDate that I can check on the GridRowBound event. If it hasn't changed, I want to apply one css class and if it has I want to apply a different class. The code I have does almost exactly what I want but I am setting the class on the row ...

I need a cycle which iterates through dates interval

I have the start date and the end date. I need to iterate through every day between these 2 dates. What's the best way to do this? I can suggest only something like: Date currentDate = new Date (startDate.getTime ()); while (true) { if (currentDate.getTime () >= endDate.getTime ()) break; doSmth (); currentDate = new Da...