algorithms on NucuLabs
https://blog.nuculabs.dev/tags/algorithms/
Recent content in algorithms on NucuLabsNucuLabshttps://blog.nuculabs.dev/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E
https://blog.nuculabs.dev/%3Clink%20or%20path%20of%20image%20for%20opengraph,%20twitter-cards%3E
Hugo -- gohugo.ioen-usMon, 03 Jun 2024 00:00:00 +0000Ranking: BM25+
https://blog.nuculabs.dev/posts/2024/2024-06-03-dsa-ranking-bm25/
Mon, 03 Jun 2024 00:00:00 +0000https://blog.nuculabs.dev/posts/2024/2024-06-03-dsa-ranking-bm25/Introduction The BM25+ is a ranking algorithm used to rank text documents based on a relevance score.
It is used in search engines to determine which documents are the most relevant given a terms query.
The algorithm implemented is based on the Improvements to BM25 and Language Models Examined paper.
Implementation An index can be used to index the terms and the documents in which the terms occur:
[term: apples] - doc1, doc2, doc3 [term: grapes] - doc2, doc4 When a user queries using the apples term then doc1, doc2 and doc3 is returned.The Linked List
https://blog.nuculabs.dev/posts/2024/2024-04-17-dsa-linked-list/
Wed, 17 Apr 2024 00:00:00 +0000https://blog.nuculabs.dev/posts/2024/2024-04-17-dsa-linked-list/Introduction A linked list is a fundamental data structure which consists of Nodes that are connected to each other.
Other variations are:
Double linked list Circular linked list (circular buffer) The Singly Linked List To visualize the data structure, if you want to store two integers 10 and 20 you will have a 2 node linked list that will have: [Node 1, Value 10] -> [Node 2, Value: 20] -> [null]Tail Recursion
https://blog.nuculabs.dev/posts/2021/2021-07-03-tail-recursion/
Sat, 03 Jul 2021 22:32:20 +0000https://blog.nuculabs.dev/posts/2021/2021-07-03-tail-recursion/Hello everyone! ðŸ‘‹
Todayâ€™s article will be about tail recursion, a technique that allows you to optimize certain recursive functions.
Introduction In short, when you write a recursive function, each new call it does allocates a frame onto the stack. For example, let us take this following function:
private static long RecursiveFib(long n) { if (n <= 1) { return n; } return RecursiveFib(n - 1) + RecursiveFib(n - 2); } If we set a breakpoint at return n and call the function with RecursiveFib(10), we will get the following stack frame.LeetCode: Reverse Linked List Solution and Explanation
https://blog.nuculabs.dev/posts/2020/2020-11-17-leetcode-reverse-linked-list-solution/
Tue, 17 Nov 2020 22:59:44 +0000https://blog.nuculabs.dev/posts/2020/2020-11-17-leetcode-reverse-linked-list-solution/Hi,
In this article I will explain my solution for the following LeetCode problem: Reverse Linked List.
If youâ€™re interested in solving this problem then please try to spend at least one hour or more on it before looking at my solution.
To help you solve this problem Iâ€™ve created the following table:
Current Prev 1 NULL 2 1 3 2 NULL 3 Think about how you can use this table to write an iterative or recursive algorithm that reverses the linked list.LeetCode: Find The Town Judge
https://blog.nuculabs.dev/posts/2020/2020-05-11-leetcode-find-the-town-judge/
Mon, 11 May 2020 20:05:11 +0000https://blog.nuculabs.dev/posts/2020/2020-05-11-leetcode-find-the-town-judge/Hello
In this article I will present you my Python3 solution for the following problem which I found on LeetCode: find-the-town-judge.
Note: The solution is on the second page, so you wonâ€™t get spoiled if you want to attempt to solve the problem by yourself. Have fun!
from collections import defaultdict from typing import List """ In a town, there are N people labelled from 1 to N. There is a rumor that one of these people is secretly the town judge.