Wednesday, December 26, 2012

Introduction to Algorithms, 2nd edition - Chapter 1

Notes

1.1 Algorithms 

Algorithm = Inputs -> Outputs (Specific procedure)

Computational problem = desired I/O relationship (general)...an algorithm defines a specific relationship

Nondecreasing = same or greater

Define computational problem by specifiying I/O

Instance = One input

Correct algorithm = halts on all inputs with correct output

Correct algorithm solves a problem

Specification = Precise description of guts

"Incorrect algorithms can sometimes be useful"

Problems solved by algorithms:

  • Determining sequences (Human Genome Project)
  • Finding good routes; quickly find Internet pages
  • Negotiate and exchange electronic commerce
  • Allocate scarce resources
2-D -> 3-D mapping?

Given = inputs
Wish to find = outputs

Two common characteristics of algorithms:
  1. Many candidate solutions
  2. Practical applications
Data structure = store and organize data to facilitate access and modifications

Problems without published algorithms

Efficiency

Interesting NP-complete properties:
  1. it is unknown whether or not efficient algorithms exist
  2. If an efficient algorithm exists for any one of them, then efficient algorithms exist for all of them
  3. Several NP-complete problems are similar, but not identical, to problems for which we do not know of efficient algorithms
Real world NP-complete problems arise in real world

Traveling salesman

1.2 Algorithms as a technology

Terminates with correct answer

What if infinite speed and free memory?

Good software engineering practice = well designed and documented

Bounded resources (like computing time) should be used wisely

Algorithms are greater than hardware and software considerations

Insertion sort

Merge sort

Constant factors versus input sizes

Running time

Crossover point

Algorithms are important

Algorithms = core of contemporary technology

Algorithm knowledge technique = truly skilled programmer


Definitions


  • Concave polygon (one of the angles surpasses 180-degrees)
  • Permutation (a rearranging of terms)
  • Linear programming (Linear programming (optimization)  is a specific case of mathematical programming (mathematical optimization).
  • Graph
  • Product
  • Vertex
  • Associative
  • Dynamic programming (a method for solving complex problems by breaking them down into simpler subproblems...The word dynamic was chosen by Bellman to capture the time-varying aspect of the problems, and because it sounded impressive.[3] The word programming referred to the use of the method to find an optimal program, in the sense of a military schedule for training or logistics. This usage is the same as that in the phrases linear programming and mathematical programming, a synonym for mathematical optimization.)
  • Constant not dependent on n
  • Pipelining (a set of data processing elements connected in series, so that the output of one element is the input of the next one)
  • Superscalar (a form of parallelism called instruction level parallelism within a single processor. It therefore allows faster CPU throughput than would otherwise be possible at a given clock rate. A superscalar processor executes more than one instruction during a clock cycle by simultaneously dispatching multiple instructions to redundant functional units on the processor.)




Exercises 1.1

1.1-1 Give a real world example in which one of the following computational problems appears: sorting, determining the best order for multiplying matrices, or finding the convex hull.

  • Sorting
    • Sorting files in a directory by creation date
    • Sorting various paper denominations of money
    • Sorting tax return forms by form ID number
  • Determining the best order for multiplying matrices
    • ???
  • Finding the convex hull
    • Identifying area of forest burned by fire

1.1-2 Other than speed, what other measures of efficiency might one use in a real-world setting?

  • Storage requirements during runtime
  • Power consumption
  • Size of hardware
  • Size of software at rest

1.1-3 Select a data structure you have seen previously and discuss its strengths and limitations.
Stack

  • Strengths
    • Simple to implement: two operations, push and pop
    • Push and pop operate in constant time
  • Limitations
    • Not elegant way to traverse elements, since have to pop and store elsewhere in order to inspect and preserve order

1.1-4 How are the shortest-path and traveling-salesman problems given above similar? How are they different?

  • Same
    • Both want shortest path, per constraints
    • Both seem like NP-complete problems
  • Differences
    • Traveling-salesman requires begin and end at same node
    • Shortest-path goes point-to-point

1.1-5 Come up with a real-world problem in which only the best solution will do. Then come up with one in which a solution that is "approximately" the best is good enough.

  • Only the best solution
    • Note: best means no cutting corners, not necessarily "perfection"
    • Everything comes down to acceptable tolerances, in the real world
    • Typically, anything involving human safety in life and death situations
      • Space station airlocks (opening and closing)
      • Airplane auto-pilot systems
      • Traffic control systems (for example, traffic lights)
    • Financial transactions
      • ATM
  • Approximately the best is good enough
    • Pretty much everything else ; o )
    • Point-to-point driving when time not of the essence...probably OK to get reasonably close to a location and then figure out parking, eating, and so forth
    • Pouring a beer...OK to have a bit of foam at the top
