Posts

Showing posts from June, 2013

Searching and Sorting

Introduction to Sorting and Searching Arrays In this blog post, we will be going over simple implementations for sorting and searching lists.  Learning to write fast search and sort algorithms will have an immense impact in the performance of all programs, as many real world applications deal with huge sets of data.  In this post, I will not include Big-Oh notation, which I will write in a later post.  Just worry about speed in a relative sense for now. Sorting using Selection Sort Let us take a look sorting an array first. You are given a random list of numbers in an array, and are told to sort them in ascending order. 9 5 7 3 2 1 8 There are 7 numbers in total in the array.  Now the most basic way of approaching this problem would be to find the smallest number swap it with the front position, but in an unordered list, you have no idea of where that number will be.  Therefore you must traverse the entire list to find the smallest element, besides...

Collections

Introduction to Collections Today I am going to dive into a concept known as "Collections" in Java.  This blog post will be guided by the Collections chapter of Java Tutorials book denoted in the introduction. Collections are defined as an object that groups multiple elements into a single unit. Some of the actions that are associated with Collection are Store - Collections are used to store many elements into one place Retrieve - To retrieve data stored inside of the Collection and return it to who asked for it Manipulate - To manipulate data stored inside of the Collection, but to not change other data. The Java Collections Framework allows us to easily recreate and utilize different data structures so programmers don't have to.   A few benefits includes... Reducing Programming effort Increases Programming speed and Quality Allows communication between unrelated APIs Fosters code reuse You may find yourself asking, "This sounds like some...

Control Flow Syntax

Control Flow and Branching Statements 6.27.2013 I was flipping through the Java Tutorial Book looking for interesting topics, and I found a section called "Branching Statements".  What I found was a different way in how to approach loops.  In this section, it uses 'break' and 'continue' to traverse through the loop.  When breaking from a 'for loop', it will immediately exit from the current loop, ignoring 'if statements' if there are any. Using a break statement in a set of nested for-loops Something that I immediately learned from this is that break only affects loops.  Good on me for paying attention in class!  In addition, the non-labeled break statements will only leave the inner most loop. Take for example this simple code: for(int i = 0; i < 2; i++) { System.out.print("Sam "); for (int j = 0; j < 5; j++) { System.out.print("John "); if (j == 3) break; } } It s...

Start of an adventure!

Today is the official start of my mission to improve my coding skills.  I've been busy getting settled back at home, and finally had time to sit down and start coding. Just for reference, the whole point of this blog is to let me record progress for myself and to keep track of the coding concepts that I learned this summer.  Definitely at the start of this blog, the coding will focus on very rudimentary concepts, but this is only too reinforce my understanding for myself of how to program properly. My goal of this blog is to provide an easy way for myself and others to understand basic and advanced topics in learning computer science. To be clear, I will mainly be focusing on Java.  I will use several different sources including the internet, and book material from: http://amzn.com/0321334205 - Java Tutorial by Sun Microsystems http://amzn.com/0470509473 - Java Concepts by Cay Horstmann will update more sources as they come along... With that, this is the int...