The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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.

Filter by
Sorted by
Tagged with
-1
votes
0answers
12 views

Can't figure out how to finish converting the given input into hexadecimal format

I don't know how to do step 3 in the docstring, which is to add 2800. I cant figure out how to get around the f's that are showing up at the end of some the numbers. Because of the f's, I cant turn ...
2
votes
1answer
33 views

Concise Way To Specify The Space Of All Python Programs Under A Certain Size And Running Time?

Given the grammar of the Python language, is there a concise way to specify the space of all possible (and correct) Python programs? To avoid the underlying halting problem, the specification would ...
0
votes
0answers
15 views

How to compute the predecessor-subgraph in all-pairs-shortest-paths algorithm?

The following slow algorithm (implemented from CLRS book) which runs in $\Theta(V^4)$ works fine for computing shortest paths distances: ...
2
votes
0answers
63 views

Consider vectorization and for loop, do both approaches have the same time complexity?

I am learning this post Fast computation of nearest neighbors is an active area of research in machine learning. The most naive neighbor search implementation involves the brute-force computation ...
0
votes
0answers
43 views

Is Python's Grammar in a known Category between CFG and CSG?

I have a high level understanding of formal languages and grammars, and I'm familiar with the four major types of grammars in Chomsky hierarchy. I was interested in knowing the classification of ...
1
vote
0answers
29 views

Creating N using commands of the form A=2A-B [closed]

You are given two integers L and R. Their values are initially set to L=0 and R=1. You can change their values by performing the following Commands: The command ...
1
vote
1answer
20 views

Complexity of iterative exponentiation

I've watched multiple videos and read articles about recursion but I'm still confused. I've got this problem here but I'm unsure how to answer it: The following function calculates $x^n$ ...
2
votes
1answer
34 views

Are there any benefits of implementing the Fisher–Yates shuffle algorithm from tail to head instead of head to tail?

I was looking at the Fisher–Yates shuffle algorithm and followed the Python implementation for it. Python starts from the end of the array to the start. Looking at the algorithm I didn't see any ...
0
votes
0answers
12 views

Selecting right cartons for meeting demand (retail supply chain)

I am working on an inventory allocation problem and I could use some help figuring out an optimal solution. Let's say a retail chain's warehouse stores inventory in cartons (physical boxes). Each ...
1
vote
1answer
39 views

Intuition behind this specific algorithm for time series

Going through the EPI book and I need some help understanding this part. There's a problem, 5.7, that deals with buying and selling twice over a single time-series in order to maximise profit. The ...
1
vote
0answers
26 views

How to implement minimization of maximum regret?

We run a report, but for one of our big clients, it is taking too long. There is a loop where it loops for a list and fetches it upstream 1by1. We're making this a bulk operation now, but some items ...
2
votes
0answers
48 views

On teaching Kolmogorov complexity with Python and the complexity of composed strings

The setting of this question is a bit long-winded, but please bear with me. This fall I will be lecturing a course on mathematical information theory, and on a few lectures we will be discussing ...
1
vote
1answer
36 views

I am looking for an algorithm that can find the best possible combination of inputs, in order to determine the optimum output

So as the title poorly implies, I'm looking for an algorithm that can accomplish the following task (as an example): Given the inputs A(1:100), B(1:100), C(1:100), that can take on any value between ...
0
votes
2answers
54 views

What is the official name of a specific type of combination algorithm

Say that I have the following set of variables: [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z] The values represent a list of variables from a dataset. ...
1
vote
0answers
46 views

How to approach backtracking when using immutable types (Python)? [closed]

In Python when we are building a recursive algorithm that uses backtracking a mutable type such as a list is great to use. It can be modified at each call in our recursion tree, then returned back to ...
2
votes
0answers
57 views

Knapsack problem in real life

My task is to develop an algorithm for the optimal arrangement of cylindrical objects in cartons. The algorithm is to have the task of placing as many products as possible into cartons, at the same ...
1
vote
4answers
48 views