Exercises 1.2

1.2-1 Give an example of an application that requires algorithmic content at the application level, and discuss the function of the algorithms involved.
Section 1.1 of this book defines an algorithm as "any well-defined computational procedure that takes some value, or set of values, as input and produces some value, or set of values, as output." Given this broad definition, I suggest the example of a web-based SQL formatter. As input, it takes a sequence of characters representing a SQL query. As output, it produces formatted SQL code, per constraints specified by the user. The algorithm functions as a set of rules which transform the input into the output based on the constraints specified by the user. For example, if the user selects "DB2" SQL as the input and C# as the output, the algorithm logic would transform the inputs into outputs conforming to C# rules.

1.2-2 Suppose we are comparing implementations of insertion sort and merge sort on the same machine. For inputs of size n, insertion sort runs in 8n^2 steps, while merge sort runs in 64nlgn steps. For which values of n does insertion sort beat merge sort?
We wish to find the greatest value of n for which 8n^2 < 64nlgn. Since this seems to represent a transcendental function, I have elected to plug and chug to arrive at the answer. I used OpenOffice.org Calc to calculate the results below:
  • When n = 2, we have 8(4) < 64(2)(1) => 32 < 128, which is true.
  • When n = 4, we have 8(16) < 64(4)(2) => 128 < 512, which is true.
  • and so forth, until n = 44, when we have 15,488 < 15373.8, which is false
Therefore, in this particular implementation, insertion sort beats merge sort for values of 2 <= n <= 43.
1.2-3 What is the smallest value of n such that an algorithm whose running time is 100n^2 runs faster than an algorithm whose running time is 2^n on the same machine?
We wish to find the smallest value of n for which 100n^2 < 2^n. Since this seems to represent a transcendental function, I have elected to plug and chug to arrive at the answer. I used OpenOffice.org Calc to calculate the results below:
  • When n = 1, we have 100(1) < 2^1 => 100 < 2, which is false.
  • When n = 2, we have 100(4) < 2^2=> 400 < 4, which is false.
  • and so forth, until n = 15, when we have 22,500 < 32,768, which is true
Therefore, in this particular implementation, the algorithm with running time 100(n^2) runs faster than the algorithm with running time 2^n for values of n >= 15.
Problems

