What is the time complexity of this loop where it only runs one time? [closed] - while-loop

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 2 years ago.
Improve this question
This questions was asked in Expedia Summer Intern test
We need to find the time complexity of this while loop?
int a=1;
while(a<3){
a=a+2;
}

this is O(1)
this is exactly one iteration.
a exceeds the bound of the loop which is 3 (after one iteration);

Since no input dimension affects the number of operations, the asymptotic complexity is constant.

The time complexity for this code is O(1). Because it is a single loop with finite number of iterations.
Reference: https://www.geeksforgeeks.org/analysis-of-algorithms-set-4-analysis-of-loops/

Related

Normal distribution of input data [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Should I normalize input data to normal distribution before fit it into RNN? If yes, why? At the moment almost all the columns are right shifted, so it's not a normal distribution at all.
You do not necessarily need to transform the inputs to a normal distribution, but you might want to preprocess them so that the majority of each of their values is between 0 and 1. Otherwise, when using sigmoid functions for internal nodes, you may cause saturation. If your inputs are each U(0, 1000), for example, then there's no need to transform to normal distributions, but rather to just scale by 0.001.

Counting Kernels of Corn [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 7 years ago.
Improve this question
I'm looking for some guidance here. I primarily am a frontend developer. What I am trying to figure out is how an algorithm can be implemented to count kernels on an ear of corn.
From my initial research it seems there are a couple of different directions to go. Main ones I have seen are a SIRF type of implementation and others call for conversion to the HSV color space or LAB color space in order to then to normalizations and then counting.
For reference usually the corn that will be counted is "dent" corn. Here is an example:
This will be implemented in VB.net, but I can always translate the algorithm if needed.
Thank you for your help!

Increment counter or query relations? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
Let's say I have a User model and a Favorite model. I want to know how many favorites a user has.
I see that you can accomplish this in two ways.
Atomically increment a counter attribute on the user model when a favorite is created. Access using user_instance.favorite_count
Query the favorite count for the user: user_instance.favorite_set.count()
I would imagine that as the DB grows, counting becomes more expensive.
Which implementation is more scalable?
I smell some premature optimization here. Databases are extremely good at counting things. Unless you have measured and are seeing some identifiable slowness, you should not attempt to denormalize: it is difficult to get right and always at risk of getting out of sync. Go with the query; and don't forget you can use aggregation to query the counts for a queryset of users at one time.

Are there other programming techniques? [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 have realized that most of the problems that I solve on a day to day basis are done via two programming techniques: iteration or recursion.
Are there other techniques out there? Any book recommendations or online references?
the programming techniques that you use to solve the problems can be divided into types of algorithms (not into the loop or technique they use in there program, like you mentioned). some of the methods are..
1. Divide and conquer
2. greedy
3. dynamic programming
you can refer this link to read more..

Is using many variables good practice? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I always tend to declare a new variable every time I have some heavy treatment(e.g. mathematical operation) to store the result within.
Is it a good or a bad practice?
Well, one of my first programs (solving a quadratic equation) had 30 variables and I felt so proud that I managed it lol. However too many variables which are unnecessary will kill the readability big time and you're going to start having troubles.
I'd say it's a double-edged sword. Use too many and you fail, use to little and errors start to happen.
Aim for making it neat so you have minimal troubles locating yourself and figuring out what's happening.
Good luck!
:)