LRU Implementation in Kotlin

LRU (Least Recently Used) is a caching algorithm used in computer memory management, where the least recently used items are discarded first. In other words, it maintains a cache of a fixed size and when the cache is full, the least recently used item is removed to make room for new items. LRU is a … Read more

Fractional Knapsack in Kotlin

Fractional Knapsack is a type of knapsack problem where an algorithm is designed to find the maximum possible value that can be obtained by filling a knapsack of a given capacity with a set of items that have individual weights and values. The key difference between the Fractional Knapsack problem and the 0/1 Knapsack problem … Read more

Spiral Matrix Traversal in Kotlin

A spiral matrix is a matrix of m rows and n columns with each cell containing an integer value. The traversal of a spiral matrix is a way of visiting every cell in the matrix in a spiral order, starting from the top-left corner and moving in a clockwise direction. To traverse a spiral matrix, … Read more

Rope Cutting Problem in Kotlin

The rope cutting problem is a classic problem in mathematics and computer science that involves cutting a rope into pieces of a certain length. The problem is usually stated as follows: Given a rope of length L, and a set of integers representing the desired lengths of the pieces, what is the minimum number of … Read more

Josephus problem in Kotlin

The Josephus problem is a classic puzzle that involves a group of n people arranged in a circle. The problem is named after the Jewish historian Flavius Josephus, who according to legend, had to use this strategy to avoid being captured and killed by the Romans during the Jewish-Roman War. The problem statement is as … Read more

KMP algorithm in Kotlin | Knuth-Morris-Pratt

The Knuth-Morris-Pratt (KMP) algorithm is a string-matching algorithm that efficiently finds occurrences of a pattern string within a larger text string. It was developed by Donald Knuth, Vaughan Pratt, and James Morris in 1977 and is considered to be one of the most efficient string-matching algorithms. The basic idea behind the KMP algorithm is to … Read more

Rabin-Karp algorithm in Kotlin

The Rabin-Karp algorithm is a string searching algorithm that finds the occurrence of a pattern string P in a text string T with a time complexity of O(n+m), where n is the length of T and m is the length of P. The algorithm uses hashing to efficiently compare the pattern with substrings of the … Read more