Sunday, June 3, 2007

The C Tutorial

Ok, this blog is actually a segment devoted to a friend or two...
The tutorial will cover basics of C concepts, and implementations of a couple functions.

Part I - Basics of C
Arrays and Pointers are ideally the same. Actually, the name of an array is the same as a pointer to its first element. In simple terms a pointer is just an unsigned int, with "special powers." Pointers have the ability to go to the address it holds and access the data type T, if the pointer is of type "pointer to T" (T *). An array can be thought of as a T * const type, that is the address that it points to cannot be changed.

Also, you can think of there being the most basic unit of pointers, the char*, since a char is one byte. In any event, I will give some examples to demonstrate this:

struct A a;
struct A* pa = &a;

pa points to a struct, or put another way, pa holds the address of a struct A type.
*pa will go to the memory location that pa currently holds and extract the type to which it points, namely the type is struct A.

so

*pa holds the exact same object of "a" in the example above.

Since, the universal pointer is the char*, we can access each byte of the "a" object like so:

char *c = pa; // point to the starting address of "a"

We can scan through every byte, but there is something essential we must know about incrementing a pointer:
If we have a pointer of type T, then incrementing the pointer by one is equivalent to doing:
T *p;
p + 1 ; // increment by one
start at p's address and add sizeof(T) bytes to get "p+1"

That's why a char* is universal, everytime you increment a char*, it gets increased by only one.
Thereby, letting you move freely within any aggregate data type, using a char*.

Malloc() is a function call that returns an address; ideally, you just cast to the proper T* for proper assignment. However, if you understand what pointers are, then it's legal to just assign it to an unsigned int. (if you cast correctly)


Malloc, basically keeps track of a header that will hold the total size of the current block, as well as have a flag to check if it's currently in use. Free() knows the size of this magical header and will set the flag back to unused, so that this memory can be used again some time later. Think of the header something like so:

struct malloc_header {
size_t totalSizeToAllocateIncludingHeader;
char isBeingUsed;
};


So when you call malloc(), it's actually adding the size of the header to the total number of bytes to allocate:

int MALLOC(size_t size) {
return size + sizeof( struct malloc_header);
}

where the standard malloc() will return
the total number of bytes actually needed.

and when you call free, it moves back sizeof(struct malloc_header) bytes to get to the header and unset the isBeingUsed flag and deallocate that block of memory.

Another concept that should be known is pass by value and pass by reference. In C, there is no such thing as pass by reference. However, there is a hack to get passed this dilemma. Just pass a pointer (address of an object), and if you change the value through this pointer, then the object will be changed after the function call. That's the entire concept of "trying to make C parameters pass by reference." An example follows:

void func( char *c ) {
*c = 3;
}

char c = 5;
func(&c);
// c is now 3 after the function call

Address-of operator is a nice operator to have. Bascially, it just does a look-up on the type that is using the address-of (&) operator and returns a pointer of that type. For example,

char c = 3;
char *d = &c; // c's type is "char", so &c returns a pointer to type char, char*
char **s = &d; // d's type is "char*", so &d returns a pointer to type char*, char**

char a[3];
&a is of type char (*)[3], because a is of type char[3], therefore it's a pointer to an array of 3 chars.

Common things to know about strings. In C, there is a little problem with C-style strings, as they call it. They are basically null-terminated strings, meaning, they need to end in the integer value 0, or ascii char value '\0'. It's basically a hack that was agreed upon. If this value is not present, none of the string library functions will work for you. Also, string literals (sequences of characters in double quotes) always end with a '\0' (null-terminator character). Therefore,
"hello" is actually seen as hello\0 by the compiler. There are some differences when assigning string literals though.

In pointer notation:
char *s = "hello"; // s points to the address where 'h' is located
char s[] = "hello"; // s contains the string 'h', 'e', 'l', 'l', 'o', '\0' as its elements in the array
The value of s, in both cases hold the address of a char that has value 'h', though they are NOT the same address, but they both hold the same value.

Function calls in C -
Basically when a function call is executed, an activation record is set up and added to the stack.
First what happens is that the parameters to the function get added, then the return address get added, and then the local variables (sometimes called automatic variables) are added to the stack. They are popped back off the stack in reverse order. That's why they tell you to NEVER return the address of a local variable. (It's automatically deleted)

*You should know fork(), waitpid(), wait() and semaphores/locks *

