Skip to main content

All Questions

Tagged with
2 votes
0 answers
74 views

backward induction algorithm computation

Is there a way to significantly speed-up this code? I'm solving a dynamic programming model using a backward induction algorithm. A crucial step is to calculate the current-period value function (VF), ...
manifold's user avatar
  • 121
2 votes
0 answers
134 views

How to make this arbitrary precision π calculator using Machin-like formula run faster?

Two days ago (or yesterday depending on your timezone) was π-day. So I thought it was a good day to calculate π. I used Machin-like formula to calculate π, in homage of William Shanks, who calculated ...
Ξένη Γήινος's user avatar
6 votes
4 answers
483 views

Traversal Heap Sort (No Extractions)

I developed a heap sort variant that sorts a heap through traversal. Unlike in the standard heap sort, the algorithm does not remove the min element from the heap instead it traverses all the nodes of ...
ariko stephen's user avatar
4 votes
3 answers
1k views

Coding exercise to represent an integer as words using python

Context: Convert a non-negative integer num to its English words representation. Example 1: Input: num = 123 Output: "One Hundred Twenty Three" Example 2: Input: num = 12345 Output: "...
Silah's user avatar
  • 111
3 votes
1 answer
89 views

Check which sinks are connected in the pipe system using Python

It would be very helpful to me as a beginner if I could get feedback on my code, specifically about the efficiency of algorithm used and potential improvements in code quality. Code context: There is ...
Silah's user avatar
  • 111
4 votes
1 answer
135 views

Advanced Python Calculator using OOP

I've been into computer science fundamentals (proper data structures/algorithms/etc) including Object Oriented Programming. Therefore, I decided to reformat my old traditional Python Calculator into ...
Raphael Irvin's user avatar
7 votes
3 answers
761 views

Optimal Algorithm to Append and Access Tree Data

I have been studying intermediate or more advanced data structures in Python, one of which I've decided to try out is the Tree Data Structure. I've been studying the theories as well as the ...
Raphael Irvin's user avatar
4 votes
1 answer
140 views

Efficient polynomial multiplication in Python

I'm practicing problems for the ICPC competition, and one of the problems requires solving it by using an FFT to compute the product of two polynomials efficiently. Since this is for the ICPC ...
João Areias's user avatar
6 votes
3 answers
1k views

Implementation of Euler-Maruyama numerical solver

I am trying to write a python implementation of Euler-Maruyama and Milstein schemes for numerically solving stochastic differential equations. The pseudo-code for the algorithms is in the Wikipedia ...
Quasar's user avatar
  • 549
3 votes
2 answers
184 views

Find the join of two set partitions

Two partitions of a set have a greatest lower bound (meet) and a least upper bound (join). See here: Meets and joins in the lattice of partitions (Math SE) The meet is easy to calculate. I am trying ...
Watchduck's user avatar
  • 230
3 votes
1 answer
83 views

Number of partitions of (a,b) into k distinct parts which sum up to (a,b)

Problem set This is somewhat a generalization of the famous partition of integer n into k parts. Given two integers ...
linuxbeginner's user avatar
2 votes
1 answer
73 views

Clique Connect: minimum spanning tree

Problem Statement You are given a weighted undirected graph G with N vertices, numbered 1 to N. Initially, G has no edges. You will perform M operations to add edges to G. The i-th operation (1≤i≤M) ...
user24714692's user avatar
6 votes
1 answer
347 views

Codeforces: D2. Counting Is Fun (Hard Version)

The code works okay for the following problem. Problem An array 𝑏 of 𝑚 non-negative integers is said to be good if all the elements of 𝑏 can be made equal to 0 using the following operation some (...
user24714692's user avatar
14 votes
4 answers
2k views

Create a snail matrix

Statement: Create a script that, given an integer \$n\$, create a square matrix of dimensions \$n \times n\$ with the numbers from \$1\$ to \$n^2\$, arranged in a snail pattern. Example: ...
Dorian Turba's user avatar
4 votes
1 answer
88 views

Centre of mass based TSP solution (2)

I updated the code to a working state. My previous question. Even if this code working I wonder if I can write this code in a more efficient way. Maybe less for loops Etc. ...
tumr's user avatar
  • 53

15 30 50 per page
1
2 3 4 5
81