I’m having some difficulty understanding the prompt of this algorithms problem. via /r/learnprogramming


I’m having some difficulty understanding the prompt of this algorithms problem.

This is the prompt:

Describe an algorithm to sort a list of n integers, each in the set [0..n3 − 1], in O(n) time. Justify the correctness and the running time of your algorithm.

When I think of sorting in O(n) time, I think selection sort (which has been covered in my class, along with insertion sort (O(n2)), merge sort (O(n log n), and quick sort).

What's throwing me off is the phrase "each in the set [0..n3 − 1]". I'm not entirely sure why my professor feels the need to make this point. The way I'm interpreting it is that if I have an array with 5 integers, this means that largest value integer could be (53 – 1). So what? Is this going to have any effect on my algorithm, or am I interpreting the problem wrong?

Submitted October 31, 2015 at 07:24PM by pfftStupidScholar
via reddit http://ift.tt/1GF3OzA

I’ve been off/on programming for a few years now. Short, simple programs, no issue. But when it comes time to put everything together to make a game like tic-tac-toe/etc. I lose my mind. via /r/learnprogramming


I’ve been off/on programming for a few years now. Short, simple programs, no issue. But when it comes time to put everything together to make a game like tic-tac-toe/etc. I lose my mind.

I've been wanting to learn C++/SDL for ages now. For whatever reason I just can NOT progress. I'll get into programming, then get frustrated and stop for months.

It may have to do with overthinking. I don't know. But when it comes time to use certain things to accomplish something (ie, arrays, nested for loops, etc, anything with +=, ++, –, etc. At first I'm like "ok, I see what's going on". But when it comes time for me to try it out myself I'm lost.

When I was programming I was using LazyFoos SDL tutorials.

As the lessons progressed, the less I could do myself.

Submitted October 31, 2015 at 07:40PM by Genocide3883
via reddit http://ift.tt/1kj73Ss

[Help] encryption and shifting numbers around via /r/learnprogramming


[Help] encryption and shifting numbers around

I need to Replace each digit with the result of adding 7 to the digit and getting the remainder after dividing the new value by 10. Then swap the first digit with the third, and swap the second digit with the fourth. Then output the encrypted number to a text file called dataout. How do I go about splitting up a 4 digit integer and performing the necessary tasks using loops?

 import javax.swing.* ; import java.io.* ; public class Project5E { public static void main(String[] args){ final int QUESTION_BOX ; int input ; QUESTION_BOX = JOptionPane.QUESTION_MESSAGE ; String number = JOptionPane.showInputDialog (null, "Four Digit Number:", "", QUESTION_BOX); input = Integer.parseInt(number) ; for (int x = 0; x<1; x++) { PrintWriter encrypted = new PrintWriter("D:\Coding\SoftwareEng\dataout.txt"); 

encrypted.println(input)

 } } } 

Submitted October 31, 2015 at 06:49PM by Flauk
via reddit http://ift.tt/1WqgKLe

Array Preorder traversal[C++] via /r/learnprogramming


Array Preorder traversal[C++]

http://ift.tt/1WnHmBP

My program should first read in the number of nodes in the tree and a left child, middle child, and right child array representation which it does. The number of nodes doesn't exceed 10. It does do this. Here is a sample input:

7
2 -1 4
3 5 6
-1 -1 -1
-1 -1 -1
-1 -1 -1
-1 7 -1
-1 -1 -1

However, whenever I try to perform a pre order traversal I am confused on how to write a function that would work for all trees. My professor said that the algorithm should be recursive, and I'm not sure how to implement that either.

Submitted October 31, 2015 at 06:31PM by Shpank_Dog
via reddit http://ift.tt/1GSSlMl

I’m Scared to Start Programming via /r/learnprogramming


I’m Scared to Start Programming

Programming and coding has always been a passion of mine, I have really wanted to take on both, right now I am fluent in HTML and CSS, and I know a little PHP. Now, here's the catch I am a designer, and I know when it comes to the tech industry, it is very rare that someone can do both programming and designing well. I have started to look at things like LUA and Javascript, and unlike HTML,CSS,PHP, it just doesn't seem to "click", I am not sure how long I should spend with it, I seem to learn coding and programming extremely well if I am taught by a teacher, not including Youtube videos. Someone. Tell me where to start, and what I should do.

Submitted October 31, 2015 at 06:37PM by erucae
via reddit http://ift.tt/1GSSlw1