• Hey, guest user. Hope you're enjoying NeoGAF! Have you considered registering for an account? Come join us and add your take to the daily discourse.

Programming |OT| C is better than C++! No, C++ is better than C

Slavik81

Member
Programming GAF, I have a question with vectors is there a way to find a size 2 x 2 subvector using the member functions?

You'll have to be more specific. What programming language and/or library are you referring to? What are the dimensions of the original vector?
 
You'll have to be more specific. What programming language and/or library are you referring to? What are the dimensions of the original vector?

C++.The <vector> library, and the vector has 63 elements in it. The object is to find a 2x2 array within the vector that has the largest summation of numbers.
 

Slavik81

Member
Sorry, but I'm afraid you won't find one. If I understand what you're trying to do correctly, there's no standard function for it. You'll have to create that functionality yourself.

By the way, I presume your 63 element vector is actually a 64 element vector, and is interpreted to be an 8x8 2D grid. Zero indexed, of course, so the last element has an index of 63. Just a guess, though.

If so, it sounds like a good learning exercise. Good luck!
 

Water

Member
Why do you say that? Genuine curiosity.
When you are writing some random code and need some data structure to hold your data, hashtables are pretty much next in line after (dynamic) arrays; they are just very useful and well-performing in general.
 

leroidys

Member
Why do you say that? Genuine curiosity.

Well aside from just being generally really useful, they've been the answer to at least half of the contrived algorithms questions I've been asked in interviews. They always want to see if you can do stuff in order n time, so traversing linked lists or arrays are usually out by default.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
When you are writing some random code and need some data structure to hold your data, hashtables are pretty much next in line after (dynamic) arrays; they are just very useful and well-performing in general.

Well aside from just being generally really useful, they've been the answer to at least half of the contrived algorithms questions I've been asked in interviews. They always want to see if you can do stuff in order n time, so traversing linked lists or arrays are usually out by default.

Good to know. Thanks
 

OceanBlue

Member
Well aside from just being generally really useful, they've been the answer to at least half of the contrived algorithms questions I've been asked in interviews. They always want to see if you can do stuff in order n time, so traversing linked lists or arrays are usually out by default.

Isn't traversing/iterating through arrays and linked lists O(n) at most?
 

tokkun

Member
Isn't traversing/iterating through arrays and linked lists O(n) at most?

Pretty much every data structure is O(n) to traverse all elements.

A given algorithm may require you to do more than just traversal, though. The key to hash tables is that for a well-designed hash, the average time for search/insert/delete is O(1), whereas for a linked list the average search time is O(n), and for an array the insert/delete time is O(n).
 

OceanBlue

Member
Pretty much every data structure is O(n) to traverse all elements.

A given algorithm may require you to do more than just traversal, though. The key to hash tables is that for a well-designed hash, the average time for search/insert/delete is O(1), whereas for a linked list the average search time is O(n), and for an array the insert/delete time is O(n).

Oh, I see what you mean. I probably need to learn how to use hash maps properly. I always just default to arrays for everything.

Maybe this is why I can't get interviews. :(
 
Best of luck. When in doubt, hashtables!

Thanks! It turns out there were no technical or programming questions in this interview, though...it was just a short "screening" interview. I wish they would have done it over the phone, because it was a 90 minute drive both ways.

I did well in the screening, though, from what the interviewer said, and they're going to have me back for the actual technical interview soon. Then I shall hash all the tables for them!
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Thanks! It turns out there were no technical or programming questions in this interview, though...it was just a short "screening" interview. I wish they would have done it over the phone, because it was a 90 minute drive both ways.

I did well in the screening, though, from what the interviewer said, and they're going to have me back for the actual technical interview soon. Then I shall hash all the tables for them!

Are you a junior/senior going for this internship?
Best of luck on your 2nd interview!
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Guys, I have a more serious question to ask you.

Last month my school decided to revamp the Computer Science program here.
This includes switching to Python for the first introductory course, (ICS 140), and then cramming all of Java into the second course, (ICS 141). This doesn't affect me personally since I have gone through those two courses already, but their logic doesn't make sense to me.
They are also relaxing the math and theory requirements and changing up some of the upper division courses.

