Efficient way to add element to sorted datastructure [closed] - algorithm

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/

Related

Lisp stack overflow bound [closed]

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.
I really need an advice. I have a function that have big number of recursive calls. Actually i need it. And algorithm is correct it works in C but in lisp there is a problem because of stack overflow. What should i do to solve it? How can i change algorithm to be able to work in lisp?
You have three options:
Rewrite the algorithm to be tail-recursive or, equivalently, iterative
Change the algorithm all together
Increase the lisp's stack size

Algorithm for ordering a set [closed]

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.

Core algorithm of genetic algorithm [closed]

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.

Insertion sort of items in array [closed]

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.
In plain English describe the algorithm for an insertion sort of items in an array.
I've also been asked to use diagrams if appropriate but that's a little hard on here I understand.
Here is a PDF presentation which describes insertion sort.
With a quick google search http://en.wikipedia.org/wiki/Insertion_sort

travelling salesman [closed]

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.
Where can I find source code for travelling salasman problem?
nowhere, it's not been solved.
You had mentioned that you were having problems with more than 8 or 9 nodes. This isn't surprising because the complexity increases exponentially with each added node.
As a result many solutions involve Genetic programming to gradually evolve a good answer. Finding the best generally requires a brute-force check of all possibilities.
One example is here, which also provides their source code.

Resources