In computer science, an in-place algorithm is an algorithm which transforms input using no auxiliary data structure. However a small amount of extra storage space is allowed for auxiliary variables. The input is usually overwritten by the output as the algorithm executes. In-place algorithm updates input sequence only through replace or swapping of elements. An algorithm which is not in-place is sometimes called not-in-place or out-of-place.
In-place can have slightly different meanings. In its strictest form, the algorithm can only have a constant amount of extra space, counting everything including...
@orlp If I've understood this correctly, I don't think so. Suppose we have [1,2,3,4] and [5,6,7,8]. Then getting [1,2,3,4,5,6,7,8] is probability (1/2)^4 since after that you must take from the other list, but [1,2,3,5,6,7,8,4] is (1/2)^3 * (1/2)^4
def shuffle(li):
l = len(li)
if l == 1: return li
a = shuffle(li[:l//2])
b = shuffle(li[l//2:])
r = []
while a or b:
if random.random() <= len(a) / (len(a) + len(b)):
r.append(a.pop())
else:
r.append(b.pop())
return r
getting the length of a doubly linked list and splitting it up in two is O(n), but is only done once, not in a loop
@NathanMerrill what about nondeterministic runtimes?
Quicksort may take only $\Theta(n\log n)$ time in worst case if one employs a linear-time algorithm to find the median as the pivot. Of course, randomized quicksort has a better practical performance usually. — BangyeJan 6 '15 at 19:04
although you might want to post it to cs.stackexchange.com to maybe see if someone can prove that for you (but be prepared to be very specific about your memory limits, computation model and linked list, or it's impossible to answer)
Hi. I have answered a challenge, in C, using this as output format: f(a,b,c)int*b;{...} where f is called using only two arguments. I have copied this trick off someone else's answer to some different challenge. My question is: has anyone seen this used a lot in C answers - is it old hat? (Otherwise, I am going to search for that specific answer where I have seen it, to give credit to the author.)
I mean, instead of a return statement, you pass a pointer as the second argument when you call the function. That will contain the result after the function call is completed.
How would one include a "classic" Lenny face in a LaTeX document?
A paper is due tomorrow and I am curious. e.g. ( ͡° ͜ʖ ͡°)
I have attempted to use the verbatim environment but it has proved fruitless.
If you can wrap them in a common parent it is as simple with just CSS, no JavaScript is needed.
CSS:
#sidebar {
display: none;
}
.cart:hover #sidebar {
display:block;
}
HTML:
<div class="cart">
<img src="images/cart.jpg" width="80px" height="30px" />
<div id="sidebar">some t...
My electric garage door works like this:
There is just one push button to control the door
If the door is fully closed and I hit the button, the door starts to open. It takes 10 seconds to open fully
If the door is fully open and I hit the button, the door starts to close. It takes 10 seconds...
Shortest paths in a divisor graph
code-golf number-theory graphs
Introduction
In this challenge, we will be dealing with a certain infinite undirected graph, which I call the high divisor graph.
Its nodes are the integers starting from 2.
There is an edge between two nodes a < b if a divides...
Implement the Maximize Affirmed Majorities voting system
code-golf
There are many different voting systems in existence. Different voting systems have different mathematical properties, which serve to describe the "positive features" of that system. Here is an informative list of these proper...
ok. So if I want to turn a "top candidate" algorithm into a "sorted candidates" algorithm, after I've run my affirm function, I need to find the top candidate(s), remove them, find the next candidate(s), and so on?
Functional Programming in Your Language
A lot of modern programming languages allow some form of functional programming, but I don't often see them used. I'm curious to see how different languages tackle problems that are naturally solved with some form of functional programming. The winning ent...
I don't have a suggestion, but since the name clashes somewhat with the help tour, perhaps someone else could think of something catchy and meaningful? — trichoplax2 mins ago