Live data from Hacker News

Ask HN: What are your favorite algorithms?

news.ycombinator.com

41–50 of 93 posts

Re: Ask HN: What are your favorite algorithms?

#41
post #34

Given the head of a linked list, how do you determine if it loops? eg, an l-shaped list is easy to determine - you simply process each element in the list until you find one without a subsequent element. But what if it's a 9-shaped linked list? You'll never run out of elements, so the best you could seem to do would be to store a reference to each element and check against all references to see if you've found a dupl…

Here's a visual representation of it:

https://visualgo.net/cyclefinding

Really cool!

Re: Ask HN: What are your favorite algorithms?

#44

I really like majority voting algorithm to get majority number in array which appears more then half of the elements, Its the most simplest and elegant algorithm i have studied http://www.geeksforgeeks.org/majority-element/

I'm surprised how the solution doesn't have the hashmap implementation of it, which gives out o(n) and is much more simple. But the algorithm is interesting though!

Re: Ask HN: What are your favorite algorithms?

#46
R* tree for indexing spatial data [1]. Also, if you enjoy spatial data structures, you can't go wrong with Samet's[2] _ The Design and Analysis of Spatial Data Structures_ and Applications of Spatial Data Structures_.

1: https://en.wikipedia.org/wiki/R*_tree

2: https://www.cs.umd.edu/~hjs/design.html

Re: Ask HN: What are your favorite algorithms?

#47

As basic as it is, and completely uninventive, I've always loved Dijkstra's algorithm. It was probably the algorithm that cemented my love of computer science, it's such an elegant solution to a problem and so simple once you understand it.

I was always thought it was a greedy way of doing a breadth first search.

Re: Ask HN: What are your favorite algorithms?

#48
post #34

Given the head of a linked list, how do you determine if it loops? eg, an l-shaped list is easy to determine - you simply process each element in the list until you find one without a subsequent element. But what if it's a 9-shaped linked list? You'll never run out of elements, so the best you could seem to do would be to store a reference to each element and check against all references to see if you've found a dupl…

[deleted]
Post reply on HN