Questions tagged [comparative-review]

This tag is used for questions which present a problem and multiple solutions, where the asker wishes to know which solution is best (and why).

Filter by
Sorted by
Tagged with
1 vote
0 answers
25 views

LeetCode#494 target sum (dart is slower than python)

I'm trying to solve a LeetCode problem target-sum, in two languages: Python & Dart. The difference of time taken is shocking for me" Python took ~70ms while Dart took ~900ms !! Why does Dart ...
1 vote
1 answer
49 views

Selection algorithms (order statistic) in Java: linear time vs. sorting selector vs. Quickselect

This post is about computing order statistics: given an array \$A\$ (not necessarily sorted), find the \$k\$th smallest array component. The entire repository is here. ...
  • 26.1k
0 votes
0 answers
32 views

Euler's totient function in Rust, with a performance difference between generic and classic functions

I recently started to program in Rust, having like 2 good years of experience in C++, I thought it would be possible to directly switch to Rust without following a lot of tutorials, especially knowing ...
  • 101
2 votes
1 answer
106 views

Card game simulations, with a multithreaded version slower than the single-threaded one

I'm new to rust and I'm trying to build a card game simulation to find all of the best actions with all possible hands. This requires a lot of simulations and my first 3 million are already taking a ...
0 votes
1 answer
28 views

Find longest "binary gap" [closed]

I'm doing a few challenges and I found this one on Codility: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the ...
  • 101
1 vote
1 answer
57 views

Shortest path in dags: Part 2/3 - the preprocessing and shortest path algorithms

Part 1/3 Part 3/3 I have this library for performing shortest path queries on dags (directed acyclic graphs). This post presents the shortest path algorithms and the topological sorters. Two ...
  • 26.1k
1 vote
0 answers
31 views

DOM scrolling implementation [closed]

Which code is considered better to write to implement smooth scrolling for the page? 1st, with optional chaining: ...
  • 51
0 votes
1 answer
46 views

Show numbers per step count

I have a problem where I need to display the below output 1 23 456 78910 My first solution is ...
  • 103
3 votes
1 answer
76 views

"Select followed by First" versus "First followed by Select" when summing the data for a student

I am wondering which one I should choose between the following two options when I need to calculate the sum of Data of the student with ...
5 votes
1 answer
209 views

Calculate the number of people occupied at each time interval

The following scripts calculate a list with the number of people occupied at each time interval. The intervals are defined by the timestamps of two consecutive events that come from the sorted list <...
  • 53
2 votes
3 answers
562 views

Returning the other value of boolean enum

I have a class with a "mode" state. There are currently two modes and we are not likely to add more in the future. The class has a CurrentMode property, ...
  • 184
-2 votes
1 answer
88 views

Insert row into database using static or non-static method [closed]

I would like to know if there are any benefits of one of the following 2 methods which insert an object into a database The first function calls the Model method statically, creating a new instance of ...
2 votes
1 answer
57 views

Batching method implementation - Scala

I need to implement a function/method that operates on a sequence of values, and acts kind of like takeWhile, but with 2 differences, first, it doesn't act on a single element, it is performed on a ...
  • 123
1 vote
1 answer
74 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 ...
  • 305
3 votes
3 answers
249 views

A refactored payment service, handling several payment schemes

I was asked to refactor a class, to make it adhere to SOLID principles, with testability and readability. I thought I had done a decent job, only my feedback was: a) Unnecessary introduction of ...
  • 140
3 votes
0 answers
247 views

Return a 2D matrix from a C++ function in Python: ctypes versus pybind11

I found two ways in which I can use a custom C++ function (returning a 2D matrix) in Python. One approach that uses the Python module ctypes and another that uses the Python module pybind11. Approach ...
2 votes
0 answers
1k views

What is better - using SerialPort with or without await/async methods?

I'm having an implementation using SerialPort in C# using Visual Studio 2019. I'm using it in a Windows Application, using .NET Framework 4.7.2. When I open and ...
1 vote
1 answer
63 views

Constructing routes from imported URL constants

There is a file created with the project paths in a dictionary. Example: ...
  • 113
1 vote
1 answer
52 views

Comparing two general LCA algorithms in Java

Now I have two algorithms solving a problem: given a general (multi-way) tree, and any array of node names, find the the node that is the deepest common ancestor. ...
  • 26.1k
0 votes
2 answers
123 views

Draw a triangle of stars

I decided to try to write half a pyramid of stars using programming because I wanted to see if I could do it, and I did it. However after comparing it to other people's solutions I started doubting ...
  • 131
0 votes
1 answer
58 views

Time complexity of several methods of reversing a domain name string

Note: I'm aware of this existing post which is similar. However, it does not address all my questions sufficiently. I have the following three functions, all of which do the same thing: reverse a ...
3 votes
1 answer
355 views

