Skip to main content

All Questions

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
-1votes
1answer
390views

Find base period of sequence in C++

For a sequence of numbers a1, a2,...,an, we say that there is a period if 1≤p<n and if it holds that it is ai=ai+p for all values for which this equality makes sense. For example, the sequence of ...
user avatar
1vote
2answers
225views

Analysis of Algorithms and building of Time Equation?

I'm having trouble figuring out the time equation for a couple small snippets of code. int sum = 0; for (int k = n; k > 0; k /= 2) for (int i = 0; i < k; i++) sum++; int sum = 0; ...
potroast12's user avatar
0votes
1answer
44views

why am I getting a SyntaxError from a loop in python [closed]

Can anybody please tell me what is wrong with this code. Whenever I try to run this I end up with an invalid syntax error. I'm a beginner, I'd be grateful if you can guide me Thank you in advance! ...
Harvey Harris's user avatar
0votes
1answer
319views

Make a program that outputs a pattern of lines whose width and height is based on the number in the input

I want to devise a program to input a positive integer, and by using XX characters – output a figure that has n rows and each row k has k pairs of XX. For instance, if input is 5, the output will be: ...
Sina Heidari's user avatar
1vote
1answer
104views

My nested for loop times out when searching for 2 numbers in an array that add up to a sum value

I'm trying to find a better/faster algorithm that doesn't timeout when I try to find any 2 numbers in an array of numbers that add up to a sum(ex. s). I need to return the pair of numbers that adds ...
JeromeCode's user avatar
1vote
6answers
2kviews

How to use a nested While loops to display Rows and Columns in Java

I am trying to come up with the following output: Row 1 Col A Row 1 Col B Row 2 Col A Row 2 Col B I am having trouble figuring out the logic to complete this task. So far I came up with the code ...
Nicholas Zachariah's user avatar
0votes
1answer
75views

Derivation of runtime for triple nested for loop

I had to do a problem which required me to figure out the runtime for this snippet of code: for (i = 1; i <= log(n); i = i + 1) { for (j = 1; j <= 2*i; j = 2*j) { for (k = 1; k <=...
God's Drunkest Driver's user avatar
1vote
2answers
3kviews

Best and the worst case time complexity for 4 nested 'for' loops?

What is the worst and the best time complexity for nested for loop? int compare(int n, int A[][]) { int i, j, k, m; for (i=1; i<=n; i++) { for (j=1; j<=n; j++) { for ...
rjgupta21's user avatar
0votes
1answer
48views

nested for loops, 2nd for loop based off of the length of the 1st

for my assignment I need to loop through list of words (5757 total) and compare all words with easy other. The words are sorted and I make an array with them all, that's not important, checking words ...
vikiridi's user avatar
0votes
2answers
187views

Generalizing increasing number of nested loop algorithm

Sorry for the terrible title, but I have no clue on how to generalize (or simplify) my loop case here. I have a program that iterates to a sequence of integer, for example dimension=1 to 5. In each ...
Mantas Anni's user avatar
0votes
1answer
64views

Analysis of Running Times

I need to give the running times for the following for loops (in big-Oh notation): sum = 0 for i = 1 to n do for j = 1 to i do sum++ sum = 0 for i = 1 to n do for j = 1 to i^3 do ...
PresumablyZach's user avatar
1vote
2answers
894views

Big O Notation of Java Nested Loops

I am aware of the various rates of Big O such as O(n^2) and O(n), and have no problem determining the Big O value of simple nested for loops such as the following. for (int i = 0; i < n; i++) ...
Increase's user avatar
20votes
7answers
14kviews

Creating N nested for-loops

Is there a way to create for-loops of a form for(int i = 0; i < 9; ++i) { for(int j = 0; j < 9; ++i) { //... for(int k = 0; k < 9; ++k) { //N-th loop without knowing N at the ...
Andrew's user avatar

close