Maintain realtime counter [closed] - algorithm

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
The following is an interview question which shows up here and here:
Given a timer time() with nanosecond accuracy and given the interface
interface RealTimeCounter:
void increment()
int getCountInLastSecond()
int getCountInLastMinute()
int getCountInLastHour()
int getCountInLastDay()
The getCountInLastX functions should return the number of times increment was called in the last X
Here's one suggested solution (paraphrased from the above blog entry):
Maintain an ArrayList of timestamps. When asked for a given counter, let's say, the count for the last second, perform a binary search for (timer.time() - ONE_SECOND_IN_NANOSECONDS), and return the list.length() - list_index. Then, as a background process at regular intervals we trim our data. Since we only need to maintain data for the last day, we can delete all entries prior to the last day.
Please critique this solution or offer a better performing one.

Related

How to align long texts? [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 2 years ago.
Improve this question
I want to align a pair of long texts with ~20M chars each.
I've used in the past Smith-Waterman algorithm but (from my limited understanding) it requires creating a 2-dimensional array with the size of the texts (20M by 20M array) - which is not practical.
So I'm looking for an algorithm to align a pair of long texts that will keep a practical memory size and execution time.
UPDATE
I've also tried Myers and Miller using this implementation: https://www.codeproject.com/Articles/42279/Investigating-Myers-diff-algorithm-Part-of
But I still got out of memory exception on "not so large" texts (1MB).

Searching through an list [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 6 years ago.
Improve this question
I'm reading about AI and in the notes it is mentioned
A lookup table in chess would have roughly 35^100 entries.
But what does this mean? Is there any way we could find out how long it would take the computer to search through and find it's entry? Would we assume thereis some order or that there is no order?
The number of atoms in the known universe is estimated to be around 10^80 which is much less than 35^100. With current technology, at least a few thousand atoms are required to store a single bit. I assume that each entry of your table would have multiple bits. You would need some really advanced technology to implement the memory of your computer.
So the answer is: With current technology it is not a matter of time, it is simply impossible.

What takes less time to complete, comparing two variables, or assigning a new value to a variable? [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 6 years ago.
Improve this question
Basically what I'm saying is, which operation takes less time to complete? I know the time it takes to complete 1 of these operations is too fast to measure, but I would assume that there would be some way to explain what happens that could explain which one is faster.
Also, I would assume that comparing two variables would be more taxing on the CPU and assigning a value would be more RAM taxing. Is that correct?
In American football, this would be like asking which is faster:
A running play?
A passing play?
It's too vague, too general to have any kind of sensible answer.

What is the function of state in a pseudorandom number generator? [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 working on a pseudorandom number generator for an assignment and I'm having a hard time wrapping my head around how state is used in it. What does it mean to advance to the next one? I'm not looking for tips on implementation, just an explanation of the concept. Thanks!
A PRNG generates a sequence of numbers.
To calculate the next number, you have some internal state (variables set to specific values, if you will). That's the state referred to in the context of PRNG. This state can often be represented by just a single number.

Given two strings of length, test if the two strings are identical [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 have a algorithmic based question. No code is required, just have to state how I would write this in words. Use n and m as variables if needed, in Java.
Enter the first string in the variable n.
Enter the second string in the variable m.
Compare the two string lengths :
*if they're different , return false.
Scan the two vector , character per character :
*if there's one difference, return false.
Return success.

Resources