Skip to main content

All Questions

0votes
2answers
72views

Trying to figure out the best and worst case time complexity of a function. Is it possibly that worst and best case are the same?

I've been asked to find the best and worst case time complexity "in terms of their running time as a function of input size, n." I'm pretty new to Big O but I was doing okay will the other ...
Mia Good's user avatar
2votes
1answer
96views

Populate A Function Handle "Array" in MATLAB

I have the following function handle uppercase K and array of lowercase k and gamma values. N = 3; k = randi([1,1000],N+1,1,"double"); gamma = randi([1,100],N+1,1,"double"); K = @...
Jonathan Frutschy's user avatar
1vote
1answer
205views

Populate the Diagonal Elements of An Array MATLAB

I have the following matrix C that I would like to recreate in MATLAB: In this case uppercase C is an N = 3 by N = 3 matrix, but I would like to generate C for any size of N by N. I randomly create ...
Jonathan Frutschy's user avatar
-1votes
2answers
577views

Optimizing a Nested Loop Algorithm for Maximum Efficiency

I'm working on a project that involves processing a large dataset with nested loops, and I'm struggling to optimize my code for maximum efficiency. Here's my current approach, which I know is not ...
prabu naresh's user avatar
-1votes
2answers
76views

Optimizing Python Code for Finding Index Pairs Meeting Specific Inequality

I have a Python code that efficiently solves my task, but I'm concerned about its time complexity. The task is to find the number of index pairs (i, j) where the inequality aᵢ ⊕ aʲ ≥ bᵢ ⊕ bʲ holds ...
Maxviz's user avatar
1vote
1answer
85views

Is this algorithm with three nested loops O(m*n) or O(m*n^2)?

i'm doing a code challenge for funzies and trying to determine the time complexity of my solution. it's been a minute since college so i want to confirm i'm doing this analysis correctly. here's the ...
Turner J's user avatar
2votes
1answer
717views

How do I write a python function to maximize sum of N X N upper left sub-matrix from given 2N X 2N matrix?

I have this problem to solve: Given a 2N x 2N matrix of integers, you are allowed to reverse any row or column any number of times and in any order. The task is to calculate the maximum sum of the ...
micahondiwa's user avatar
1vote
1answer
79views

Running time of 3 nested for-loops, where the innermost loop depends on the operations in the outer loop (not an obvious case)

I'm a beginner here studying algorithms for the first time. I'd like to know the running time of the following algorithm with 3 nested for loops. I know in most cases it's the lengths of the loops ...
CodingPup's user avatar
0votes
4answers
4kviews

To remove duplicate elements in an array and only show unique one

I made a program to remove duplicate elements in an array, but it is not working correctly. Can someone help me with it? When I input 1,1,1,2,3 it displays 1,1,2,3. It works fine with other inputs, ...
Divyam's user avatar
0votes
2answers
179views

How to make Python to run 4 nested loops faster?

I have 4 nested loops in my Python code and it takes ages to finish all the loops when the grids are big. For example, here is a piece of my code: from itertools import product T = 50 beta ...
Zuba Tupaki's user avatar
0votes
2answers
397views

Use nested C loops to produce the following out put

Am a beginner in C and I came across this question, How to produce the following pattern using C nested loops BBBBBBB BBBBBB BBBBB BBBB BBB BB Code # include <stdio.h> int main() { int Row, ...
Eric paul's user avatar
0votes
1answer
55views

Big O notation of nested loops

function compressBoxesTwice(box1, box2) { box1.forEach(function (boxes) { console.log(box1); box2.forEach(function (boxes) { console.log(box2); }) }) } compressBoxesTwice(); ...
Hamza Baig's user avatar
-2votes
1answer
72views

What is the big O of a nested loop when the inner loop is of variale length?

What is the time complexity of this? The outer loop is O(log n). But I am not sure about the inner loop? Is it O(log n) also? Would that make this entire algorithm O(n log n)? while (n > 0) { ...
Zuse's user avatar
  • 103
0votes
1answer
112views

generating a nth prime number without using 'isprime()' function

there is no output for the code when the input exceeds two. import java.util.Scanner; class PrimeNumberFinder { static boolean is_prime(int number ,int[] prime_numbers) { boolean is_prime =...
Pranshu's user avatar
-2votes
2answers
684views

Leetcode jumpgame recursive approach

Given the following problem: You are given an integer array nums. You are initially positioned at the array's first index, and each element in the array represents your maximum jump length at that ...
sotn's user avatar
  • 2,131

153050per page
close