Algorithms

Spring 2011
course
navigation

March 3

homework

Discuss; see where we are.
See attached python (improved and completed graphs.py) for 3.2a and 3.2b.

chapter 4 topics :
1. Discuss how to implement a breadth-first search, and the use of stacks and queues in non-recursive tree searches.
2. Discuss the idea and method behind Dijkstra's minimum path algorithm. Mention the "greedy" approach.
3. Discuss the notion of a "heap", and simple vs sophisticated implementations.
What is the O() runtime of Dijkstra's with a good heap? What is the O() of the heap operations?

midterm check-in

languages methods analysis structures classic problems --------- ------------------ --------- ----------- ----------------- python brute force O() linear array sorting C divide-and-conquer linked lists etc FFT greedy queue, stack graph properties heap
Midterm project? Spring break timing? Discuss.

system("dot ...") issue

Looks like I was doing some unclean stuff in my binary_tree.c from last week.
I put in an unintentional "race condition": since I didn't close the "tree.dot" file explicitly, and fired up the "/usr/local/bin/dot" immediately, it was possible that the .dot file wasn't in a finished writing state before the dot program tried to use it. Trying to replicate a problem Ned was getting gave me situations where the .png file was empty ... without getting any errors.
So here's the improved code.
// Write 'tree.dot' graphviz file, // and use that to create a .png of the graph. void make_dotfile(node tree){ FILE* dotfile; int status; if ((dotfile = fopen("tree.dot", "w"))==NULL){ printf("Oops - error opening tree.dot\n"); exit(1); } fprintf(dotfile, "digraph tree {\n"); write_dot_node(dotfile, tree); fprintf(dotfile, "}\n"); status = fclose(dotfile); // Here's the bugfix: close tree.dot before using it. printf(" fclose(dotfile) returned %i\n", status); printf(" -- making dotfile ... \n"); status = system("dot -v -Tpng < tree.dot > tree.png 2> tree.stderr "); // -v is "verbose" printf(" system(dotfile...) finished; status=%i \n", status); }
That does several things more thorougly:
http://cs.marlboro.edu/ courses/ spring2011/algorithms/ notes/ March_3
last modified Thursday March 3 2011 2:23 pm EST

attachments [paper clip]

     name last modified size
[IMG]3p2a.png Mar 3 2011 2:00 am 33.8kB [IMG]3p2b.png Mar 3 2011 2:23 pm 29.7kB    graphs.py Mar 3 2011 2:00 am 9.85kB [IMG]random_20.png Mar 3 2011 2:00 am 171kB