Quadratic equations using 2 different approaches

I am reading Mark Newman's Computational Physics and at chapter 4 page 133 in Exercise 4.2 he asks a) Write a program that takes as input three numbers, a, b, and c, and prints out the two solutions ...
0
votes
1answer
26 views

How does a=2 twice in this code sample? [closed]

I am just starting out learning code. The output of the following code is OOOXOXOO, but I don't see how X can be printed twice. How does a=2 more than once? ...
-3
votes
1answer
99 views

Could we define the decimal notation of a natural number as a series of operations applied to 0? [closed]

People have made mistakes. For that reason, there probably is a demand by some people for a computer program that's easier to verify makes the calculations properly. I think that according to the ...
1
vote
2answers
63 views

How can the length of a string be $O(\log n)$?

I have just started learning about time complexities and am currently reading Logarithmic Complexity. Here's an example of a piece of code which is $O(\log n)$: ...
12
votes
3answers
3k views

Which other programming languages apart from Python and predecessor are out there using indentation to define code blocks? [closed]

Python quite famously uses indentation to syntactically define blocks of code. (See Compound statements in the Python Language Reference). After years of using Python I'm still intrigued by and very ...
1
vote
0answers
143 views

Mixed Integer Linear Programming application problem

I have a Mixed-Integer Linear Programming question. There's this game called Islanders. Pretty graphics, it's about maximizing your score building a small city in a confined island. Here's a quick ...
0
votes
0answers
25 views

Good algorithm to compress down connections of graph nodes?

I have a collection of graph nodes which are connected to each other. I wrote a DFS algorithm to recursively search the connectivity of the graph to find all connected nodes, however due to the size ...
1
vote
1answer
49 views

Big Oh Time Complexity Involving 'for i in range(n)' [closed]

Given the code below and the comment analysis: ...
0
votes
0answers
561 views

Draw 3D bounding box of object in 2D image OpenCV

Recently I have been interested in Computer Vision and I am now experimenting with OpenCV in Python. I have done some research but haven't really found what I am looking for. Therefore I try to give ...
2
votes
1answer
129 views

Compute hash value according to multiplication method

In "Introduction to Algorithms" by C. E. Leiserson, R. L. Rivest and C. Stein (ISBN: 978-0262033848), p. 264 they state this: I get everything but the last part stating $h(k) = 67$ ...
0
votes
0answers
51 views

How to perform particle swarm optimization clustering of results obtained from tf-idf vectorizer?

I have a collection of news articles. I have performed tf-idf operations on them. I am using python as programming language so it was just the use of TF-IDF vectorizer function. I now have the ...
0
votes
0answers
143 views

Random Forest - Conditional Permutation Importance

I've been looking for the most unbiased algorithm to find out the feature importances in random forests if there are correlations among the input features. Besides the most commonly preferred ...
0
votes
0answers
16 views

Cluster with categorical / ordinal

i have a dataset with movies review. I wish cluster my element but inside i have a categorical / ordinal values. i seen that exist: MCA (Multiple Correspondence Analysis) https://www.utdallas.edu/~...
0
votes
0answers
19 views

how can I write an algorithm in python that converts a natural number n into base b? [duplicate]

I only know simple python but I'm not sure how to write an algorithm that takes values n and b, where n is a positive integer and b is the base, and converts n into base b. Note b<=10.
1
vote
0answers
20 views

How to go about designing a quiz that changes difficulty based on user performance?

I thought about using a machine learning algorithm to learn the performance patterns of the quiz taker and model the next quiz based on how he/she performed. So each question will have a difficulty ...
1
vote
0answers
19 views

If statement not capturing the conditional I'm seeking [closed]

I'm working on a hw assignment, and my if statement isn't working the way it's intended. This is an ATM machine project. I've already gotten the program to read the csv file and stored it into a ...
0
votes
1answer
52 views

Ant Colony optimisation for finding subsets with ~0 sum