1-1 Comparison of running times
For each function f(n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem takes f(n) microseconds.

Note: I found this problem statement confusing, initially. The authors treat the computational problem and algorithm as a black box. The black box can solve an input of n items in f(n) microseconds. The authors ask the reader to calculate the largest size n the black box can solve on or before various times (t). For example, for f(n) = n, the black box can solve an input of 1 item in f(1) = 1 microsecond and 2 items in f(2) = 2 microseconds.

We first convert the times in the header row into microseconds (one microsecond = 1/1,000,000 of a second):
  • 1 second = 1 * 10^6 or 1,000,000 microseconds
  • 1 minute = 6 * 10^7 or 60,000,000 microseconds
  • 1 hour = 3.6 * 10^9 or 3,600,000,000 microseconds
  • 1 day = 8.64 * 10^10 or 86,400,000,000 microseconds
  • 1 month = 2.592 * 10^12 or 2,592,000,000,000 microseconds (assuming 30 days per month, on average)
  • 1 year = 3.15576 * 10^13 or 31,557,600,000,000 microseconds (assuming 365.25 days per year)
  • 1 century = 3.15576 * 10^15 or 3,155,760,000,000,000 microseconds
Second, for each cell, we need to calculate the largest size n the black box can solve on or before the specified number of microseconds:


Notes 1 second 1 minute 1 hour 1 day 1 month (assume 30 days, on average) 1 year (assume 365.25 days) 1 century
lg(n) Put both sides on base 2; this converts 2^lg(n) to n. 2^(1 * 10^6) 2^(6 * 10^7) 2^(3.6 * 10^9) 2^(8.64 * 10^10) 2^(2.592 * 10^12) 2^(3.15576 * 10^13) 2^(3.15576 * 10^15)
sqrt(n) Squaring both sides solves for n. (1 * 10^6)^2 = 1 * 10^12 (6 * 10^7)^2 = 3.6 * 10^15 (3.6 * 10^9)^2 = 1.296 * 10^19 (8.64 * 10^10)^2 = 7.46496 * 10^21 (2.592 * 10^12)^2 = 6.718464 * 10^24 (3.15576 * 10^13)^2 = 9.9588211776×10^26 (3.15576 * 10^15)^2 = 9.9588211776×10^30
n 1 * 10^6 6 * 10^7 3.6 * 10^9 8.64 * 10^10 2.592 * 10^12 3.15576 * 10^13 3.15576 * 10^15
nlg(n) Put both sides as an exponent on base 2; since nlg(n) = lg(n^n), this converts 2^(lg(n^n)) to n^n. Transcendental...so we have to do things the hard way. 6.2746 * 10^4 (link) 2.801417 * 10^6 (link to get approximation, then manual refinement) 1.33378058 * 10^8 (link to get approximation, then manual refinement) 2.755147513 * 10^9 (link to get approximation, then manual refinement) 7.1870856404 * 10^10 (link to get approximation, then manual refinement) 7.98161 * 10^11 (link to get approximation, then manual refinement) 6.86565x10^13 (link to get approximation, then manual refinement)
n^2 Taking the square root of both sides solves for n. sqrt(1 * 10^6) = 1 * 10^3 or 1,000 sqrt(6 * 10^7) = 7.745966692 * 10^3 or 7,745 sqrt(3.6 * 10^9) = 6 * 10^4 or 60,000 sqrt(8.64 * 10^10) = 2.939387691 * 10^5 or 293,938 sqrt(2.592 * 10^12) = 1.609968944 * 10^6 or 1,609,968 sqrt(3.15576 * 10^13) = 5.617615152357805 * 10^6 or 5,617,615 sqrt(3.15576 * 10^15) = 5.617615152357 × 10^7 or 56,176,151
n^3 Taking the cube root of both sides solves for n. cuberoot(1 * 10^6) = 1 * 10^2 or 100 cuberoot(6 * 10^7) = 3.914867641×10^2 or 391 cuberoot(3.6 * 10^9) = 1.532618865×10^3 or 1,532 cuberoot(8.64 * 10^10) = 4.420837798×10^3 or 4,420 cuberoot(2.592 * 10^12) = 1.373657091×10^4 or 13,736 cuberoot(3.15576 * 10^13) = 3.1601×10^4 or 31,601 cuberoot(3.15576 * 10^15) = 1.46679335×10^5 or 146,679
2^n Taking lg of both sides solves for n. log(1 * 10^6) / log(2) = 1.993156857×10^1 or 19 log(6 * 10^7) / log(2) = 2.583845916×10^1 or 25 log(3.6 * 10^9) / log(2) = 3.174534976×10^1 or 31 log(8.64 * 10^10) / log(2) = 3.633031226×10^1 or 36 log(2.592 * 10^12) / log(2) = 4.123720286×10^1 or 41 log(3.15576 * 10^13) / log(2) = 4.484305×10^1 or 44.84305 log(3.15576 * 10^15) / log(2) = 5.1486909×10^1 or 51
n! Plug and chug...Wolfram Alpha helps 9 11 12 13 15 16 17

Speeding up playback rate for online videos under Linux

Seems like every link I have found to-date shows how to increase playback rate for online videos under Windows/Mac using Enounce MySpeed plugin or recommends downloading the video to local storage and using a client-side app like mplayer/VLC/and so forth.

Will keep looking.

Friday, December 14, 2012

Time to get classy

From Reddit:

Good evening gentleman/ladies.
  1. Get out your drink of choice.
  2. open 3 tabs on your favorite browser.
  3. On the first tab
  4. On another tab
  5. On the last
All on one page.

Thursday, December 06, 2012

Wool navy trench coat - purchased

Found one after years of looking...for $70 on eBay! : o )











UPDATE: it's a very nice coat. It turned out a bit darker than expected, so more formal than something I would want to wear every day. So, still looking for a grayed navy trench coat. This one looks very nice, though--no complaints.

Clothing measurements

Circa 2012:

Chest: 38"
Neck: 16"
Sleeve: 26"
Shoulders: 19.5"
Waist: 34"
Inseam: 32"
Thigh: 23"
Belly: 38.5"
Torso: 29"
Arm: 12"
Hip: 43"

Reyn Spooner (c. 2024)

Tailored Fit XL Aloha Shirt fits shoulders the best...but this leaves the length too long and the chest a bit baggy

  • Shoulder: 20.3"
  • Chest: 50.6" (slightly baggy)
  • Bottom opening: 48.6" (slightly baggy)
  • Length: 31.8" (slightly long)

Blue Ginger (c. 2024)

Men's medium aloha shirt: fits OK. Shirt measurements of the men's aloha shirt (Taro / Navy-Blue-Multi)(taken while not worn):
  • Shoulder: 21"
  • Chest: 21.5" x 2
  • Length: 26"
  • Bottom opening: ~23"

