# 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.

105 questions
Filter by
Sorted by
Tagged with
18 views

### How to calculate delta Q (modularity increase matrix) in graphs?

I've been trying to implement the Three-stage Algorithm to compare its results with our new proposed algorithm with different datasets than those mentioned in the article. I've succeeded in ...
27 views

### What is considered a “decent” project to show in an interview? [closed]

I am a Computer Science student beginning my final year. I heard you need a good portfolio of projects to showcase in job interview. My question is what is considered a good project? I assume bulding ...
76 views

### Lambda Calculus Conversion

How can I take a Haskell data type or function (eg fold, list, String, zip) and convert or translate it to a lambda calculus abstraction? Example: If sum computes a sum of all elements in a list, and :...
42 views

### How do you write a python\pseudo code that generates all pair permutations?

What would be a good pseudo code or Python 3 code for the following permutations problem? Let us define a n-permutation as a bijective function $\pi: \{0,...,n-1\}\rightarrow \{0,...,n-1\}$ and ...
46 views

### Combinations of set unions

I have a set $S = \{0,1,2,3,4,5,6,7,8,9\}$. $S_i \subset S$ for $i = {1,2,3,4,5}$. Any three $S_i$ has the same union, that is $S_1 \cup S_2\cup S_3 = S_1\cup S_2\cup S_4 = ...=S_3\cup S_4\cup S_5 = A$...
21 views

### Sorting idea - using little buckets (Not BucketSort)

I am recently been doodling with sorting, thought about writing my own ideas, and what I am about to write here came to my mind, and I am writing it here because I do not know if such sorting idea ...
39 views

### What programming language should I use to run physics simulations of CO2 being absorbed by different materials?

I want to model the absorption of CO2 with multiple different materials such as cement, limestone, wood, etc? I know Matlab is capable of these types of physics simulation according to this research ...
49 views

### What is the difference between python list and c++ vector?

I read about the similarities between the python list and c++ vector and it looks as if the only difference is python list is heterogeneous. Are there any other differences? How are they both ...
4k views

### Checking equality of integers: O(1) in C but O(log n) in Python 3?

Consider these equivalent functions in C and Python 3. Most devs would immediately claim both are $O(1)$. def is_equal(a: int, b: int) -> bool: return a == b <...
82 views

### What is the expected time complexity of checking equality of two arbitrary strings?

The simple (naive?) answer would be O(n) where n is the length of the shorter string. Because in the worst case you must compare every pair of characters. So far so good. I think we can all agree that ...
11 views

### Do Predecessors Ever Get Updated in Depth-First Search?

Is it true to say that in a Depth-First Search that uses a dictionary of predecessors to find the path to its destination, once a node has been pushed onto the stack and been added to the predecessors ...
29 views

### A pretrained model for mathematical equations characters detection

I am working on a project to convert equations to LaTeX code. After segmenting out the characters, I got stuck on the detection part and was looking for some pre-trained model that could detect ...
111 views

### Can a 600 MB text file with digits of the square root of 2 be compressed to 600 KB?

I have a simple script to calculate gaps in a sequence of digits of the square root of 2 (or any other multi-precision constant). As input, I generated files with the bigfloat module in Python: ...
5 views

### modeling DNS server CPU utilization on simulator framework

I'm creating my simulation framework, the DNS system. I have two related questions about the name server. I would like to know how much time the Authoritative Name server spends time to resolve one ...
15 views

### How to pick a random index in an array based on the index's value?

While solving a problem on leetcode, I used a heap to give the largest probable value. The problem statement is as follows: Given an array w of positive integers, where w[i] describes the weight of ...
8 views

### Is there any pseudocode of generating special orthogonal group which I can used for reference?

So, I want to include pseudocode of generating special orthogonal group for my thesis and I need something like a paper which I can refer to. I use this Scipy function to generate SO(n) and there is a ...
22 views

### Meaning of this python modulo operator exercise?

I just got started with Python PCEP course material on netacad.com. I've come across the following exercises: 2 % -4 = -2 2 % 4 = 2 As I understand it, ...
13 views

### 3D reconstruction from multiple images

Sorry if it's a trivial question but I'am a beginner. I am working on 3D reconstruction from multi-images project. I am working with these datasets. There is a par.txt file including the camera ...
31 views

### 3D Reconstruction from multiview calibrated camera

I have a calibrated camera whose intrinsics were calculated prior. Suppose I have multi images with the same camera. Using the first two views.I have the 1) initial reconstruction using 8 point ...
62 views

### How to wiggle sort an array in linear time complexity?

The wiggle sort is nums < nums > nums < nums > nums ... For an input: nums = [1, 5, 1, 1, 6, 4], the expected output is ...
50 views

...
30 views

### How would I make sure my compressed string has the smallest length possible?

I'm trying to make a function that takes a string and compresses the repeating blocks. The code I'm using is implemented in such a way that a single character like 'a' would be converted to '1(a)' ...
40 views

...
21 views

### Computing all paths from root to the leaf nodes in a tree

I have a this tree, i want to print out all paths from root to all child nodes: NOTE: I wanted to come up with a solution that does not involve passing state between recursive calls. ...
29 views

### Longest subarray with at most two different values - Runtime complexity for a DP solution

Consider the problem of finding, for a given input array, the longest subarray with at most two different values. For example: ...
17 views

### Reducing Kleene's predecessor for Church numerals

I am trying to "reinvent" Kleene's predecessor myself. The following code snippet should be self-explanatory. The idea is to make a 2-tuple and count up from zero, i.e. ...
154 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 ...
36 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 ...
19 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 ...
20 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 <, >,...
122 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,...
262 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 ...
81 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 ...
36 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?
23 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, ...
45 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) ...
74 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'...
18 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....
24 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 ...
91 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 ...
125 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 ...
65 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 ...
64 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 ...
33 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 ...
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 ...
43 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: ...
67 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 ...
142 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 ...
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$ ...