Part II - Examples (Code)
int atoi(char *str) {
// str holds "1235"
char isNeg = str[0] == '-'; // is it neg?

int i, currValue = 0;

/* if we multiply currValue by 10, we are shifting the currValue to the left */
/* for example, say we have "23" and currValue = 2, currValue * 10 = 20, so
currValue * 10 + 3 = 23
*/

for( i = isNeg; i < strlen(str); ++i )
currValue = currValue * 10 + (str[i]-'0'); // shift it to the left and add an integer if( isNeg ) currValue = -currValue; return currValue; } char *itoa(int number) { char isNeg = number < number =" -number;" s =" (char*)malloc(32);" count =" 0;" t =" s;" count =" 0;" half =" size/2;" i =" 0;" i =" 0;" curr ="="" next =" curr-">next;
curr->next = prev;

return reverse(curr, next);
}

// iterative solution
struct Node * reverse( struct Node *head) {
struct Node *prev = NULL;
while( head ) {
// keep track of the next Node* in the list
struct Node *next = head->next;

// let head's next pointer be its previous
head->next = prev;

// update the pointers for prev and head
prev = head;
head = next;
}
return prev;
}

// inorder traversal for a binary tree
void inOrder( struct Node *root ) {
if( !root ) return;

inOrder(root->left);

/* print out the value of this node */
printf("%d\n", root->id);

inOrder(root->right);
}

Thursday, May 31, 2007

Interviewing tips Part I(for UWF students)

Ok, this is part one of a sequence of blogs that are directly correlated to help UWF students get jobs at the top tech companies in the nation, and even, the world. There has been a lot of hype that UWF students just end up at Harris Corporation or at Space and Naval Warfare (SPAWAR), and can't do any better. This blog (out of many) will help enlighten that false prophecy of where a UWF CS graduate *can* end up.

The blog concentrates on the courses that actually help the UWF graduate prepare for interviews. Of course, one needs to worry about the items in their resume. Be it true or not, you need to know what's on your resume and how to elaborate on the selected items during the interview. (Since that is all the interviewer has to go off in bringing you in for an interview in the first place) In any event, the first part is to know the in's and out's of your resume.

Foretelling what the interview questions are highly unlikely, but there are a couple things to consider and which courses will help in aiding the student to get passing marks in the interview. The questions for a top company will generally come from questions regarding OOP, syntax/coding, OOP-implementation in a certain language, datastructures, algorithms, and system programming-specific concepts. The language of choice is almost always C or C++. However, if the questions regarding OOP and OOP-implementation tend to crop up, then it's a viable choice between C++ and Java. Otherwise, you'd best stick to C and C++ to do well on the interview.

Given that information, the courses that are most pertinent for the UWF student are as follows:
DataStructures and Algorithms
Analysis of Algorithms
Intermediate Programming
Operating Systems


That's about it -- just four courses that need to be studied. However, that ends up being a lot of material to be familiar with. I will break down the essentials that need to be taken from the courses:
Intermediate Programming - OOP concepts, how to implement OOP concepts, differences in other languages (i.e., Java vs C++ with regards to inheritance)

Operating Systems - system programming concepts - threads, process, PCB, synchronization, IPC, thread scheduling, library vs kernel threads, as well as the dining philosophers problem.

Datastructures - various datastructures, problem sovling capability, and time complexity.

Analysis of Algorithms - time complexity, memoization, greedy algorithms, and the infamous TSP.

Here's a short list of the actual concepts that *someone* has studied that got that *someone* passed many interviews:
OOP - inhertiance, virtual functions, pure virtual functions, abstract class vs interface, multiple inheritance, virtual function implementation (C++), and polymorphism (what it means to be polymorphic as well as examples to show polymorphic behavior)

Threads - Kernel vs Library, communication between threads - mutex/semaphores, thread synchronization - CS (critical section), and the dining philosopher problem.

Algorithms/Datastructures - everything about linked list and tree structures. (The complexity for algorithms with trees is almost always O(n*log(n)) with the log(n) as being the key feature to go from top->bottom of a tree) "Know your time complexity of the algorithms"

any comments on what else should be studied throughout the UWF course curriculum? :)
Next blog will cover some specific concepts in C that should be known.
(Hint: pointers are evil)

Sunday, May 27, 2007

I have education, but I'm not educated...

Courses taught in school these days are a bit lacking.

For example, a lot of courses are taught in full Java, including Operating Systems. Refer to Joel on Software if you are inclined to thinking that Java is useful for teaching, edifying, and promoting students to think on their own.

