Sign in to follow this  
Followers 0
zraith

Programming-Issues

5 posts in this topic

Well, I read alot of boks on c and cpp programming, yet none of the books I have read seem to get into the critical thinking part of programming... Take for example, in my book they ahve a sequential searching routine, yet the routine makes no sense... The author doesnt even try to explain it.. The code works, but it doesnt make sense...

I am asking all you 1337 programers to help me here... How did you guys get into programming, what made you stick with it, and what are some must-have resources you use?

I get all the code, but I wouldnt know where to stat on even making a search function for a database...

Thanks beforehand for help....

0

Share this post


Link to post
Share on other sites

I never forced it, it came from wanting to know how programs worked

0

Share this post


Link to post
Share on other sites

Try How to Think Like a Computer Scientist. I've never read it through myself, but I heard it teaches you programming concepts, not just language features. It's a free, online book so you don't have to shell out any dough, plus the book is written in a way that lets you choose from a few different programming languages. I recommend python, but that's up to you.

0

Share this post


Link to post
Share on other sites
Well, I read alot of boks on c and cpp programming, yet none of the books I have read seem to get into the critical thinking part of programming... Take for example, in my book they ahve a sequential searching routine, yet the routine makes no sense... The author doesnt even try to explain it.. The code works, but it doesnt make sense...

I am asking all you 1337 programers to help me here... How did you guys get into programming, what made you stick with it, and what are some must-have resources you use?

I get all the code, but I wouldnt know where to stat on even making a search function for a database...

Thanks beforehand for help....

I think i'd differentiate what you're asking, which seems to be about computer science, from programming. I'll recommend a book first, with the caveot that it's very expensive, but the author does a good job exploring things, and it's a book (technically a series of 3 books) everyone should own.

The Art of Computer Programming, Volumes 1-3 by Donald Knuth. You'll often see them sold together in B&N and Borders. This book is language neutral as a text of this sort should be and if you work through the book, you will have a much more thorough understanding of computer science.

Let's take the topic of searching, you want to find piece of information. The most naive approach is to check each record for the item you are searching. This is the easiest way to approach the problem, and is also the slowest, with the worst case of O(n) (which means you have to visit n nodes to find the information or know it's not in the list, n being the size of the table.

Now, how can we improve this? Well one way is to require the data is in sorted so we can do a more efficient search. A binary search is a search in which you split the table into progressively smaller pieces, based on a greater than or less than comparison.

Let's take a simple example now. We have a 10 element array with the numbers 0-9 in it and compare a linear search to a binary search. In a binary search you always are looking at the index between low and high. Let's take it one step at a time:

We start out, low is 0, high is 9, middle is 4 so we are looking at the 5th element of the array, which is the number 4. Since 9 < 4 we want to increase low to 1 more than the current middle.

Now low is 5 and high is 9, making middle 7. We check the array, and the value is 7, and we want 9, so we increase low again, this time to 8.

Now low is 8, and high is 9, making middle 8. Since the value at a[middle] is 8, and we are looking for 9, we have to increase low yet again, this time to 9.

Now low is 9 and high is 9, making middle also 9. The value is 9, which is what we were looking for, so we can exit the function, we found the number in 4 comparisons. A linear search would have taken 10 comparisons to find the same number.

The beauty of the binary search is it just carves the array into smaller and smaller pieces. The downside is that it requires sorted data in order to function at all.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0