Compare algorithms by time{O(n logn) or O(kn)} and space{O(1) and O(k)} respectively [closed] - python

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
If i have 2 algorithms A and B
Where A uses O(n logn) time and O(1) extra space.
On the other hand B uses O(nk) time and O(k-1) extra space.
What you guys think which one would be a better choice? And why?

Better choice is the one which doesn't exceed memory budget and is measurably faster in production conditions. A reliable way to find that out is measuring.
If you're writing a library that will/may be used in many different environments, then a good choice is to implement both algorithms and let the user choose.

Related

Data Structures and algorithms Sorting algorithm in Python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 days ago.
Improve this question
On geeksforgeeks in Selection sort algorithms it says that "It can cause poor branch prediction due to its high branch misprediction rate" and "Selection sort algorithm needs to iterate over the list multiple times, thus it can lead to an unbalanced branch" as disadvantage. What does it mean by branch or unbalanced branch or poor branch prediction?
I am expecting expaination for the concept of branch in any programming langauge.

Is there a way to compute the cosets of D<sub>2n</sub> in <i>S</i><sub><i>n</i></sub> [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Although this is a question of maths but I really wanted to figure out if something like this is possible or not by coding it .(preferably in C). I had the question posted in mathsstackexchange where I saw that there's a way to find out the cosets of D_12 in S_6 by using Python programming. Can someone just help me to figure out how are we doing this?
S_n is the group formed by all possible permutations of n-elements and D_2n is formed by the generators <r, s> where r =(123, n) and s=(1n)(2 n-1).
Here's the link to the answer
https://math.stackexchange.com/questions/3880306/find-the-cosets-of-d-2n-in-s-n
Also I am not accustomed to posting questions in stackoverflow, I really don't know how to add mathematical symbols.
Though the logic remains same, the implementation will vary from Python to c due to difference is data types and so on. So you should try learning Python, it’s very easy to learn and you can pick up writing code in Python within few days considering you already you know a few other languages. And writing such complex programs can be easy in Python due to the vast inbuilt libraries and readability. So it’s better if you learn Python and start implementing this in Python.

Python Wedding Seating plan [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am getting married in three months and what to attempt create a python code that will pick my seating plan for me as a project to improve my coding further. On the day there will be 10 tables for 100 guests. I want to build a sample to see how effective it is but struggling with ideas on how best to do it as I am fairly new to python coding.
I decided to start with a matrix which determines how much each guest knows each other. The more positive the number the better, the more negative the number the more they dislike each other.
Below is an example: 12 guests try would like to try and get 3 tables. Any suggestions on how to optimize this or a better way to go about it would be greatly appreciated.

Python, efficiently and easily substitute parts on very long string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a big file with some format. I want to substitute some items in the string by others, the string is long (like a big XML but with no format).
I know where they are, i could locate them by using a regular expression for each, but i wonder which is the best method, easier and better if its the most efficient way.
format/% already searches the string for parameter placeholders internally. Since they're implemented in C, you're not gonna beat their performance with Python code even if your search and replace workload is somewhat simpler. See Faster alternatives to numpy.argmax/argmin which is slow for a glance on C to Python relative performance.

Convert number to corresponding words [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to develop a piece of code that converts a number to the corresponding words, e.g. 1 -> "One", 2 -> "Two"
Is there any function in Python to do this task?
The answer to this question is "no". There is no function in Python to do this task.
If you "have to develop code to do it" (your words), then using a builtin wouldn't really be a valid solution, perhaps?
If you have to develop code to do it, you need better specifications. Do you have to be able to just do 0..9, or any cardinal number, or any number at all? (floating point? decimal? negative?). Why do you have to develop this code? Is it homework, or some special purpose?
If you just have to do 0..9, then as mentioned in comments, you should use a dictionary. Take care of case of the input.
If you have to do anything more than that, looking at the implementation of num2word would certainly be educational.

Categories

Resources