Use :first-childand :last-childwith the child ( >) selector :
$("#master > :first-child").addClass("grid_4 alpha");
$("#master > :last-child").addClass("grid_4 omega");
Keep in mind that classes cannot have spaces in them. This markup:
<li class="grid_4 alpha">...
defines a list item that has two classes. If you want to select it, you can use:
$("li.grid_4.alpha")...
, grid_4, .