Sunday, December 02, 2012

Christopher Hayes

Heard Christopher Hayes speaking on NPR a few months ago and he seems like a clued-in progressive.

Proud to be Sanatan

Saw this on a bumper sticker (or something like it) a month or two ago.

This refers to Hinduism. From Wikipedia: "Sanātana Dharma, a Sanskrit phrase meaning "the eternal law", or the "eternal way"."

Cafe Yesterday photos - Berkeley, CA

Some striking photos installed earlier this summer at Cafe Yesterday in Berkeley, CA:

celsa.dockstauer@berkeley.edu

In addition, they have a sandwich named "The Schultz". Nice.

Shower curtains


Looking for a purple and/or gold shower curtain in a traditional Japanese style.


Revenue streams

Earlier this year, I wrote down this pledge:

"I will create a new stream of passive income by Dec 31, 2012, that generates at least $50 per month on average and endures for a minimum of five years."


Thursday, November 29, 2012

Midikat

http://www.midikat.com/

I saw the MidiKat car on the way home a week or two ago.

Radio songs

Heard on 88.9 FM KXPR out of Sacramento, CA:

Alan Hovhaness: Symphony No. 2 "Mysterious Mountain" Opus 132 - Royal Liverpool Philharmonic; Gerard Schwarz, conductor; Label: Telarc; Number: 80604 (audio). The intermittent xylophone sounds like the Legend of Zelda secret passage music. : o D

Audio:
http://www.youtube.com/watch?v=vlXBmIjjzAc (part 1 of 3)

Sunday, November 25, 2012

Putting my head through the firmament - GTD

"A traveller puts his head under the edge of the firmament in the original (1888) printing of the Flammarion engraving."

Via Carl Sagan's Cosmos: Vangelis' Heaven and Hell
http://www.listenonrepeat.com/watch/?v=qDvKsQAafGU (image above appears at 3:51 mark)

A part of me seems to harbor a distrust of "drinking the Koolaid", which has delayed my adaption of GTD.

It seems like taking a leap of faith. When I came back from a summer vacation in 2011, I began focusing on working smarter, to get myself better cope with the heavy workload my position demanded.

Fast forward 14 months--I have read the GTD book, watched a few videos, and am in the process of re-reading it, underlining key phrases and noting critical points.

It feels like standing on the high dive for the first time, looking down at the water, rationally knowing the jump will not kill me, but fearing the unknown and increased risk.

Maintaining a consistent system for both home and work seems to represent the point of procrastination. Do I need a complicated system to track my projects or will a simpler system suffice? David Allen himself seems to make clear the person needs to figure out the complexity needed after collecting everything for the first time. So, now that I have everything collected, I need to process everything for the first time and figure out how complicated a system I need.

Will I see the bang for the buck in using the system? If I adopt something, I want to look smart doing it.

Will I feel the emotional benefit of the weekly review? If I do not, the effort to invest and dedicate time up-front will fail as the review portion becomes the weak link. David Allen recommends thinking about it like brushing one's teeth...after a period of forced habit, it begins feeling "right" to have clean teeth.

Have I invested enough money to purchase the tools I need to succeed? I have a stackable three-level shelf from IKEA, a Brother P-Touch labeler and extra label tape cartridges, a folder holder from Target, the GTD book, paper pads and pens. David Allen uses a few other tools: a BlackBerry, a voice recorder, a scanner, Lotus Notes...none of theses seems like necessities, and I think he would probably agree.

Do I understand the process fully enough to begin the Process phase? After watching a few videos and re-reading the book, the process flow seems straightforward enough....figuring out if I need to take action on each item, doing it if less than two minutes, otherwise deferring it, delegating it, or archiving it.

Can I imagine myself successfully implementing GTD? Yes, I think so, but I have not really thought about how it might feel to have a system in place to move my brain to function primarily as a decision making tool rather than a tool for remembering priorities and actions. I imagine manilla file folder containing...what? Next actions, I suppose, if I choose a paper-based system. A folder for active projects. No, the manilla folders would contain the support material for each of the ongoing projects. With the tiered folder hold showing those I am currently engaged in on a regular basis. I think the Next Actions lists for each Project folder probably deserve a digital format.

Psychologically, having physical folders seems very important, to me. My PhD folder: boom. My @Errands folder: boom. And so forth.

As an aside: people reading this obviously cannot see this, but I have a purple throw on my lap and a very content cat sleeping on it. :3

