Advanced algorithm

  • Circle detection: Floyd's Tortoise and Hare

  • Find majority: Boyer-Moore Algorithm

Floyd's Tortoise and Hare

quesions

https://leetcode.com/problems/linked-list-cycle-ii/description/ https://leetcode.com/problems/find-the-duplicate-number/description/

explanation

Boyer-Moore Algorithm

questions

https://leetcode.com/problems/majority-element-ii/description/

explanation

https://gregable.com/2013/10/majority-vote-algorithm-find-majority.html

KMP

1) build pattern table; 2) match them https://www.youtube.com/watch?v=GTJr8OvyEVQ&t=632s https://leetcode.com/problems/implement-strstr/description/ https://leetcode.com/problems/repeated-substring-pattern/description/ https://leetcode.com/problems/shortest-palindrome/description/

Kadane's algorithm (maximum subarray sum)

https://leetcode.com/problems/maximum-subarray https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/description/

A* search - n-puzzle problems

Binary Indexed Tree

BIT explain: https://www.topcoder.com/thrive/articles/Binary%20Indexed%20Trees Key: one index is responsible for storing value representing a previous range, which is (index - getLSB(index), index]. E.g. index 12(1100) is responsible for (8, 12], i.e. (1000, 1100].

https://leetcode.com/problems/range-sum-query-mutable/description/ https://leetcode.com/problems/range-sum-query-2d-mutable/description/

https://leetcode.com/problems/reverse-pairs/description/ https://leetcode.com/problems/count-of-smaller-numbers-after-self https://leetcode.com/problems/count-of-range-sum

Last updated

Was this helpful?