I just posted two questions on Stack Overflow in which I also included answers:
How is it possible to do binary search on a doubly-linked list in O(n) time?
How is it possible to do binary search on a singly-linked list in O(n) time?
I was reminded of the algorithm that you would use for the first of these cases when a friend talk about this coming up during a job interview, and on my commute to work realized that the second of these was possible at all. I really like algorithms and data structures and thought it was nifty that it was possible to combine a fundamental algorithm and fundamental data structure in a way I hadn't seen before.
After posting these, both questions and their answers got downvoted and there was some discussion in the comments about whether it was appropriate to post these questions.
I have a few questions:
Was it in appropriate for me to post these questions with answers? This isn't the first time I've posted a question/answer pair (I actually like sharing things with SO this way), and I think that it's encouraged, but I wanted to double-check that this is the case.
Was this the right way for me to post these question/answer pairs? I posted these as separate questions because the algorithms in both cases are different, though they're closely-related. I figured that it would be useful to describe them separately to highlight the differences between the array/doubly-linked list case and the doubly-linked list/singly-linked list cases, though in retrospect that might not have been a good idea. Would it have been more appropriate to post a combined question that covered both cases?
Is there any recourse for the downvotes? I have a lot of reputation and don't care too much about the reputation points, but it's weird to get four downvotes in under a minute for question/answer pairs that I was really happy about.
Thanks everyone!