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
1vote
3answers
49views
DFS search that returns "not found" or distance
Assuming I've the following code: ...
  • 133
1vote
1answer
38views
Insertion Sorting Algorithm
I am new to data structures and algorithms. I have just implemented an insertion sorting algorithm. I just want to make sure if my code is alright. ...
  • 13
2votes
1answer
92views
Lingo (word-game) guessing strategy
My friend and I are kind of noobs in Python and are looking for ways to improve. We thought it would be cool if we could get some feedback on the following code. It is for a game named "Lingo&...
1vote
1answer
70views
Pathfinders.hpp - Dijkstra's algorithm
I have this Visual Studio 2022 project, in which I compared the performance of 4 point-to-point shortest path algorithms. This one presents the Dijkstra's algorithm: ...
  • 24.7k
-1votes
0answers
19views
Why do I need this extra boolean in this instance of Flood Fill algorithm? [closed]
I am doing LeetCode #1254: Number of Closed Islands, I am familiar with the Flood Fill algorithm, a recurrive DFS approach where you set visited nodes to a certain character/int (marker) so that you ...
0votes
0answers
10views
Custom sorting algorithm in Salesforce Apex
I had a scenario where I needed to sort a list of EmailTemplate, but didn't have anything to sort the list by (other than a common number in the ...
  • 794
4votes
4answers
827views
Count numbers that are the sum of three perfect cubes
From numbers from 1 to 100, count the numbers where the following equation is satisfied with 1 <= a <= 100, 1 <= b <= 100, and 1 <= c <= 100: $$a³ + b³ + c³$$ I have this: ...
1vote
1answer
84views
Comparing a prefix tree against a HashSet of strings in Java
Here, I have made an attempt to find out whether a prefix tree is any more efficient than a simple java.util.HashSet<String>. See what I have: ...
  • 24.7k
3votes
0answers
31views
Python: Algorithm for fast boundings box collision between two large sets of m and n rectangles
AABB: Axis Aligned Bounding Box ALGORITHM: Compare m number of AABB to n number of AABB to find if there is a collision between m and n sets. PROBLEM: Slow implementation for large number of ...
  • 31
0votes
1answer
51views
priority-based scheduling algorithm
I have developed a program that implements a Priority Scheduling algorithm (Priority Scheduling). The total number of processes is read directly from the standard input, each process specifying the ...
  • 447
2votes
1answer
106views
What are the issues with implementing the Shortest Job First algorithm?
I wrote a program that implements the Shortest Job First (SJF) scheduling algorithm. The total number of processes is read directly from the standard input, following that for each process to specify ...
  • 447
1vote
1answer
133views
Round Robin algorithm implementation
I wrote a program that implements the Round Robin planning algorithm. The total number of processes is read directly from the input standard, and for each process the arrival time and execution time ...
  • 447
0votes
0answers
42views
Stamp Combination Kattis
I tried to solve Stamp Combination problem on Kattis, which basically gives an integer array and a target number. The problem asks whether we can find a contiguous subarray which starts at either end ...
  • 21
3votes
1answer
75views
C++ : Garage Sale Algorithm
I'm studying Dasgupta's "Algorithms". I solved this problem in C++: The garage sale problem. On a given Sunday morning, there are \$n\$ garage sales going on, \$g_{1}, \cdots, g_{n}\$. For ...
  • 1,033
7votes
2answers
507views
C code to convert hexadecimal string to base64
I've written a program to convert a hex-encoded string to base64, and here is my code. My main concerns are: Optimizations - Is my code sufficiently optimized and if any more optimization is possible....
2votes
1answer
39views
Change values in array until no consecutive values
I have to find an algorithm to solve this question : You have an array with n integers in it. Make an algorithm that changes array so that there are no consecutive expressions in it and returns the ...
  • 23
0votes
0answers
45views
Leetcode #462 (Minimum Number of Arrows to Burst Balloons), with and without optimization
I have an interesting optimization and I want to get some confirmation on whether it's valid: I was solving Leetcode #452: Minimum Number of Arrows to Burst Balloons (description in footnote [1]) and ...
  • 243
0votes
0answers
68views
A doubly-linked list supporting full reversals in O(1) time (Java): Part I/II: the list
I have this Java data structure implementing only the very basic methods of the java.util.Deque and java.util.List interfaces. ...
  • 24.7k
5votes
4answers
2kviews
C++ basic bank money class
I am trying to create a basic money class that fits into a small console banking application I am making. Money.h ...
2votes
1answer
71views
Leetcode 662: maximum width of binary tree in Java
I have the following solution to this problem. The idea is to compute the maximum width of a binary search tree. The width of a BST on a particular depth is defined as the distance from the leftmost ...
  • 24.7k
1vote
1answer
57views
Reverse a sublist of a singly-linked master list in constant space and maximum of one pass (Java)
So I found this funky programming challenge somewhere on Quora. The idea is to take the head of a singly-linked list, and reverse a specific sublist. The requirements are: runs in constant space, ...
  • 24.7k
