Write summaries of KMP Algorithm, Boyer-Moore string-search algorithm, Rabin-Karp Algorithm

Problem Statement

Given a search string and a pattern , we want to see if the pattern can be found in the string .

Naive Approach

The Naive implementation of the search algorithm will compare the pattern against all possible substrings of that length in the search string .

Therefore, the worst case time complexity is where the complete search space represents performing a comparison search in across all substrings in time.

This gives a time complexity which is equal to the product of the two strings.


Background

The Largest Divisible Subset problem is a great problem which embodies many critical concepts to more advanced interviewing problems such as Dynamic Programming and Backtracking. The high-level reason why Dynamic Programming is useful in the solution is that we are asked to find the maximum of a given computation. Many times, when a problem asks to optimize, this is a perfect candidate for Dynamic Programming. The high-level reason why Backtracking is useful in this problem is that we will be optimizing the subset length, while the problem asks us to return the resulting subset whose length is this optimal value…


Background

The Knapsack problem, according to Wikipedia, is one of the most studied problems in combinatorial optimization.

The general description of the knapsack problem is the following:

  • Given a set of items, where each item has an associated profit and a corresponding weight , perform a series of binary decisions to select a subset of items such that the profit is maximized while the cost is kept within constraints.

The name stems from the problem faced by someone who is picking items to put in his knapsack such that he fills the bag with the “best” items…


Background

I have been intrigued by Leet Code style questions for a while. I have been very inspired by channels like Back to Back SWE, who goes beyond the code to develop a deep understanding of what is happening.

This is my attempt to give back.

Problem Statement

Two City Scheduling — Prompt

The Two City Scheduling problem requires that you fly out people equally into 2 different cities, such that both cities have people. Differing costs are incurred by placing a person in either city. Thus, you want to design an algorithm that seeks the minimum cost.

Approach

While Leet Code defines this problem as Easy, it…

Adam Garcia

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store