|
Code bootcamp grad here with around 3 months of experience hacking css/javascript with an occasional couple of hours on python when I need to do something and no one else has gotten to it yet. I have imposter syndrome really bad so on the weekends I try to write algorithms in C. This week was randomized array search with what should be an average running time of O(n) (taken from a coursera algos course). Here's how it's going: code:
The Makefile is a little hectic, but i guess that's what happens when you're trying to figure out make? I tend to use make and other basic unix stuff quite a bit at work, so it pays to get more familiar with these basic utilities. Given that background, am I doing things that are obviously insane? The code could definitely be cleaner, but at least from a first approximation, how does it rank against a first or second yr CS guy?
|
# ? Nov 24, 2014 05:13 |
|
|
# ? Apr 26, 2024 23:00 |
|
replace dem while loops with a find the element function (replace dat test with randomized property test)
|
# ? Nov 24, 2014 05:31 |
|
Algorithm aside, why C instead of C++? It has a lot of convenient features C doesn't, like objects, iterators, and even the ability to define variables whenever the hell you want, not just at the top of the function like C. If you're scared of all the fancy C++ features like polymorphism and template meta-programming, you don't have to use those (in my experience, most people use them badly). Unless your job relies on running algorithms, I wouldn't worry about them unless you enjoy puzzling them out. A lot of CS guys use them as dick-waving contests but then turn around and don't know much about actual computer functions like threading or I/O. Also, if you want to share code, there are sites where you can paste code in your browser and share a link with someone, where they can examine and even run the code. Try http://cpp.sh/
|
# ? Jan 8, 2015 23:39 |
|
Here's a few comments: Avoid hardcoding the length of the array ("while (i < 5)") as it breaks if you add or remove numbers from the array. You can use the idiom ("sizeof(data)/sizeof(data[0])") to determine the number of elements in the array, which in this case is 5. I personally like to define a macro to simplify that: code:
You may also want to familiarize yourself with the "for (initializer; condition; increment)" method of writing loops as they're very idiomatic and would simplify some of your while loops. For example, in C99 the first loop could be written: code:
code:
ExcessBLarg! fucked around with this message at 01:06 on Jan 9, 2015 |
# ? Jan 9, 2015 01:03 |
|
sudonim posted:Algorithm aside, why C instead of C++? Also, the above examples could just as well be C++. With what he's doing, the two languages are nearly equivalent anyways. sudonim posted:Unless your job relies on running algorithms, I wouldn't worry about them unless you enjoy puzzling them out. A lot of CS guys use them as dick-waving contests but then turn around and don't know much about actual computer functions like threading or I/O. A common weakness of code bootcamp folks is they don't have the same background knowledge of algorithms and data structures that are commonly taught in sophomore CS courses. The result is that when faced with a problem of moderate complexity they may end up implementing an unnecessarily complicated or inefficient due to not knowing better. So these kinds of thought exercises are entirely appropriate to fill in for what background knowledge may be missing.
|
# ? Jan 9, 2015 01:14 |
|
ExcessBLarg! posted:A common weakness of code bootcamp folks is they don't have the same background knowledge of algorithms and data structures that are commonly taught in sophomore CS courses. The result is that when faced with a problem of moderate complexity they may end up implementing an unnecessarily complicated or inefficient due to not knowing better. So these kinds of thought exercises are entirely appropriate to fill in for what background knowledge may be missing. My bootcamp recognized this flaw and attempts to fix it by fitting in a section on algorithms and data structures. I still feel like I need a bit more teaching on the subject though, because I'm really picky about doing things the "best" way (which I realize doesn't usually exist). Anyway my point is we're not all CS-retarded
|
# ? Jan 10, 2015 18:44 |
|
Is there a recommended book on Amazon about data structures and algorithms?
|
# ? Jan 10, 2015 21:43 |
|
Don't gently caress around, get Cormen: http://www.amazon.com/gp/product/02...2BGKD5BGR3QQPD6 The only issue I have is that it's a bit too comprehensive (so it can be tough to tell what the most important sections are). Most college classes cover only a few chapters. Luckily the MIT Intro to Algorithms class uses this book, so their syllabus is a good place to start.
|
# ? Jan 11, 2015 00:00 |
|
|
# ? Apr 26, 2024 23:00 |
|
evensevenone posted:Don't gently caress around, get Cormen: http://www.amazon.com/gp/product/02...2BGKD5BGR3QQPD6 Done. Thank you much
|
# ? Jan 11, 2015 09:58 |