This, along with their choice to build a parking ramp + student center instead of their planned Science and Engineering building worries me. I have already thought about transferring to a different school, (similar tuition, similar distance), but I haven't locked myself into anything yet.

I want your input though since most of you here are much more experienced than I am when it comes to this topic. Not necessarily on whether I should transfer, but instead whether these things are worth worrying about.

Below are some pictures I pulled from the document they sent out describing the changes to the curriculum.
d0ehBo2.png
Thanks.
 

usea

Member
That's not worrying by itself. Honestly they're minor things.

Also your department probably has meetings or something where students have some say in changes like that. I know at the 2 major CS schools near me, in one of them there's a yearly meeting with students and alumni about planned changes. It's basically a discussion for a few hours. At another school, the CS students actually have a vote on a board about changes.
 
Have you talked to anybody from the faculty about what they mean by "reducing" the requirements? It could be a much smaller change than you think. It does sounds like it could be moving towards something less 'traditionally computer-sciency' though.
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
Have you talked to anybody from the faculty about what they mean by "reducing" the requirements? It could be a much smaller change than you think. It does sounds like it could be moving towards something less 'traditionally computer-sciency' though.

No, I just found out about it earlier today so I haven't had time to talk with anyone about it. That is a good idea though.
It seems to me like they are steering the focus towards an IT professional (systems administrator, etc.) instead of a computer scientist (software engineer, etc.). That wouldn't be too surprising as this college is geared towards working individuals that are returning to finish their degree or get their first degree.
Then again I could be completely wrong about this whole thing.

Edit: my advisor told me that they revised the curriculum based on student feedback and feedback from outside companies. They felt that some of the courses weren't as important to programming, so they were removed as requirements or revised. The upper level math courses are still available, and I can minor in math still, but they are not requirements for the major.
It gives me something to think about. Friday I will be visiting a different college, (more traditional, classes all week instead of only once a week), so I will take that experience into consideration when thinking about where I want to be this fall.
 
Damn. I am required: Calc I and II, Statistics (intro I and II or applied), Linear Algebra and a math elective (200+) that's not discrete math, plus physics 1 and 2 and their labs.

And of course the only thing I have left after this semester is the math elective :\
 

usea

Member
No, I just found out about it earlier today so I haven't had time to talk with anyone about it. That is a good idea though.
It seems to me like they are steering the focus towards an IT professional (systems administrator, etc.) instead of a computer scientist (software engineer, etc.). That wouldn't be too surprising as this college is geared towards working individuals that are returning to finish their degree or get their first degree.
Then again I could be completely wrong about this whole thing.

Edit: my advisor told me that they revised the curriculum based on student feedback and feedback from outside companies. They felt that some of the courses weren't as important to programming, so they were removed as requirements or revised. The upper level math courses are still available, and I can minor in math still, but they are not requirements for the major.
It gives me something to think about. Friday I will be visiting a different college, (more traditional, classes all week instead of only once a week), so I will take that experience into consideration when thinking about where I want to be this fall.
A lot of schools are "theory-heavy" and produce students who can't actually write code. They focus on PhD prep instead of producing programmers who can get jobs.

To me the changes sound a lot more like preparing students to get jobs as developers, not as system administrators.

You sound pretty down about the change in direction from your school. Honestly it's probably not going to affect you at all. If you want to leave for other reasons that's one thing, but don't make these changes out to be a scapegoat. Don't have a kneejerk reaction. Changes happen to curriculums constantly.

You know more than me about the situation though.
 
Damn. I am required: Calc I and II, Statistics (intro I and II or applied), Linear Algebra and a math elective (200+) that's not discrete math, plus physics 1 and 2 and their labs.

And of course the only thing I have left after this semester is the math elective :\

Same here. I was just about to mention how awesome those requirements are.
 

Joseca

Banned
Hi programming-GAF. I started college a month ago in Computer Engineering in Mexico. I started knowing almost nothing about programming, and I'm getting to know C and C++, also I'm taking linear algebra, calculus and discrete math in this first semester. The thing is, I want to know how classes are in US colleges, because I'm interested on how much of a difference in education there is between here and there. I read that there are colleges that upload videos of some classes (or lectures I think they're called) for free, so which ones would you recommend to watch?