In any event, this post is to ponder the actual education learned while in school. I was referred to a student that he was "in school, but not being educated" and "what is the point of school if you don't learn"...

Therein, lies a great paradox that probably won't be answered by the end of this writing, but I will definitely try a poke at it. So, students know that teachers don't really care about the students, and that there is a lot of material to learn, and the teachers usually give a half-ass lecture on the subject and then provide a way for you to fail the course by giving explicit material that was NOT covered in lecture. They seem to like to fail students with a smile on their face, and wonder why students don't really like them?! But the point is that teachers aren't really teaching their students anything anymore. I can go into specific detail, but I doubt it's really needed. This post is not for the professors as much as it is for the students. Students from all over can testify that this is the case. Though it probably isn't 100% true, it is true for the general public.

Therefore, how do students actually learn? Well, it's the environment, some would say. I don't necessarily disagree with this idea. If you are in a good and learning environment, then it's easy to be educated by other students. The environment is good and manageable to learn something. However, what happens when you have a poor learning environment, and the teachers, well... suck. I guess you're virtually screwed, and without a good job, to boot. With that said you have education, but aren't educated. Therefore, what we need is to have the best of both world, good environment and good teachers. But that's a perfect world, and well, teachers and the environment is somewhat NOT perfect. Anyways, just thoughts to ponder...

Friday, May 18, 2007

Stress...

Stress, that's the theme of this post...

What makes a person have spasms and fits of rage? Sometimes, it's seen when there is an overload of pressure and stress. The pressure, stress, and hard work for students studying Computer Science boils down to basically a 30-45 minute interview with a company.
This can be actually quite funny to watch. Possibly, the most entertaining event out there is when a CS graduate flares up in, but a moment after being unable to answer particular interview questions. I mean, this is their livelihood on the line. For the sake of the money, for the sake of the career, and for the sake of reputation, all your years of studying boils down to a couple questions, or even a "question" of the entire existence of your career path.
I don't know about you, but that's hella scary. There is a story of which someone has seen, and inevitably, had to be told. So, let's go on with the story here. A CS graduate had an interview with Google for a possible Software Engineer position. What a great chance to work with one of the top companies in the nation, and even the world! However, there's a reason why Google is the best. They hire the best, and that means hard interviews, and for which a good story behind the interview. In any event, as the interview went along. The complexion and reaction of the CS graduate was overwhelmingly changing and changing. And it wasn't for the betterment of the one being interviewed. Sadly to say, his appearance seemed like in a confounded state, ready to pounce on anything that seemed to go by him. If anything was a hint of what was going on his mind, the shaking of his head repeatedly throughout half of the interview should've been an indication of how stressful continuing the interview was! So the interview ends, in which happens to be a closure and more shaking of the head continues. So, the interview is over and the stress is done with, right? Think again, the CS graduate turns and puts his hands on his hips and shakes his head repeatedly. Then he grasps for the air as if it were a substance to be reached and then his hands turn to fists powering down onto the desk with a heavy, strong, and boisterous *thump*, literally heard by everyone in the small building. Possibly, that has quenched the stress and pressure of doing badly on the Google interview. Well not quite, he goes and punches the wall, constantly saying, "I knew that SHIT! I knew that SHIT! How come I get interviewed by someone who can't speak proper english, and on a phone, no less!" Interestingly enough, after the yelling, screaming, and utter disappointing shock of doing badly, he leaves the room and the building.
This has a little to do with stress and pressure on CS graduates trying to get into the top companies that they study so hard while in college to get into. More or less, it's too much stress that the students go through while competing with one another. Ideally, some have the "no stress-no pressure" mentality... well, that's before the interview. Not many have the effect of doing well under stress and pressure, or at least the stress and pressure come out and show, just like our young CS graduate that bombed the Google interview.
The story is funny, true, and unbearable to keep yourself to not laugh at. I mean, this has to be one of the funniest things to capture, possibly on a YouTube.com moment. Anyways, this is just one of the many stories that are out there with failed interviews and stressful moments. But I have a good friend that is going for a Micrsoft interview next week, and was joking with him how the stress factor is going to come; maybe not now, but he'll see. But good luck to him on that, and good luck to all that have to feel the stressful threat of interviewing and work through that eventful day.

Thursday, May 17, 2007

UWF Graduates doing OK