It seems to come down to: my lazy side complaining about the extra work needed to learn a new habit. Like exercising a muscle. I think I want some reassurance I will feel the emotional benefits of using the new system. From my research, it seems reasonable to feel cautiously optimistic the GTD system will help bring structure to the way I collect my thoughts and process those collections into actionable projects. I will trust my system and lean on it to support my intuitive judgment calls on what to work on next...or what not to work on. I look forward to capturing as much as I can into the system, so I can live my life focused on actions rather than to-do lists.

UPDATE: important to note David Allen does not say this will make life easier...it does not represent a silver bullet...it simply represents a tool to allow people to focus fully on the challenges one identifies as the most important to focus on, at any point in time...it "clears the decks" of the mind, so to speak.

Saturday, November 24, 2012

Vision

The Zendone GTD workflow overview

Thinking through a lot of options for managing GTD; something workable at both home and at the office where corporate IT limits my options (for example, EverNote).

It all boils down to list management; getting everything out of my head and into Collection dumps; then a Process and/or Organize phase for each of the Collection dumps to figure out whether to take immediate action or to Organize it for later or to trash it ... and so forth.


GTD web software

Some web-based vendors:

  • Nirvana
  • Doit.im 
  • ToodleDo
  • ZenDone (wow, beautiful)

Friday, November 23, 2012

Notetaker wallets

Some variations on taking notes while away from a PC:

Principles

"A great way to think about what your principles are is to complete this sentence: "I would give others totally free rein to do this as long as they ..."--what?

David Allen, GTD

Thursday, November 22, 2012

Inuyasha anime run

Chibi Koga, Kagome, and Inuyasha

Hachi (flying form), Shippo (balloon form), Kirara (normal form)

Dawn and I spent the last month making a run through Rumiko Takahashi's Inuyasha.

167 first run episodes + 26 final act episodes + four movies later, we completed the run on Wednesday evening.

Random notes (SPOILERS)
  • Shippo's drawings of Kagome and Inuyasha in Episode 38 (~15:50) at the beginning of Episode 39 looked great
  • Episoe 53 ("Father's Old Enemy: Ryukotsusei"; 父の宿敵 竜骨精) represents one of my favorite mini-clips: Miroku, Sango, and Shippo riding on Kirara...the demon cat sort of just moves statically across the screen...just looks sort of silly, contrasted the audio of the demon cat roar at the same time
  • Episode 68, (""Shippo Receives an Angry Challenge"; 七宝へ怒りの挑戦状) has a cute-looking mini-dragon demon named Koryu...plus more kid drawings by Shippo and Soten.
  • Episode 106 ("Kagome, Miroku, and Sango: A Desperate Situation"; かごめ、弥勒、珊瑚、絶体絶命) shows Shippo's full bag of tricks around the 13:16 mark
  • Episode 130 ("Shippo's New Technique, The Heart Scar!"; 吠えろ七宝奥義 心の傷!) with the young fox demons, was cute
  • Episode 3 of The Final Act ("Meido Zangetsuha"; 冥道残月破), where Shippo advances in rank by pulling tricks on Inuyasha, also was cute
  • We noticed a steady improvement in the production quality as the seasons progressed
  • Hachi, the Tanuki demon, transforms into a floating bus...one of our favorite characters, even though he seems to show a general character flaw 
  • Buyo the family cat seemed really nice...Inuyasha seemed to really like playing with him
  • In the final episode, Inuyasha dumps the twins on Shippo, saying, "Slay the fox"
  • It was weird watching Sesshomaru in the second ending credits in such a melancholy attitude, after watching him as a pseudo-antagonist
  • Ugh, English dub...thankfully, we watched all as English sub...they even say the names of the characters wrong x_x "Kuh-GO-mey" instead of "KAH-go-mey", "Nah-RAH-koo" instead of "NAH-rah-koo" , "Seh-SHO-mah-roo" instead of "SESH-oh-mah-roo"
  • A lot of beautifully-done incidental artwork and audio ... pictures of feudal Japan life, such as cooking, vendors, dress, mountains, shrines, statuary, buildings
  • I think Kagome's mom comes across wonderfully understanding and supportive...almost to the point of incredulity...I suspect she harbors secret superpowers. ; o )
  • Totsai's three-eyed cow seems like a really inventive addition
  • Sexual advances of Miroku really awkward and struck me as not aging well...
  • Favorite song: "Come" by Namie Amuro. (audio)
  • Banzai! Banzai! Banzai! : o )

Tuesday, November 20, 2012

Teeth

Cannot stop looking at them in the mirror after getting them cleaned...so white and perfect. : o )


Blog Archive