I know this is kind of nonsense, but it blows my mind that in the US college is so expensive and here I'm paying like $100 per semester, and so far, it isn't bad (I think so haha).
 

Granadier

Is currently on Stage 1: Denial regarding the service game future
A lot of schools are "theory-heavy" and produce students who can't actually write code. They focus on PhD prep instead of producing programmers who can get jobs.

To me the changes sound a lot more like preparing students to get jobs as developers, not as system administrators.

You sound pretty down about the change in direction from your school. Honestly it's probably not going to affect you at all. If you want to leave for other reasons that's one thing, but don't make these changes out to be a scapegoat. Don't have a kneejerk reaction. Changes happen to curriculums constantly.

You know more than me about the situation though.

Ok. This is a good way to think about it. Thank you.
There are other reasons why I am looking into transferring, and this was just another thing that came up on my radar recently. I wanted to ask you guys about it to basically get some input from a different perspective than mine.
I have always been really interested in the theory side of topics. The practical portion comes easier to me when I can understand the underlying concepts and how it works. But I understand what you are talking about with certain schools that only teach the theory and don't produce capable programmers. That is less of a worry for me personally than my worry about not getting enough theory to understand those concepts.

Damn. I am required: Calc I and II, Statistics (intro I and II or applied), Linear Algebra and a math elective (200+) that's not discrete math, plus physics 1 and 2 and their labs.

And of course the only thing I have left after this semester is the math elective :\

Same here. I was just about to mention how awesome those requirements are.

Yeah, I was pretty surprised as well because all the other curriculums at different schools that I looked at required those upper division courses for a CS major.

Hi programming-GAF. I started college a month ago in Computer Engineering in Mexico. I started knowing almost nothing about programming, and I'm getting to know C and C++, also I'm taking linear algebra, calculus and discrete math in this first semester. The thing is, I want to know how classes are in US colleges, because I'm interested on how much of a difference in education there is between here and there. I read that there are colleges that upload videos of some classes (or lectures I think they're called) for free, so which ones would you recommend to watch?

I know this is kind of nonsense, but it blows my mind that in the US college is so expensive and here I'm paying like $100 per semester, and so far, it isn't bad (I think so haha).

Holy course load Batman!! How are you still alive taking all those courses at once?

To answer your second question though. MIT, Harvard, and some other schools here have started uploading their classwork so that people can access them for free online.
Here are a couple links:
edX courses
MIT OpenCourseware
Harvard courses through edX
 
am brain farting about this, if someone could help in anyway i'd much appreciate it :)

(java) i need to increment an integer from 000000001 to 999999999. by 1 each time the method is called.

000000001
000000002
....


I can't think of a simple way to do this, unless there are things built into java that can help?
 
am brain farting about this, if someone could help in anyway i'd much appreciate it :)

(java) i need to increment an integer from 000000001 to 999999999. by 1 each time the method is called.

000000001
000000002
....


I can't think of a simple way to do this, unless there are things built into java that can help?

integer++?
 

NotBacon

Member
am brain farting about this, if someone could help in anyway i'd much appreciate it :)

(java) i need to increment an integer from 000000001 to 999999999. by 1 each time the method is called.

000000001
000000002
....


I can't think of a simple way to do this, unless there are things built into java that can help?

You don't need a method for the single operation 'variable++'...

If you're talking about a loop: for 0 to 999999999 { increment }


And guise hashtables are O(1)....
 

leroidys

Member
Isn't traversing/iterating through arrays and linked lists O(n) at most?

Pretty much every data structure is O(n) to traverse all elements.

A given algorithm may require you to do more than just traversal, though. The key to hash tables is that for a well-designed hash, the average time for search/insert/delete is O(1), whereas for a linked list the average search time is O(n), and for an array the insert/delete time is O(n).

You don't need a method for the single operation 'variable++'...

If you're talking about a loop: for 0 to 999999999 { increment }


And guise hashtables are O(1)....