Throughtout the massive posts that seem to discredit UWF, there are some success stories. I guess I will dive into the current curriculum at UWF before going into some of these "success" stories.
The curriculum is similar to any other CS-school out there. Some professors are actually elite. Let me highlight some of the schools that the professors graduated from as well as some of the Ph.D. schools that UWF has to offer:

Massachussetts Institute of Technology (MIT) - Math/Operations Research
University of California San Diego (UCSD) - Comptuer Science/Engineering
Ohio State University (OSU) - Computer Science/Engineering
University of Michigan - Mathematics
University of Texas - Mathematics/Philosophy
State University of New York - Stony Brook (SUNY) - Mathematics
University of Cairo - Egypt - Computer Science/Mathematics/Engineering
Michigan State University (MSU) - Computer Science
College of William and Mary - Computer Science/Engineering/Philosophy
University of Southern Mississippi - Computer Science/Engineering/Mathematics
University of Alberta - Mathematics
University of Waterloo - Computer Science/Mathematics
University of Toronto - Computer Science
Purdue University - Mechanical Engineering
University of Ulm - Computer Science/Engineering

The wealth of diversity in the faculty is great. Some of the UWF faculty have even worked for AT&T Bell Labs. Many contracts with NASA, Motorola, and LANL are tied to UWF. However, for some reason, the professors are NOT pursuing options for the students at UWF to jump on board. This is quite unusual. If anything, they are missing out in class, just for their conferences and intense schedule with research on these oh-so-many contracts. Including student participation on some of these projects might even make it worthwhile for attending UWF's CS dept. But I guess that's not a major concern now since they have recently hired a Chemistry professor to take over the Engineering, Physics, Computer Science, and Mathematics departments.

In any event, there is some point to this babbling going on today.
Ah, yes, the success stories.
I've talked about a student gaining entrance into Microsoft from UWF. Though, it was through an "in," so I guess that's a good thing for UWF's reputation.
There are a couple students that are doing really well that are UWF alums.
Currently, they are not residing in the state of Florida anymore, however, they are achieving an income of greater than $65,000 USD (which is higher than the average starting salary for MS graduates) Touche for them!

I guess I'm stuck here writing this blog, and totally wish I could make that type of money, eh?!
Anyways, to each his own. But the point is that UWF indeed has a good faculty, good resources, good contracts for research, as well as good students. The only thing I see lacking is the need for the professors to latch onto students to help them grow and create an environment where the faculty and students can cooperate on a learning and educating plateau. This would totally increase the chances for students to actually have a job by the time they graduate.

And I'm not talking about some of these crappy web development jobs out there that pay $50,000 that does not require much thinking involved. It's time that UWF contribute to the actual research in the area, and that is NOT including IHMC, the non-profit organization that pays up to its type of organization. Yeah, that's right, "NON-PROFIT" and that ain't no joke. I mean, come on. $7.50/hr for undergraduates as being testers... and $10.00/hr for graduate students interning. I think I'd make more at McDonald's on any given day, and that's without a 4-yr degree at a university that IHMC says they sponsor. That's totally bogus, especially since the main head guru used to be a faculty member at UWF. Talk about low-balling the purchase price for a UWF-alum that's concentrated in Computer Science. Some graduates need to actually pay off their bills, not stack them up, even after graduating college!?!

Anyways, that's the need that UWF currently has, and I think, if UWF actually stepped up to the plate, they could definitely spearhead the future technologists to compete with the current market in California, Seattle, DC, and New York. That's my opinion. I mean, the professors at UWF know how to teach, and some of them do it fairly well. Now, all that's left is to actually get some of the professors to care about their students. Why the hell would you even get into teaching if you did NOT care about the students. Are you just saying random things that the students don't understand, and then saying, "I DID MY JOB." What kind of load of crap is that? And what kind of load of crap is it where the professors teach a subject where they haven't dived into fairly much without code. I mean, if your'e going to teach Networks, you should at least know how to do some coding. Your lectures should be at least well-prepared. There is no excuse for not being prepared as a professor. That's your livelihood... no one really cares if you have a pretty face and hooters, teach the damn subject! (not really pointing to anyone but yeah)