Python function to output a string that is justified to the right

I just solved this exercise from Think Python, 2nd edition: Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
3 votes
2 answers
130 views

Retry read/write until all bytes are transferred or error occurs

Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
's user avatar
3 votes
1 answer
599 views

Format an integer with space as thousand separator

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
1 vote
1 answer
84 views

Show progress bar for different states

I have this working code which shows the progress bar based on different states ("not-started", "progressing" and "done"). Each state will have its own class. I notice it ...
1 vote
1 answer
128 views

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: ...
  • 26.1k
2 votes
0 answers
48 views

Python: How to best create a dictionary from another dictionary in a library

I have the following code which builds up a dictionary of endpoints that I iterate through later on. Is this the cleanest, most scalable and performant way? I was thinking of adding a list as a key to ...
  • 360
0 votes
0 answers
86 views

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 ...
  • 422
4 votes
3 answers
93 views

Destructuring with map and assigning to a constant

I don't know exactly what to name this, but I was refactoring a code snippet and looking at this constant users I thought I'd do this destructuring: Before: ...
  • 369
1 vote
1 answer
86 views

Java: Using one class or algebraic data types to model different state?

I'm creating a tool to analyze a card game which is played by three players. A Card is associated with a number of points and looks like this: ...
0 votes
0 answers
37 views

Should I replace this request queue?

I just found myself hacking around the limitations of a backend that aborts highly concurrent transactions by queueing the requests using Solution A. I don't like this solution very much, and have a ...
0 votes
1 answer
70 views

2 ConvertToBase3 methods with great disparity of execution time

I have two methods to do the same thing: convert a number to ternary. ...
  • 109
0 votes
2 answers
184 views

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 ...
2 votes
2 answers
150 views

How can I optimize this pairwise Euclidean distance search algorithm?

x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns. I need to get a matrix of Euclidean distances between each pair of rows from x and y. I ...
1 vote
0 answers
47 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
  • 141
0 votes
0 answers
63 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
  • 101
0 votes
3 answers
231 views

C# 'out' keyword in JavaScript [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent in JS. So, please take a look at the code and leave your opinions or suggestions about this. C# ...
's user avatar
0 votes
2 answers
70 views

List of objects inside same model vs Factory vs Service [closed]

I am creating a simple Country class. This Country have list of know countries. we can get the list of known countries Country.AllCountries, ...
-1 votes
3 answers
85 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
0 votes
1 answer
66 views

Convert string to 10 character string with leading zeros if necessary

I have the below data and am obtaining the expected output column for it. ...
  • 149
2 votes
1 answer
247 views

=PRINTF("{1} - {2}", ... ) in Excel without VBA - LAMBDA functions with variable number of arguments

The TEXTJOIN function has a really nice interface: =TEXTJOIN(delimiter, ignore_empty, text1, [text2], …, [text252]) ... where ...
  • 2,210
1 vote
2 answers
82 views

Comparison of 2 different ways of writing Merge Sort Algorithm

I have recently learned Merge Sort algorithm in C++ with 2 ways of writing it. 1st Way: ...
  • 11
2 votes
3 answers
80 views

URL & HTML encodings on pagination

I wrote this Pagination Section. It shows links to pages 123456789 and so on on SERP (Keyword Search Result Pages). Like you see on Google SERPs. Even though they work, I'm not sure I finished them to ...
6 votes
5 answers
675 views

Comparing 2 distinct sieve of Eratosthenes algorithms in Java

In this post, I will present and compare two distinct algorithms for sieve of Eratosthenes: com.github.coderodde.math.prime.PrimeFinder ...
  • 26.1k
3 votes
3 answers
129 views

Comparing 8 different Disjoint-Set data structure variants in Java

The Wikipedia page on Disjoint-Set data structures presents \$4\$ distinct algorithms for finding the root node of the tree, and \$2\$ distinct algorithms for performing the union operation. In this ...
  • 26.1k
1 vote
0 answers
40 views

Graph stored as adjacency list or as endpoints and intervals

I tried speeding up my Graph class, so I removed the Node class and Edge class, and decided to use arrays and ArrayLists. My 2 implementations seem very similar, ...
1 vote
2 answers
110 views

Search for text in a file

I have this implementation of Grep where I use re.search: ...
1 vote
1 answer
289 views

Which of these two Vuetify Navigation Drawer prevent prop mutation workarounds seem better?

I am very new to Vue.js, I just stumbled on a very hard thing to do (at least for me) where Vue was complaining about mutating a prop (children shouldn't change parent props apparently). I was about ...
0 votes
3 answers
261 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
2 votes
2 answers
278 views

Counting uppercase and lowercase characters in a string

I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...

1
2 3 4 5
19