Skip to main content

Posts

Compiling and Executing Java Files With -cp

I decided I was going to "man up" and figure out how to compile a java program with an external dependency from the command line instead of relying on an IDE-- the DOS command line, to be more specific. I ran into a few problems: 1.  The external dependency was given to me as a java file.  I experimented compiling it as a .jar, but I wasn't sure how to import a class from a .jar, so I ended up compiling it into a class. 2.  When I tried to run the file, I got an error saying that the class had been compiled with a different version of Java than my JRE.  The Internet told me to check my path variable for Java.  It sure looked like it was pointing to the latest JRE (and the same version of Java as my compiler).  I asked the Internet again and found the following command: for %I in (java.exe) do @echo %~$PATH:I I'm not exactly sure what the syntax of that magic command is (intuitively it's returning the path that executes when I run the "java" com...

Shell Sort Notes

I don't understand this passage.  What are the two alternatives? ( Algorithms , 258) One way to implement shellsort would be, for each h, to use insertion sort indepen- dently on each of the h subsequences. Because the subsequences are independent, we can use an even simpler approach: when h-sorting the array, we insert each item among the previous items in its h-subsequence by exchanging it with those that have larger keys (moving them each one position to the right in the subsequence). Have to research different implementations of Shell Sort.  Would also help to clarify the mistake I made in my discussion yesterday. Having said that, I can think of two possibilities.  Given, for instance, h  of 3   and a sequence: 1 2 3 4 5 6 7 8 9 -- two methods would be first : Compare and exchange 1 and 4... ...2 and 5 ...3 and 6 ...4 and 7 ...5 and 8 ...6 and 9 -- or second : Do an insertion sort on 1, 4, and 7 Do an insertion sort on 2, 5, and 8 ...

Shell Sort

Today I spent a little bit of time researching the "Shell" sort.  I wanted to post a few notes about the Princeton Algorithms Course's implementation to help me solidify my understanding. First, a little tidbit.  When I first heard about this algorithm, I thought it had something to do with shell games.  Turns out a man named Donald Shell discovered this method of sorting, whence the name. The Algorithms  book gives the following explanation (Sedgewick and Wayne,  Algorithms, 4th ed., p. 258): The idea is to rearrange the array to give it the property that taking every hth entry (starting anywhere) yields a sorted subsequence. Such an array is said to be h-sorted. Put another way, an h-sorted array is h independent sorted subsequences, interleaved together. By h-sorting for some large values of h, we can move items in the array long distances and thus make it easier to h-sort for smaller values of h. Using such a procedure for any sequence of values o...

Diary

First day as a TA at Coding Dojo Worked up through the automated testing portion of the Django official tutorial Didn't have time to do any algorithms -- learned about a path-finding problem (2D array represents connections between nodes -- determine whether there is a path from A to B for arbitrary A and B) e.g. for nodes A, B, and C [ [0, 1, 0] , [0 , 0, 1], [0, 0, 0] ] First entry says A is connected to B, second that B is connected to C -- so there's a path from A to C. The connection relationship is not robust.  A can be connected to B without B being connected to A.  It must however in some sense give rise to another relationship that is at least transitive.  If A and B are connected, and B and C are connected, then I can get from A to C.  This does not mean, however, that I can get back from C to A. Initial thought was do something with recursion.  Too complicated.  And what if you have loops?  Now it seems you just need a way to trans...

How To Get More Out Of Tutorials

We all follow tutorials.  Coming up with an idea for a new app, including the scaffolding and the specific functionality, is hard.  Struggling through something on your own can be valuable and helps you internalize it, but you also risk "reinventing the wheel" if you fail to take advantage of the resources and experience available from those who have "done it before."  Tutorials help you work through an ambitious project step by step and "learn while doing."   But blindly copying someone else's code without knowing why you are doing what you are doing can severely limit your learning.  Use the following steps to get the best of both worlds -- a dedicated teacher who will guide you every step of the way through the app you want to make AND a system that will hold you responsible for what you learn and help you to internalize it so that you can generalize specific steps for future pet projects (or work assignments). 1. Pause The Tutorial Pause t...

Starting A New Project In Django

Purpose What follows are streamlined notes following Django's web app tutorial . Project Assuming that you have Python and Django installed and, if needed, are running the appropriate environment, you begin a project by navigating to the desired project directory and running the command django-admin startproject <project name here>  This creates a directory for your project with the basic file structure. App A Django app encapsulates some site function (e.g. registration). To create a Django app, run the following command in the directory where you want to implement it: python manage.py startapp <app name here> As of Django 2, it appears that the app is automatically registered with the setup (settings.py), saving time. Errata.   Above I stated that an app does not need to be "installed" in Django 2.  This is not correct.  To install an app (necessary for using app models), add <app name>.apps.<app name>Config (e.g. Example...

Implementing A Queue With An Array

I'm working on coding an array implementation of a queue in Java.  The implementation should have the following features: The array has a head  which marks the item least recently inserted. The array has a tail  which marks* the item most recently inserted. Enqueue() adds an item to the tail of the array. Dequeue() removes an item from the head of the array. The array will resize()  dynamically as it gets too small or too large. Size()  returns the size of the queue from head to tail. IsEmpty()  returns whether or not the queue contains anything at all. You start out by initializing an empty array.  It looks like this: [0]  null  (head / tail) So at the beginning, the head is set to zero.  I guess the tail can also be zero.  Then you enqueue. [0] "To" (head / tail) So the first time you try to enqueue, the head is null.  Fill the head.  Now you want the tail to move up.   H...