Um yeah, so the point is that UWF's faculty is really good, but they should have more of a caring attitude with respect to their students. I recently read an article about Condoleeza Rice, when she was an Associate Professor at Stanford. Students would actually come to her with their problems, not related to school, just their problems. And she said she actually spent time talking to them about their problems, and figuring out the best way to approach the problems. I mean, she's awesome... a teacher that cares, who would've thought that actually would've been important!
But anyways, the point is that UWF is a good school, and their material is the same as any other school, but if they cared more about their students, the students could make a more meaningful impact in the world. But I guess since all the UWF graduates that are doing OK don't care much about that, they're more inclined to go for the jobs that pay more money. Is that really what the CS degree is for? Do we study 4-5 years for a degree to join a financial company that does great things, but why is UWF creating financial programmers/developers? Anyways, I guess students (graduates) will work in whatever field they chose, but at least guide them in the right area... (By the way, there is nothing wrong with being a financial programmer if that's what you want to do, but why do it if it's not.)

On a last note, a professor (who actually cared) asked his student, "You should try to get into a good school for your Ph.D.; you're smart, and I think you have potential. Or you could just get a job and make money, but I thought you might want to do something better than that." This, in essence, drives the spirit that teachers who care are more awesome than teachers who are there to make money and work on their own research.... than say, inspire their students to revolutionize the world.

Any comments?

Engineering Students at UWF

Computer Science internships/co-op's have been discussed recently for UWF students. However, let me take some time to elaborate on internships/co-op's for engineering students. First of all, there is so much melodramatic trauma with dealing with the Co-op office. They handle everything as far as dealing with the business aspect of setting things up for the co-op for the students, or do they?
I will go as far as to say they actually get in the way of the co-op's for the engineering students. Although, the "office" they hold seems to set everything up, they are not very helpful at all. It's more like a self-esteemed "you represent me" scam that they are so self-indulged within themselves that they are only hurting the situation for the students, whereas the engineering students find the co-op's by talking to other students than any help from the co-op office.
Let's not even talk about that ghettofied, unglorified, so-badly-pathetic, cursed thing they call the UWF Career Page Website for helping and to aid in the search for co-op jobs. This is so hardcore ugly and unhelpful that it actually contained a fair amount of webpages written in the spanish language. I know we are in Florida, and there are a lot of people of the spanish/hispanic descent, but that's ridiculous.
But that's enough bashing the career site and the career office for now. But I was told that an engineering student makes almost $13/hr for a co-op job that he has to devote himself for 3 semesters long. That's decent here in the Pensacola, FL area. Hopefully, he gets all the experience needed to find a job.
The closure of this posting is that I would like to know from students at other universities if their career office is as lame as UWF's. The fact is that UWF's career office only gets in the way. I'm wondering if that's how it is for all other schools. It's hard to say, especially since I have never talked with any students at other universities. But I look forward to any comments on this post. Any UWF students partaking in current co-ops are free to post a comment, and I would love to hear your horror story :)

Sunday, May 13, 2007

Amazon & Microsoft

Ok, here's the deal -- the only way to get into Amazon and Microsoft is through an "in" and if you can't get in there in the first place, the "in" probably is lacking.

That's the moral of the story from a post in a blog I read. The guy also talks about his girlfriend/wife got an offer from Amazon, so that was his "in" and furthermore, he talks about the interview process of Amazon. Of course, it's a bit lacking because he didn't want to disclose all the information from the Amazon interview.

But he talks about how the first phone interview went ok. The second phone interview went terrible, and how he thought he wouldn't have a good chance to get offered an on-site interview round, which is the third (3rd) round if you do well enough on the first two (2). (Which is ideally what all the good companies do - Google, Amazon, Yahoo!, and Microsoft)

In any event, this guy describes his situation and how he baffled the 2nd phone interview. But he did well enough on the first phone interview to get a shot at the on-site round. He lists how he felt, what he wore, and what hotel he stayed at during this entire spiel of events. This is all nice and dandy. He even quotes a lot of the major interview questions (shouldn't there be some type of NDA?). Anyways, it seems that he did well, though I forget if he actually got the job.

However, the jist of the blog was that there's no way you can get into Amazon without an "in" and therefore, how are UWF CS graduates supposed to get that "in"? A friend told me that a CS graduate actually had an "in" from Microsoft and he eventually got a job with Microsoft when he graduated. That's awesome, if he had done it on his own. But anyways, this "in" thing sorta sucks for those that don't have it...

I want to leave a question with anyone reading this ridiculously lame blog:
"If I don't have an 'in' will I be able to ever land those types of interviews, seemingly that I will only carry out the 'email your resume and see what happens' strategy? Since I don't have an 'in' anywhere, how is it even remotely possible to even fathom that I can get into one of the large companies with the knowledge gained from UWF and its professors?"

Next time, we'll talk more on the engineering studies at UWF.