Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

Questions tagged [algorithm]

An algorithm is a sequence of well-defined steps that define an abstract solution to a problem. Use this tag when your issue is related to algorithm design.

Filter by
Sorted by
Tagged with
0 votes
0 answers
4 views

bubble sort algorithm with nested loops performs better than with one loop JS

Here are 2 bubble sort algorithms: 1: ...
user avatar
2 votes
1 answer
431 views

The smallest positive number that is evenly divisible by all of the numbers from 1 to 20

Problem description: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of ...
user avatar
0 votes
0 answers
60 views

Sieve of Atkin C#

I don't fully understand how to make the Sieve of Atkin faster than the most ancient sieve. All implementations I found online where slower than the one I made, but still It isn't faster than ...
user avatar
0 votes
0 answers
5 views

Barabási–Albert model : Exponent value is not coming right as suggested by theoretical suggestion [closed]

i'm writing code for Barabási–Albert(BA) model, i checked the degree distribution its power law but the exponent gamma is (1.5) and the condition it should be between (2-3), can anyone tell me what ...
user avatar
0 votes
1 answer
62 views

Can I optimize my implementation of generating Fibonacci series using recursion?

My function accepts a number, which generates total Fibonacci numbers. I am using recursion. Please follow the code below, ...
user avatar
3 votes
1 answer
218 views

Kosaraju's algorithm in C simple implementation

I am wondering can I please get some feedback for my simple implementation of the Kosaraju algorithm. More specifically how I de-allocate the things I allocated using ...
user avatar
  • 359
1 vote
3 answers
72 views

Calculating square roots using binary search

I'm trying to find the square root of a number (num) using binary search in Rust. I'm new to Rust, but I've done quite a bit of programming in other languages, ...
user avatar
  • 111
0 votes
0 answers
42 views

Generates all pairs (combinations of 2) up to a limit (exclusive)

Any improvements on this combination generator. Seen a lot of combination generators online, but none like this. Found pseudocode at: https://www.baeldung.com/cs/generate-k-combinations Fastest I ...
user avatar
-1 votes
0 answers
27 views

CommonPrimeDivisors task from codility [closed]

I'm working on the following task from Codility: A prime is a positive integer X that has exactly two distinct divisors: 1 and X. The first few prime integers are 2, 3, 5, 7, 11 and 13. A prime D is ...
user avatar
2 votes
0 answers
33 views

Algorithm for solving `subsequence with highest win rate`

Problem Inputs: 1. min length of subsequence 2. binary sequence outputs: 1. starting index of sequence 2. subsequence length The task is to find a subsequence ...
user avatar
1 vote
3 answers
72 views

Printing the first n numbers of the Fibonacci sequence

I have written a code below for printing the first n fibonacci numbers, the code is as follows ...
user avatar
0 votes
0 answers
40 views

dataset anonymizing algorithm implementation with Spark

I am trying to implement the following algorithm in Spark / Java: https://en.wikipedia.org/wiki/K-anonymity. My code class is the following: ...
user avatar
2 votes
0 answers
28 views

JavaScript Linter in Java

I wrote a simple Linter that checks for matching opening and closing braces for one line of JavaScript. It utilizes a stack to store opening braces found in the line, then compares the first closing ...
user avatar
1 vote
1 answer
63 views

Solution to arithmetic arranger from freecodecamp

I tried my hand at the freecodecamp python algorithm and I came up with a solution for the first question but need help refactoring it. Here is the arithmetic arranger question click here to access ...
user avatar
  • 113
1 vote
0 answers
141 views

Golang function that reads S3 files and populates maps with strings as keys

I have a below read function which is called by multiple go routines to read s3 files and it populates two concurrent map as ...
user avatar
  • 169
1 vote
1 answer
42 views

Number of paths in a randomly labeled complete graph

