It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a set of 50 items and many conditions that specificy which element should come before other.
How to I create a ordered list?
Will like it in C# though can translate it from other languages.
Topological Sort
Translate the "many conditions" into a comparison function, and then use that in conjunction with a comparison-based sort (in the general case).
The best comparison-based sorting algorithms are O(nlogn) in the best case. Merge sort is one such algorithm and is pretty easy to implement... there are many others.
If your conditions constitute a partial ordering (rather than a total ordering), Topological sort might be most appropriate.
There are a number of sorting algorithms you can look into. The two that come to mind off the top of my head are the bubble sort and the quick sort.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
A sampling algorithm could output any real number in range [0,1],but the correct answer is in the range [0.1,0.2+x]("x" is in range [0,1]), the algorithm can output a correct answer with probability more than "0.8", then how to give a good answer with high probability? (such as run it many times, and pick the median as the right answer)
I think the question may be asking about the central limit theorem. If the samplings are independent and identically distributed, the OP could apply the classical form: Classical CLT
Otherwise, I recommend viewing the rest of the Wikepedia article to see if any of the other forms are applicable.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
What is the most efficient way to add an element to a sorted data structure?
Most red black tree packages will have an "insert element" method. If you're not using one already, it might be good to start.
If you're married to a red-black tree implementation that doesn't have an insert element operation, it'd be a good idea to add such a method, possibly from some good red-black tree doc:
http://en.wikipedia.org/wiki/Red%E2%80%93black_tree
BTW, a treap is often quite a bit faster than a red-black tree, but the red-black tree will likely have less variable performance:
http://stromberg.dnsalias.org/~strombrg/python-tree-and-heap-comparison/
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Can anyone suggest me a worst case "text string - pattern pair" for testing a KMP algorithm implementation?
I would say a pattern like
xx........x
| n times |
and a string like
xxx.........xyx...........xy....
| n-1 times | | n-1 times |
would be one of the worst cases, but it's still O(m+n)
You can find anything on KMP algorithm here :
KMP ALGORITHM
Quick extract :
Knuth, Morris and Pratt discovered first linear time string-matching
algorithm by following a tight analysis of the naïve algorithm.
Knuth-Morris-Pratt algorithm keeps the information that naïve approach
wasted gathered during the scan of the text. By avoiding this waste of
information, it achieves a running time of O(n + m), which is optimal
in the worst case sense. That is, in the worst case Knuth-Morris-Pratt
algorithm we have to examine all the characters in the text and
pattern at least once.
You should be able to calrify what you understand of the algorithm and find what you need there.
hope it helps
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
What is core algorithm of the genetic algorithm?
What needs to be defined precisely in order to code the algorithm?
You need to define:
The encoding for a solution (e.g. bitstring, tree, etc)
The fitness function - how to quantitatively evaluate the "goodness" of a solution
The crossover operator - a binary function that takes two parent solutions and combines them into a child solution
The mutation operator - a unary function that takes a solution and makes a small change (i.e. mutation) to it
Selection - how do you select individuals for the next generation? This includes the probabilities associated with crossover and mutation.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
As part of a library project, I want to include a plethora of generic algorithms and data structures. This includes algorithms for searching and sorting, data structures like linked lists and binary trees, path-finding algorithms like A*... the works.
Basically, any generic algorithm or data structure you can think of that you think might be useful in such a library, please post or add it to the list. Thanks! (NOTE: Because there is no single right answer I've of course placed this in community wiki... and also, please don't suggest algorithms which are too specialized to be provided by a generic library)
The List:
Data structures
AVL tree
B-tree
B*-tree
B+-tree
Binary tree
Binary heap
Binary search tree
Linked lists
Singly linked list
Doubly linked list
Stack
Queue
Sorting algorithms
Binary tree sort
Bubble sort
Heapsort
Insertion sort
Merge sort
Quicksort
Selection sort
Searching algorithms
Have you tried Wikipedia?
http://en.wikipedia.org/wiki/List_of_data_structures
http://en.wikipedia.org/wiki/List_of_algorithms
Algorithms, Data Structures.
There's already a resource for this sort of material. I'm voting to close as not a real question.