My post wasn't clear. Accessing a single value in a hashtable is O(1). For the contrived interview questions I vaguely mentioned, they want you to take a set of data and do something with it. If finding an element is O(1) and you have to do that n times, you get O(n) aas a starting point for the algorithm. If you want to do something to n elements with a worst case access time of n for each, you get O(n^2).
 

Joseca

Banned
Holy course load Batman!! How are you still alive taking all those courses at once?

To answer your second question though. MIT, Harvard, and some other schools here have started uploading their classwork so that people can access them for free online.
Here are a couple links:
edX courses
MIT OpenCourseware
Harvard courses through edX

Thanks for the links! Bookmarking to check them later.
I don't find it that hard actually. I take 4 hours weekly per course, and there isn't a lot of exams, because the college I go to introduced a new curriculum based more on projects and self-education. Because of that I get to understand better the concepts about programming and math rather than memorizing them and forget them after finishing a test. But I know a lot of classmates that are having a very hard time, mainly because they're kinda lazy to learn more by themselves.
 
integer++?


You don't need a method for the single operation 'variable++'...

If you're talking about a loop: for 0 to 999999999 { increment }


And guise hashtables are O(1)....

to clarify, I need them in that specific 9 digit format as a string.

000000001
000000002


public String increment(String prev)
{
int bob = Integer.parseString(prev);
bob++;

return Integer.toString(bob);
}

but I don't think that would work (on my phone atm so can't test)

}
 

NotBacon

Member
to clarify, I need them in that specific 9 digit format as a string.

000000001
000000002


public String increment(String prev)
{
int bob = Integer.parseString(prev);
bob++;

return Integer.toString(bob);
}

but I don't think that would work (on my phone atm so can't test)

}

Yeah that would kill the leading zeroes on parsing.

just use:

System.out.format("%09d%n", num); //num is an int
 

nOoblet16

Member
Are there any Gaffers here with experience in CUDA programming?

I've been trying to learn CUDA programming following the instructions here
http://www.igorsevo.com/Article.aspx?article=Million+particles+in+CUDA+and+OpenGL

I think I have a pretty decent understanding of the code provided by the guy but when I try to compile his source files I get this error and it's something that came up in a different project as well. I've searched all over but I have no answer as per what it is and how I can fix it.
The two errors I get are

Error 3 error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_10,code=\"sm_10,compute_10\" --use-local-env --cl-version 2010 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.0\include" -G --keep-dir "C:\Users\Praveer\documents\visual studio 2010\Projects\VectorAdd\Debug" -maxrregcount=0 --machine 32 --compile -I -g -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd " -o "Debug\kernel.cu.obj" "C:\Users\Praveer\documents\visual studio 2010\Projects\VectorAdd\VectorAdd\kernel.cu"" exited with code 2.
the bolded part is just the just the runtime API from nvcc command line.

The other error is
Code:
Error 1 error : declaration is incompatible with "time_t time(time_t *)"



I followed every instruction down to the point of making sure they are the same versions and have the same name yet it doesn't works at all. If I can just get this code to compile I can at least start working on it and play around with it. I'd appreciate any help. Are there any alternative to Visual studios for CUDA (with OpenGL) programming on windows?
 

tokkun

Member
And guise hashtables are O(1)....

My post wasn't clear. Accessing a single value in a hashtable is O(1). For the contrived interview questions I vaguely mentioned, they want you to take a set of data and do something with it. If finding an element is O(1) and you have to do that n times, you get O(n) aas a starting point for the algorithm. If you want to do something to n elements with a worst case access time of n for each, you get O(n^2).

I don't mean to be nitpicky, but since we are discussing hashtables in the context of interview advice, where the small details count, I will be.

Hashtables do not always have O(1) access times. The worst-case access time is O(n).

The average access times are a function of the suitability of your hashing function to the input data set and the size of the hashtable. Ideally, this will result in an O(1) average access time, but it is not guaranteed.
 

poweld

Member
since we're talking about hash tables, thought i'd share a moment i had interviewing a candidate a while back.

somehow the topic of hash tables came up, so i thought i'd ask him some basic questions about their workings.

