# Tag: big-o

## What is the time complexity of HashMap insertion and retrieval inside of a for loop?

I have written this code for an application but I’m having difficulty figuring out if its better than the legacy code (legacy code used one hashmap with List in every value). From what I understand, since Java 8 the insertion and retrieval from a Hashmap is O(log n) and the for loop is O(n) in my case. Am I correct

## What is the Big O complexity of this algorithm

I can’t seem to figure out the time complexity for this algorithm. I know that the while loop will execute at O(log n) times because n keeps halving. But I’m not super sure how to represent the time complexity of the inner for loop. Answer Each while loop divides n by 2. Therefore, the first for loop would run n

## Kotlin single equal sign “=” object assignment time complexity

What is the time complexity of object assignment using the equals sign in Kotlin (or Java)? More specifically if I have my own object ListNode What would be the copy time below? I find myself often doing this assignment since ListNode passes as val, and I can’t do Answer The assignment does not make a new ListNode object that contains

## Code taking forever to excute when turned to string Java? [closed]

Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 12 months ago. Improve this question When I change the String m1 to a 2D int array it runs

## What’s the time complexity of this anagram checker?

What is the time complexity of this method? I read that time complexity of contains() method of String is O(n) and I’m using it inside my loop that goes over the input string is the time complexity O(…

## How to merge 3 sorted arrays into 1 sorted array in Big-O(N) time?

Trying to merge 3 arrays into one so that the final array is in order. Given Merge the arrays so that the final array d = {1,1,2,3,4,5} Can’t just concatenate them and then sort the d array because that would make the time complexity larger than Big-O(N). This is what I got so far. Having problems with indexes out of

## Big O – O(log(n)) code example

Like the Big O notation “O(1)” can describe following code: What code can O(log(n)) describe? Another question: What solutions are there for “Big O problems” (what to do, when getting a lot of data as an input)? Answer Classic example: This will be: 2k = x → Applying log to both sides → k = log(x)

## A range intersection algorithm better than O(n)?

Range intersection is a simple, but non-trivial problem. Its has been answered twice already: Find number range intersection Comparing date ranges The first solutions is O(n) and the second solution is for a database (which is less than O(n) of course). I have the same problem, but for a large n and I am not within a database. This problem