Questions tagged [python]
Programming questions are off-topic here. Do not ask questions about how to write code in Python. However, conceptual questions about computer science are more appropriate. See our help center for the scope of this site.
226 questions
0
votes
0
answers
43
views
Lambda calculus with keyword parameters?
Several programming languages support a calling convention wherein values are bound to parameters via a keyword, rather than position in a tuple of arguments. I'm curious whether there is any formal ...
2
votes
0
answers
125
views
The problem of reachability in a directed graph, but all predecessors must be reached to reach a node
Let $S$ be a set of nodes belonging to a directed graph $G = (V,E)$. A vertex $v$ of $G$ is said to be reachable from $S$ if and only if $v \in S$, or if each predecessor of $v$ is reachable from $S$ ...
0
votes
2
answers
131
views
What other ways could be of representing an irreducible fraction without gcd?
My code for it:
from math import gcd
y = int(input())
w = int(input())
g = gcd(y, w)
print(f"{y// g}/{w// g}")
Could there be any other way of solving this problem without using gcd ?
-4
votes
1
answer
111
views
How to write the Python Program for the following condition?
How to write a Python Program for the following condition:
Let me explain how I tried to write the code.
$a=$ int$($input$($'enter the first integer between $1$ and $9$'$))$
$b=$ int$($input$($'enter ...
1
vote
1
answer
106
views
For which languages can branching be determined by static analysis?
Python has methods like getattr() which can be used to branch arbitrarily at runtime. As a result, static code analysis tools can't be certain what functions a ...
1
vote
3
answers
382
views
When do we multiply or add the time complexities of loops?
I am confused about calculating the time complexity of the following function.
...
0
votes
1
answer
139
views
Improve performances of Gauss-Jordan (XOR-SAT) Algorithm?
In this question I was looking for an algorithm to solve what seems to be a XOR-SAT problem.
Let's consider this equation system :
...
1
vote
1
answer
93
views
Generate product description from product specifications
I am looking for a python NLP library that can generate a proper product description based on product features provided to it.
Till now, i have tried transformers library and this is the code:
...
1
vote
0
answers
216
views
How many different colors are possible to generate in the HSV Color Space using OpenCV?
I don't know if this post belongs in this site because I feel it might be a programming question, but also I feel it might be related to the way Color Spaces work, if it does't belong here I can ...
3
votes
2
answers
1k
views
Find 1s in almost all 0 array using comparisons only
So, we are given a 100 long array, with 97 0s and 3 1s of which we do not know the locations. We must find them using only a compare function, which I managed to write (in Python):
...
0
votes
1
answer
162
views
A floating-point rounding problem
I run the Python code below. x and y differ in their 4th and 5th number, and x has larger ...
2
votes
1
answer
144
views
Repeated Substring Pattern
I've been working on the following challenge on LeetCode:
Problem:
Given a string s, check if it can be constructed by taking a substring of it and appending multiple copies of the substring together....
2
votes
2
answers
475
views
What is the practical use of list.clear() method in Python?
I was wondering if there is a reason behind clearing all the values in a list and reusing it, as opposed to deleting the list and creating a new one. Are there any practical advantages of using ...
1
vote
0
answers
77
views
Auxiliary Space Complexity of Dictionaries whose Keys are Iterables of Variable Size
Recently, I began delving into complexity analysis with dictionaries. More specifically, I have been looking at auxiliary space complexity. For the most part, this type of analysis has been ...
0
votes
2
answers
89
views
Should I concatenate three lists together or use two separate while loops in Python? Which option offers a better runtime complexity?
In the context of adding sparse polynomials, you have two alternative approaches to combine the terms from two separate polynomials. One option is to use the line of code ...
0
votes
3
answers
173
views
Compute the intersection of two polytopes and its corner points
I am looking for a method in Python/MATLAB to calculate the corner points of polytope which is an intersection of a polytope with half spaces.
I have a polytope P1 of the form
-1 <= x0 <= 1
-1 &...
0
votes
1
answer
76
views
Combining chunks on an infinite grid into regions
I am working on an floorplan application where I save elements on an infinite grid in a sparse manner. Specifically, I have the following Python class representing a sparse grid (basically a ...
-2
votes
4
answers
233
views
Can halting problem solved by soft computation?
As far as I know, the halting problem means we can't create a program that checks whether another program is stuck or halt based on given input. This means, the program expects two inputs and one ...
2
votes
1
answer
230
views
Sympy does not recognise when two partial derivatives happen to be equal
I am trying to find the first and second-order partial derivatives of a function of four variables $S$ using pythons symbolic math package sympy.
The issue is that sympy does not automatically see ...
0
votes
0
answers
180
views
Create a simple Neural Network of n layers in python from scratch with numpy to solve XOR example problem using Batch Gradient Descent
I'm a young programmer that was interested by machine learning. I watched videos and read articles about the theory behind simple neural networks. However, I can't manage to set it up correctly. I've ...
0
votes
3
answers
154
views
Number of islands
In the counting number of islands problem, I noticed that one of the solution from internet is as follows
...
1
vote
2
answers
207
views
Speeding up an array search for duplicate
I was tasked with writing a function that finds the value of an element that is the first duplicate in an array to be encountered. For the array
[2, 1, 3, 5, 3, 2]
...
12
votes
5
answers
4k
views
Does an algorithm's space complexity include input?
Consider the Kadane's algorithm for finding maximum subarray within an array:
...
1
vote
1
answer
84
views
Finding all zero sums of length m and checking for zero subsums on an abelian group (generalization of the sub sum problem?)
Let $G$ be an abelian group. We say that $G$ has property $V_n$ if for every $m > n$ and a list $L\subset G$ of $m$ elements s.t. $\sum_{g\in L}g=0$ there is a proper subset $\emptyset\neq L'\...
1
vote
1
answer
221
views
How can I convert the pseudo-code that solves maximum subarray problem to Python code?
I'm reading Algorithm Design and Application, by Michael T. Goodrich and Robert Tamassia, and sometimes the pseudo-code in this book doesn't make sense at all.
At chapter one they show us 3 solutions ...