Category "big-o"

Understanding the Big O for squaring elements in an array

I was working on a problem where you have to square the numbers in a sorted array on leetcode. Here is the original problem Given an array of integers A sor

Sorting Arrays Before binary search will Take big O (n)?

When i was learning about Big O Notations , while getting to know the binary search algorithm as it requires sorting the array before searching . I had a questi

What is the Big O notation for string.Contains() in GoLang?

strings.Contains(str, substr) N = len(str) M = len(substr) Is Average case = O(N/2 + M) Worst case = O(N - M)?

What is the time complexity of while loops?

I'm trying to find the time complexity of while loops and I have no idea where to begin. I understand how to find the complexity class of for loops, but when it

Finding Big O of the Harmonic Series

Prove that 1 + 1/2 + 1/3 + ... + 1/n is O(log n). Assume n = 2^k I put the series into the summation, but I have no idea how to tackle this problem. Any he

Does printing a string really take O(n)?

I was doing an example from Cracking the Coding Interview and I read that executing System.out.println(prefix); (where prefix is a String) would take "O(n) time

What's the difference between big O and big Omega?

Big Omega is supposed to be the opposite of Big O, but they can always have the same value, because by definition Big O means: g(x) so that cg(x) is bigger or

Nested for loop in Big Oh Complexity

for(int i = 0; i < n; i++) { for(int j = 0; j < i; j++){ // do swap stuff, constant time } } I read that single for loop is O(N) and trav

Explain the answer of this Big O complexity code

for( int bound = 1; bound <= n; bound *= 2 ) { for( int i = 0; i < bound; i++ ) { for( int j = 0; j < n; j += 2 ) { ... // c

How to find the winner(s) of Brazil's Mega Sena lottery most efficiently?

Mega Sena is Brazil's most famous lottery. The number set ranges from 1 to 60 and a single bet can contain each from 6 to 15 numbers selected (the more numbers

What is O(log(n!)) and O(n!) and Stirling Approximation

What is O(log(n!)) and O(n!)? I believe it is O(n log(n)) and O(n^n)? Why? I think it has to do with Stirling Approximation, but I don't get the explanation v

Using Big O Notation, what is the correct label for this algorithm?

I am curious. What is the correct way to describe this using Big-O Notation? var prices = [100, 180, 260, 590, 40, 310, 535, 10, 5, 3]; var biggest_profit = 0;

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 int[] a = {1,3}; int[] b = {2,4}; int[] c = {1,5}; Merge the arrays so that t

Can hash tables really be O(1)?

It seems to be common knowledge that hash tables can achieve O(1), but that has never made sense to me. Can someone please explain it? Here are two situations

Can hash tables really be O(1)?

It seems to be common knowledge that hash tables can achieve O(1), but that has never made sense to me. Can someone please explain it? Here are two situations