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
0
votes
0answers
7 views

What will the output of string comparison program? [closed]

a=[1,2,3,4,5] b = [3,4,5,6] c= [9,2,3,4] d = [1,2,3,4,0] e = [1,2,3,4] if a>b: print("A is greater than B") if a>c: print("A is greater than C") if a>d: print("A is greater than D ")...
1
vote
2answers
131 views

What is the worst-case big-O time complexity for this code?

I had a quiz in my class and didn't do so well on it. I'm looking to find out if someone can explain to me what I did wrong here - our professor is overwhelmed with office hours as we moved online so ...
0
votes
0answers
10 views

i want to add an image to my website i have already added some images but the others i wanna add are not urls but they are located in my pc storage [closed]

so i wanna have two different options to upload an image to the website one through src="{{ product.image_url }} so i can display the image through a url i provide and the other option i wanna keep is ...
2
votes
1answer
33 views

“Visited” vs “Seen” Positions in Breadth-First Search

I'm struggling to understand why there is such a radical difference in the execution time and number of steps required by two seemingly similar algorithms for Breadth-First Search in a 2d grid. In ...
1
vote
0answers
17 views

What is the best algorithm for detecting the texture of a person's clothes in real-time for a mobile robot?

I am working on the human following robot. the robot extracts a feature of clothes's texture and distinguishes between the people that they stand up in front of the robot. So, the robot needs that it ...
0
votes
0answers
15 views

Coding a Binary Constraint in Python

I am working on a CSP solver in python, and am stuck how to code the constraints. According to my assignment, the constraints are given through an input file, and can contain operators such as <, >,...
1
vote
1answer
60 views

Array segmenting algorithm

I have a sorted array of integers [x, ..., n, ..., y] so that x > 0 n - x = random positive integer The array might look something like this: [1, 2, 3, 15, 16, 17, 120, 121, 122, 123, 124, 125, 126,...
2
votes
1answer
57 views

Min-coin change problem with limited coins

I have been assigned the min-coin change problem for homework. I have to calculate the least number of coins needed to make change for a certain amount of cents in 2 scenarios: we have an infinite ...
0
votes
1answer
33 views

Cover interval with minimum sum intervals - DP recursion depth problem

READ ME FIRST: I have just found the official solutions online (have been looking for them for a while, but after posting this I quickly found it), and I'm currently trying to understand it. As I can ...
0
votes
1answer
27 views

Identify the function call statement in the following snippet [closed]

I know that the main(sys.argv[1:]) is the function call statement but I have no idea about the other two variables and why it's used. Can anyone explain?
0
votes
0answers
22 views

Cover marked squares with rectangles with optimal tradeoff

I'm trying to solve this problem where I have to cover all the squares in a N x N grid with rectangles with a tradeoff between cost and computation. These are the constraints: Fields are rectangular, ...
0
votes
0answers
42 views

Segmenting a cat's side profile and plotting a line on the edges

My goal is to segment the side profile of a cats head and plot a line on the edges of the cat's face, The cats will have different backgrounds, colour and quality, and the feature (cat's face edges) ...
2
votes
1answer
69 views

Repeated addition and comparisons of floating point numbers

In the following program where I repeatedly half an integer, it takes until i = 1074 for my integer to be equal to zero (I know that ideally the while loop shouldn'...
0
votes
0answers
15 views

What is the main concept of using lexical,linguistic, semantic or syntactic approach in NLP for cyberbullying

Am really in need of some explanation, am working on a nlp cyberbullying detection tool which i will deploy to the web using django framework, however, am stuck on some idea, can someone explain to me....
1
vote
0answers
19 views

Termination Character in Suffix Trees

I am trying to create a generalised suffix tree from a very large number of strings using Ukkonen's algorithm, however I run out of unique symbols to use as string termination characters. I was ...
0
votes
0answers
85 views

vc dimension of binary decision trees of depth d?

how do i find the vc dimension of the hypothesis space H ,of the binary decision trees of depth d-2? will the hypothesis space H consist of{0,1} and the vc dimension is the number of ways in which we ...
2
votes
1answer
64 views

(Leetcode) Combinatorial Sum - How to generate solution set from number of solution sets?

The following question is taken from Leetcode entitled 'Combination Sum' Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique ...
0
votes
0answers
56 views

Regex Questions?

I need to match all words having two adjacent vowels that differ. I did this /\b(?=\w*([aeiou])(?!\1)[aeiou])\w+/ but I am not allowed to use the ?! and it needs to be done in as few characters as ...
1
vote
0answers
62 views

Can this graph-ordering problem be solved with LP?

I have a modelling problem that I am trying to solve with LP. (More specifically, in Python using PuLP or Pyomo). I am not terribly knowledgeable in this area and have been struggling to find the ...
0
votes
1answer
32 views

How to check rapidly if an element is present in a large set of data

I am trying to harvest scientific publications data from different online sources like Core, PMC, arXiv etc. From these sources I keep the metadata of the articles (title, authors, abstract etc.) and ...
6
votes
3answers
1k views

Space complexity for storing integers in Python

So I was watching this mock interview by an Airbnb engineer on interviewing.io (https://youtu.be/cdCeU8DJvPM?t=1224) and around ~20:11 seconds he raises an interesting point. The question that the ...
0
votes
0answers
31 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
65 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
91 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 ...
2
votes
2answers
40 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$ ...
3
votes
2answers
58 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
15 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
49 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
33 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
111 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
46 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
64 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
132 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
496 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
91 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
27 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
102 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
212 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
4k 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
176 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
28 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
153 views

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

Given the code below and the comment analysis: ...
0
votes
0answers
1k 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
143 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
65 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
256 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
25 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/~...
1
vote
0answers
21 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
72 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 ...