i asked him what would happen in the event of a hashing collision during insertion, would we lose the value currently held at that position? his answer: definitely, yes.

this position was senior level and for a perl shop, so needless to say it didn't work out.
 

oxrock

Gravity is a myth, the Earth SUCKS!
Learning about hash tables right now, good to know that they're actually important :)
 

Jokab

Member
since we're talking about hash tables, thought i'd share a moment i had interviewing a candidate a while back.

somehow the topic of hash tables came up, so i thought i'd ask him some basic questions about their workings.

i asked him what would happen in the event of a hashing collision during insertion, would we lose the value currently held at that position? his answer: definitely, yes.

this position was senior level and for a perl shop, so needless to say it didn't work out.

Damn, for senior level? That's bad even for a summer internship.
 

Water

Member
Damn, for senior level? That's bad even for a summer internship.
Being hazy on hash tables and admitting it wouldn't shut the door to most programming summer internships, I think. Being wrong and confident about something this simple = red alert.
 
tbh, there are a lot of senior developers who don't know about hash collisions. I recently got a new job so I did a lot of studying and learned all about Java Collections but when asking around at my office, hardly anyone fully understood how a hash table would work on a deeper level.
 

Jokab

Member
Being hazy on hash tables and admitting it wouldn't shut the door to most programming summer internships, I think. Being wrong and confident about something this simple = red alert.

I suppose summer internship was a bit harsh. Your second point is definitely true though.
 
since we're talking about hash tables, thought i'd share a moment i had interviewing a candidate a while back.

somehow the topic of hash tables came up, so i thought i'd ask him some basic questions about their workings.

i asked him what would happen in the event of a hashing collision during insertion, would we lose the value currently held at that position? his answer: definitely, yes.

this position was senior level and for a perl shop, so needless to say it didn't work out.

Heck, in C#, it might depend on the way you're accustomed to adding the key and value. With the Dictionary<K,V> class (the modern .NET hashtable), your outcome may differ depending upon what approach you use, so if you're asking from one perspective, and the candidate answers from another, you might simply miss each other.

For example:

Code:
var table = new Dictionary<int, string>();
table.Add(1, "Hello"); // adds key-value
table.Add(1, "World");  // ArgumentException for same key


var table2 = new Dictionary<int, string>();
table2[1] = "Hello"; // adds key-value
table2[1] = "World"; // writes over existing value

If you are a developer accustomed to writing to the dictionary via the first code snippet, then you would expect the second Add to fail. If you are accustomed to writing with the second snippet, you would expect it to succeed. Sure, ideally, the person would know both (as should you), but to be honest, I'm not going to grill somebody over this particular distinction, I have larger problems to worry about for a senior level developer.
 

iapetus

Scary Euro Man
tbh, there are a lot of senior developers who don't know about hash collisions. I recently got a new job so I did a lot of studying and learned all about Java Collections but when asking around at my office, hardly anyone fully understood how a hash table would work on a deeper level.

You don't need to understand how it works to get that question right, though. Just to apply a very small amount of common sense.
 

Chris R

Member
So quick version control question... If I were to COPY a svn repo to a new server would I run into any long term issues? I know the proper thing is to dump and load, but damn if copying stuff over via explorer isn't 1000x faster.

edit: bah whatever, dumping doesn't take that long. Would be nice if I didn't need to command line this though!
 

leroidys

Member
I don't mean to be nitpicky, but since we are discussing hashtables in the context of interview advice, where the small details count, I will be.

Hashtables do not always have O(1) access times. The worst-case access time is O(n).

The average access times are a function of the suitability of your hashing function to the input data set and the size of the hashtable. Ideally, this will result in an O(1) average access time, but it is not guaranteed.

OK, sure, pathological case for hash table is O(n) for any operation.

In the context of an interview question though, you would obviously use an appropriately sized hash table so that you don't get worst possible performance -> O(1)
 

injurai

Banned
so strlcpy isn't part of the standard c library
but strncpy is... is the latter a safe replacement of strcpy?

I ask because anecdotally I was told strncpy is also unsafe. But I couldn't use strlcpy due to linking issues.
 
Top Bottom