Number of times a code is executed [closed] - algorithm

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have a piece of code that says:
for i = 4,16, . . . , n
I am trying to find an upper bound in terms of big oh notation for the number of times the statement gets executed. I believe here it goes like 4,42,43 ... and so on. Since it grows exponentially, it looks like to me that that code is executed about O(logn) times. Am i right? Thanks in advance.

You can confirm your result by thinking in terms of a loop whose index variable is used as the exponent, taking the values 1, 2, 3, ... , floor(log_4(n))

Related

I am at a crossroads in my program and I was wondering which path would be more efficient time wise [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 7 years ago.
Improve this question
I currently see two ways to code the next step of my program and there are probably more, but the two routes I have are as follows.
I take the factors of the lowest number and loop through the other numbers two see if they share those common factors.
I find the factors of the lowest number and add it to a list. I then find the factors of the other numbers that do not exceed the lowest and add them to the same list. I then run through the list to check which is the highest number that appears x times.
I am leaning towards 1, but I'm not sure.
Sorry if this is too ambiguous, thanks.
Well, given the ambiguity, as stated: the 1st requires less steps and avoids the allocation of a data structure.

an algorithm to minimize the total excess [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Imagine that you have ropes which are 5 meters long. And you want to cut the rope in some certain lengths(30 cm,73 cm) for some certain times. I want to write a program that minimize the total length of the excessed robe and tells you how you should cut every rope. But, I don't know where to start and use what algorithm. Can you give me some reference? Thank you in advance.
What you are looking for is so called Cutting stock problem.
Start by looking at this Wikipedia article and follow Suggested readings. I remember we had this as a part of some course back at the university (although I can't remember which one), so you could have a look at coursera.
Seems like homework, but I can still point you in the right direction. What you have on hand is an example of dynamic programming. From what I can understand from your question, you have a sub-case of the ever popular knapsack problem. Which is in essence an optimization problem of using the space on hand most efficiently, thus reducing the waste. Tweak it a bit to your own needs and you should be able to manage to get the solution for your problem.

Linear Probing in Hashing [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
A hash table with 10 buckets with one slot per bucket is depicted .The Symbol S1 to S7 are initially entered using a hashing function with linear probing . The maximum no. of comparisons needed in searching an item that is not present??
I am unable to solve this question. Please explain me how it can be computed in simple language for a learner
Consider what happens when all symbols hash to the same number (say zero for simplicity). How many comparisons are required to insert S1, then S2, etc?

Remove last two digits of number in Ruby [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a number that comes from an external API but it has two extra zeros at the end. What would be a solution to remove the two zeros. I have tried the chomp method and that doesn't work. The number I receive from the API is a Bignum. I am using Ruby 2.
This is a sample input from the API is 1374577200000
This is a sample output I want is 13745772000
If the number is an integer, you can use integer division:
> 123456 / 100
=> 1234
You can't chomp a Fixnum or Bignum, so you'd have to convert it back and forth:
number = 123400
number.to_s[0..-3].to_i

Mathematical function where slow increase at start and fast increase at end [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have number x=[0,n], where n>0.
I want to construct a function y=f(x) such that the value increase slowly from 0 and increase very fast when approaching n, and when reach n, y is infinity. What is a good function to model this?
1/(n-x) - 1/n will work.
There are plenty of other functions log, atan, x^(-k),... that goes to infinity at some point.
a^y is another set of functions with fast grows - maybe more suitable for coding as it can reach arbitrary large (but finite) values.

Resources