I have a complete graph with n vertices, set W (let's say W = {1,2,3}) and a path ...
user avatar
  • 13
1 vote
1 answer
43 views

Calculate the value of PI in JS

I have created an algorithm which calculates the value of PI in JavaScript. Can this algorithm to be improved? ...
user avatar
  • 153
2 votes
2 answers
118 views

Find all pairs of natural numbers whose sum is 12

I have been given the following task to complete. I am not sure if my solution is the most efficient. Are you able to take a look and suggest any changes? task: An application that finds all pairs of ...
user avatar
  • 21
4 votes
1 answer
88 views

Case-insensitive sort in C

I wrote a sorting program so that if the optional argument -i is present then the sorting should be done without taking into account lowercase / uppercase letters. ...
user avatar
  • 179
0 votes
0 answers
11 views

Functional Fibonacci in OCaml

I'm very new to OCaml, and as an exercise I decided to implement the nth Fibonacci algorithm (return a specific Fibonacci number, given an index) in different ways, using what I've learned so far. I ...
user avatar
  • 729
3 votes
1 answer
55 views

Topological Sort C++

Comments on optimizing the code or improving the code are requested. The input parameters to the class constructor are a one dimensional array of job ID's and the second argument is a list of vectors ...
user avatar
-1 votes
0 answers
59 views

Calculate board positions after each move in tic tac toe

In a game of tic tac toe I am trying to calculate all board positions after every move. We make the following assumptions. X always goes first and is designated with a 1. O goes second and is ...
user avatar
  • 253
5 votes
1 answer
85 views

С++: Find max element from section in matrix

I'm a newbie in programming. Could you please check my code and give any refactoring ideas, tips, etc... how it can be improved. I wrote a code to perform the following task: Find in randomly filled ...
user avatar
1 vote
2 answers
101 views

Duplicate Binary Search Improvements

I'm working on an implementation of binary search (in Python) that can operate on a sorted array that may have duplicate elements. I've written a submission that has managed to hold up against my test ...
user avatar
1 vote
1 answer
46 views

isPalindrom-function in TypeScript

I have written an isPalindrom-Function in TypeScript. ...
user avatar
  • 3,758
1 vote
2 answers
63 views

Reading 12-bit words from 32-bit stream

I have a device (ADC) that stores its samples in a 32-bit buffer and each sample is a 12-bit word : I needed an algorithm to read those samples to a container (say ...
user avatar
  • 771
0 votes
1 answer
66 views

Subset Product Algorithm

Subset Product is an NP-complete problem and is my favorite problem. So, I've written a slightly smarter way of solving the problem. Will performance impact matter if I use multi-cpus and my GPU? Do ...
user avatar
0 votes
2 answers
51 views

Algorithm for twoSum

This is my PHP algorithm for the twoSum problem in leetCode: ...
user avatar
  • 3
0 votes
1 answer
30 views

Is my approach for Palindrome right or is there a better way to do it?

The code below is for checking whether the input string is palindrome or not ...
user avatar
1 vote
0 answers
15 views

Iterating over de Bruijn sequences in JavaScript

I have just put this code together, it's not quite the most elegant but it seems to get the job done. Does it seem alright? I could not find anywhere a "de Bruijn sequence algorithm", so I ...
user avatar
  • 299
2 votes
2 answers
94 views

Optimizing a recursive path finding algorithm

On input i get width and height of matrix, string of text and another string of finalText I want to reach. The characters of the first string are assigned to matrix. My goal is to find shortest way to ...
user avatar
  • 21
5 votes
2 answers
686 views

Find non-overlapping pairs of elements in a list whose difference is less than some given threshold

I have the following task: Let us have a list (denoted by L, and for simplicity, the elements come from the interval [0,1]). We are given a parameter (denoted by C), and we want to find as many pairs ...
user avatar
  • 153
1 vote
2 answers
80 views

Closest Pair of Points - Optimizing Code for big sets of points

I'm trying to create an algorithm that finds the closest pair of points (2D) within a set of points. I'm using a divide and conquer method which is explained here Closest Pair of Points Algorithm. ...
user avatar
  • 11
1 vote
1 answer
70 views

Categorise amount into "small", "medium" and "large"

I have a super simple function that returns a text label for a range of the input ...
user avatar
  • 275
5 votes
0 answers
63 views

Dijkstra's algorithm in Perl

I have this Perl module project. My implementation of the Dijkstra's algorithm follows: ...
user avatar
  • 25.3k
3 votes
2 answers
96 views

Given a list of digits, construct the largest number divisible by 3

What is the performance of this program? What should I do differently to optimize performance (O(n))? How would you grade it relative to what defines an optimal, elegantly-written program? Input: A ...
user avatar
4 votes
0 answers
49 views

d-ary heap in Perl

This is my the very first data structure written in Perl: ...
user avatar
  • 25.3k
2 votes
1 answer
61 views

Leetcode problem: minimum removal to make valid parentheses

I was working on this problem on leetcode Question Your task is to remove the minimum number of parentheses ( '(' or ')', in any positions ) so that the resulting parentheses string is valid and ...
user avatar
  • 179
0 votes
1 answer
87 views

Finding missing numbers in ranges

I have a list of (potentially overlapping) ranges, e.g [(3, 9), (8, 10), (1, 18)]. I need to process them in order and for each range calculate how many numbers ...
user avatar
2 votes
2 answers
135 views

Much more efficient trisexual genetic algorithm for TSP in Java

(The entire project lives there.) This time, I have made the previous version of the GA for TSP run faster by around the factor of 6+. The idea is to cache the tour costs with the actual tour objects ...
user avatar
  • 25.3k
2 votes
0 answers
64 views

Genetic trisexual algorithm for TSP in Java [duplicate]

(A more efficient version of the GA.) This is my the very first take ever on GA: GeneticTSPSolverV1.java: ...
user avatar
  • 25.3k
2 votes
1 answer
66 views

Golang solution to CTCI 1.2: Check whether two strings are permutations of each other

Just started learning Go recently. Did some questions from Cracking the Coding Interview book. Wrote the solutions in Go. Let me know what you think. https://github.com/samjingwen/ctci Below is ...
user avatar
3 votes
1 answer
109 views

The shortest path between airports

Airlines need to provide their customers with flights to every corner, so they need an app that allows them to do so. The customer must be able to transfer when there is no direct connection. The ...
user avatar
0 votes
2 answers
77 views

Encryption and Decryption in C

I have written a program in C, which encrypts and decrypts a c-styled string (const char *) and print the result to stdout. It ...
user avatar
3 votes
1 answer
67 views

Algorithm Challenge: Fuzzy Search

I recently took part in an algorithm challenge to create a Fuzzy search with the following criteria: Given a set array, create a function that receives one argument and returns a new array containing ...
user avatar
1 vote
1 answer
45 views

Genetic TSP in Java with graph expansion

This post presents my take on TSP (travelling salesman problem). The idea is to: Take an input node i, Compute the entire graph ...
user avatar
  • 25.3k
2 votes
1 answer
88 views

Leaky Bucket Algorithm with no Queue

Basic implementation of a leaky bucket, the idea is you call it by saying I will allow e.g. 5 login attempts per 60 seconds. ...
user avatar
4 votes
1 answer
113 views

Rijndael Cipher in C++ (128bit AES)

I am a hobbyist and do not work in the industry, but I do have an interest in programming an cryptography. I decided to have a go at writing a 128bit implementation of AES in C++. This is my first ...
user avatar
3 votes
1 answer
70 views

Traditional vs. bidirectional Dijkstra's algorithm in C

I have this CLion project on GitHub. It constructs a directed, weighted graph consisting of 100 thousand nodes and 500 thousand directed arcs, picks two random nodes, and computes the shortest paths ...
user avatar
  • 25.3k
3 votes
1 answer
58 views

Percolation threshold simulation using C++

I am studying Algorithms by Princeton University. The first week assignment is to simulate percolation by using Java. https://coursera.cs.princeton.edu/algs4/assignments/percolation/specification.php ...
user avatar
  • 135

1
2 3 4 5
99