1vote
2answers
67views
Implementing graph for pathfinding
I need a graph for multiple pathfinding algorithms,so I wanted to ask whether my new graph implementation is ok. Would someone who works as a developer in related fields(Graphs, Pathfinding, ...
  • 23
3votes
2answers
60views
Cleaning a game logs list to find the frequent action triplets and the busy user
I have these game logs which I need to clean, process and find the frequency of game actions. These game actions should be a triplet. In the below given list, ...
  • 205
6votes
4answers
140views
Nelder-Mead optimization in C++
I've implemented the Nelder-Mead optimization algorithm in C++. I found this document to be a very good explanation of how the algorithm works, but I'll try my best to explain it (with an example) ...
  • 12.2k
5votes
1answer
375views
Simple IP address subnet calculator
In this task I had to create simple IP address / subnet calculator in Python. I'm just wondering how you see this problem. There is my code: ...
3votes
2answers
126views
Binary Search of Array in C#
I am an algo-newbie and this is my first attempt at writing binary search and it worked on the first try. But something about it tells me that its far from perfect. Please tell me how I can improve. <...
  • 133
2votes
1answer
38views
Minimum Spanning Tree in Rust
As a project I have worked on implementing and benchmarking two different minimum spanning tree algorithms in rust. My main concern is adhering to good style and not programming any glaring ...
  • 161
1vote
0answers
23views
Non-allocating k-nearest-neighbours between two matrices in Julia
I played around with some optimizations when answering this SO question. Sought is a function which given matrices x of size (m, l) and ...
3votes
1answer
68views
Optimize "Fill magic square" in python with backtracking
I have written a python program with backtracking that fills a n * n magic square. It solves for n = 4 in 4.5 seconds but gets stuck when I run it for n = 5 on my ...
  • 133
2votes
2answers
20views
Transforming a data of key value pairs to label and key
I have the following data ...
  • 329
9votes
1answer
436views
3D Inverse Discrete Cosine Transformation Implementation in C++
This is a follow-up question for 3D Discrete Cosine Transformation Implementation in C++. In this post, I am trying to follow user17732522's answer to update ...
  • 3,090
0votes
0answers
19views
Efficient algorithm to track all the direct parents and transitive parents(parents of parents and grand parents) in a directed acyclic graph
I am preparing for online coding assessment, where I have come across a question to write an algorithm to find the list of direct parents and transitive parents for each vertex in a directed acyclic ...
0votes
2answers
144views
Good practices for parsing this text file
I have the following .txt file structure that i want to parse in Java(8): ...
1vote
0answers
49views
Algorithm to fit people in a monthly calendar
I have an interesting algorithm to build and I have tried a couple of things but couldn't get it just right. I have the following set of rules: 16 people to fill every day of the month (let's call it ...
  • 111
2votes
1answer
108views
red black tree implementation in cpp
I am learning algorithms and trying to implement them in c++, I have chosen to try to implement a red-black tree due to its self-balancing properties and its ability to stop the worst case of O(n) ...
6votes
1answer
189views
3D Discrete Cosine Transformation Implementation in C++
This is a follow-up question for Parallel 3D Discrete Cosine Transformation Implementation in Matlab and Operator overloading in Image class implementation in C++. I am trying to implement 3D Discrete ...
  • 3,090
1vote
0answers
43views
Java reimplementation of the Python difflib.SequenceMatcher class
I'm rewriting a Python script into an Android app. This script uses difflib.SequenceMatcher to compare sequence of strings. I haven't been able to find something ...
  • 235
0votes
1answer
30views
Find the shortest path from bottom left to top right in a maze using dfs and bfs algorithm
The following code is applying the depth-first search and breadth-first search algorithm to find the shortest path from bottom left to top right in a 10 x 10 grid. ...
0votes
2answers
107views
c++ Most clean way to implement duplicate Binary Search Tree for complex type
I have tried to make my own implementation for a BST task I was given for a complex type (Transaction), that should be able to store duplicate values as well. However, I am not sure if I have gone ...
3votes
1answer
96views
Dictionary based non-local mean implementation in C++
This is a follow-up question for Manhattan distance calculation between two images in C++ and Dictionary based non-local mean implementation in Matlab. For learning C++20 and researching purposes, I ...
  • 3,090
1vote
2answers
58views
Binary Search using recursive approach
Is the following implementation of recursive function correct? How about the time complexity of the code; is it good in terms of performance? ...
3votes
2answers
68views
Parsing a std::string to a dictionary (std::map)
As always - the context ! Preliminaries Recently I needed a way to transport data from one environment to another. Though the proper way (probably) to do this would be to use databases (which I don't ...
  • 759
0votes
1answer
188views
A New Sorting Algorithm
I have designed an Algorithm for sorting numbers. This algorithm works by sorting an array of any length with random, non-repeating whole numbers in a linear manner by ascending order. Under the ...
3votes
1answer
93views
(Google Foobar XOR Checksum Challenge) How do i optimize this function to run for much larger values?
I wrote a function that accepts 2 integers start and length as input and returns the bitwise XOR of certain numbers as described below: ...
0votes
1answer
60views
Generating floats from integers
I wanted to make an algorithm that is a counter-example of Cantor's diagonalization argument. Given an integer, this Python code will produce a unique rational number. Fed the sequence of positive and ...
  • 451
3votes
1answer
132views
Deque class for .Net (C#)
As .Net has no Deque class (Double-Ended Queue) in the Frameworks and I couldn't find an example implementation that I was happy with, I have written the following with the intent that I may post it ...
2votes
0answers
130views
Parallel Breadth First Traversal in Rust
Overview I have been writing my own graph API for Rust and one thorny problem I wished to tackle was a parallel breadth first traversal of the graph. The API itself will have different graph flavours, ...
  • 171
1vote
0answers
47views
Eulerian Circuit for directed graphs
Summary It's been quite a while since I last touched algorithms and Python. This piece of code finds the eulerian circuit for the directed graph. A bit convoluted and its structure leaves much to be ...
2votes
0answers
34views
Maximizing Efficiency of Collatz Conjecture Program Python
My question is very simple. I wrote this program for pure entertainment. It takes a numerical input and finds the length of every Collatz Sequence up to and including that number. I want to make it ...
  • 21
3votes
2answers
165views
Rabbit Searching Problem in Rust
This is my Rust implementation of the rabbit searching algorithm I found yesterday in this video. The problem statement is as follows. There are 100 holes in a line. A rabbit is in one of the holes. ...
  • 33

1
2 3 4 5
97