I have a set A = [x1, x2...xn] where xi in R (real). I need to find all non intersecting subsets with subset sum ~0 (approximately equal to zero). Since the set can have non zero real numbers, I have ...
0
votes
0answers
71 views

Composite and Non-Composite User-Defined Data Types

I have a learning resource which claims the following about user-defined data types Non-composite include: Enumerated Pointer Composite include: Record Set This confuses me, and I would ...
-1
votes
1answer
57 views

Does this sorting algorithm already exist? And if so, what is its name?

I created this algorithm off the top of my head this morning. It has one loop, therefore it has a time complexity of O(n) and only stores two variable during loop so it has a space complexity O(1) ...
1
vote
1answer
31 views

After how many iterations will an integer circle back to 0 in Python? [closed]

If this question is completely garbage I apologize because I am new to CS and haven't understood at how programming languages (Python specifically) work. I was reading about how in a standard two-...
0
votes
1answer
27 views

My code works, But how do I make this code run in a deterministic time?

The Problem: Given 3 inputs Bounce, Ball drop height, and ball view height. How do I calculate the number of times the observer can see the ball pass. So my code gives correct output, but it takes ...
2
votes
1answer
113 views

Minimum cost node cut

I am interested in solving the following problem: Given an undirected graph whose vertices are weighted, find a subset of vertices of minimal weight whose removal disconnects the graph. Is there ...
0
votes
2answers
335 views

Help with Time Complexity

Suppose we have the function below: ...
-1
votes
1answer
178 views

What is the procedure to find the time complexity of python program? [duplicate]

Is there any kind of function which is used in python to calculate the time complexity of another function?
1
vote
0answers
29 views

Is this solution is bad for the coin change problem? [closed]

was doing coin change problem as an assignment(didnt know before), after came with this solution i checked the solutions available couldnt find a similar one like this, just curious. removing the ...
1
vote
1answer
96 views

Finding a minimum weight path with certain restrictions

I have a directed weighted multigraph whose vertices are sets of URLs. We add to this multigraph all edges of the form $i\to j$ where $i\subset j$ (such edges are of zero weight), where $i$, $j$ are ...
2
votes
1answer
246 views

Why is this n^2 growth?

I am attempting to understand the growth of the following algorithm, which is described as $n^2$ growth in the book I am reading: "... performs of the order of $n^2$ steps on a sequence of length $n$....
3
votes
1answer
54 views

Why does parallelising slow down this simple problem against looping through all the data?

I've been using multiprocessing and parallelisation for the first time this week on a very large data set using 32 CPUs. I decided to explore it for a smaller task just to see if I could learn ...
1
vote
1answer
55 views

A problem about slicing and indexing in numpy in Python [closed]

I learned that in numpy, given a vector, slicing and indexing could give different results. I ran the following codes: ...
2
votes
1answer
329 views

How can I optimize 3 variables in order to maximize the end product?

I am in the process of making a cryptocurrency trading bot. Currently, I am doing backtesting over a period of 7 months in which I provide a portion of historical data as if it were in real-life. By ...
3
votes
1answer
580 views

How to use Latin hypercube sampling with fixed points?

I use Latin hypercube sampling to select what point to evaluate my function. As evaluations take a lot of time, I want to limit the time by adding already evaluated points. I thought about taking the ...
1
vote
1answer
2k views

Python: Clustering based on pairwise distance matrix [closed]

I have a matrix which represents the distances between every two relevant items. For example, M[i][j] holds the distance between items i and j. My next aim is to cluster items by these distances. I ...
0
votes
0answers
54 views

how to build logical representation from dependency tree

I'm trying to build logical representation from dependency tree with python. i created the tree with stanford parser. How can I derive logical presentation from it using Lambda-calculus?
0
votes
0answers
45 views

Van Emde Boas Cluster recursion

I have been trying to implement a Van Emde Boas tree in python, but I'm having trouble understanding how exactly it works. In the notes here, It states that the summary of a VEB structure is another ...