My Explanation On The Automata Assignment

Here is my homework for Automata Theory.
Pardon me for not being able to use MSPaint efficiently. ^^

As far as I can remember, the homework was to convert an NFA diagram to a DFA diagram.

Here's the NFA diagram:


Using subset construction, I am able to determine the states and state transitions.

δD({q0},a) = δN(q0,a) = {q1}

δD({q0},b) = δN(q0,b) = {q2}

δD({q1},a) = δN(q1,a) = {q3}

δD({q1},b) = δN(q1,b) = {}

δD({q2},a) = δN(q2,a) = {}

δD({q2},b) = δN(q2,b) = {q4}

δD({q3},a) = δN(q3,a) = {q3} U {q6} = {q3,q6}

δD({q3},b) = δN(q3,b) = {q3}

δD({q4},a) = δN(q4,a) = {q4} U {q6} = {q4,q6}

δD({q4},b) = δN(q4,b) = {q4}

δD({q3,q6},a) = δN(q3,a) ∪ δN(q6,a) = {q3,q6} ∪ {} = {q3,q6}

δD({q3,q6},b) = δN(q3,b) ∪ δN(q6,b) = {q3} ∪ {} = {q3}

δD({q4,q6},a) = δN(q4,a) ∪ δN(q6,a) = {q4,q6} ∪ {} = {q4,q6}

δD({q4,q6},b) = δN(q4,b) ∪ δN(q6,b) = {q4} ∪ {} = {q4}

δD({},a) = {}, δD({},b) = {}

From the subsets above we can produce this DFA:


However, we can still simplify the DFA (above). I'm not sure about the rules in simplifying DFAs yet, so I hope this will suffice for now:


Please leave your comments if I'm wrong or if I had broken some rules.

Read More ..

J2ME RecordStore Example


import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.rms.RecordEnumeration;
import javax.microedition.rms.RecordStore;
import javax.microedition.rms.RecordStoreException;

/**
* Preferences Store
*
*Create a class that can persist program preferences. The class will store the preferences into a Record Store.
*Each record will have a variable name and value. Each variable/value pair is stored in a single record.
*The name and value are stored in the database as Strings.
*
*The class should implement these methods:
*public String readVar(RecordStore recStore, String name, String defaultValue)
*public void writeString(RecordStore recStore, String name, String value);
*
* @author calcifer
*
*/

public class PreferenceStore extends MIDlet implements CommandListener{
private Display display;
private Command exit;
private Command write;
private Command read;
private Command back;

private Form inputForm;

private TextBox output = new TextBox("Your Preference:", "", 250, TextField.ANY);
private TextField varName = new TextField("VarName:", "",32,TextField.ANY);
private TextField varValue = new TextField("Value:", "", 32,TextField.ANY);

private RecordStore recStore;

private Alert success;

public PreferenceStore(){
inputForm = new Form("Preference");

exit = new Command("Exit",Command.EXIT, 0);
write = new Command("Write", Command.OK, 0);
read = new Command("Read", Command.OK, 0);
back = new Command("Back", Command.BACK, 0);

output.addCommand(back);
output.setCommandListener(this);

inputForm.append(varName);
inputForm.append(varValue);
inputForm.addCommand(exit);
inputForm.addCommand(write);
inputForm.addCommand(read);
inputForm.setCommandListener(this);

success = new Alert("","Successfully Added!", null, AlertType.INFO);

}

public void startApp() {
try {
recStore = RecordStore.openRecordStore("Preferences", true);
} catch (RecordStoreException ex) {
ex.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
if(display == null){
display = Display.getDisplay(this);
}
display.setCurrent(inputForm);
}

public void pauseApp() {
}

public void destroyApp(boolean unconditional) {
}

public void commandAction(Command c, Displayable d){
if(c == exit){
notifyDestroyed();
try{
recStore.closeRecordStore();
}catch(Exception e){e.printStackTrace();}
}
else if(c == write){
display.setCurrent(success);
writeString(recStore, varName.getString(), varValue.getString());
varName.setString("");
varValue.setString("");
}
else if(c == read){
output.setString("");
output.setString(readVar(recStore, varName.getString(), varValue.getString()));
display.setCurrent(output);
varName.setString("");
varValue.setString("");
}
else if(c == back){
display.setCurrent(inputForm);
}
}

public void writeString(RecordStore recStore, String name, String value){
String newItem = new String(name + value);

byte[] bytes = newItem.getBytes();
try{
recStore.addRecord(bytes, 0, bytes.length);
}catch(Exception e){ e.printStackTrace();}
}

public String readVar(RecordStore recStore, String name, String defaultValue){
StringBuffer sb = new StringBuffer();

try{
RecordEnumeration enumerator = recStore.enumerateRecords(null, null, true);
while(enumerator.hasNextElement()){
String item = new String(enumerator.nextRecord());
String val = new String(name + defaultValue);
if(item.equals(val))
sb.append(item);
}

}catch(Exception e){e.printStackTrace();}

return sb.toString();
}

}

Read More ..

Interesting Computer Programming Quotes

I'm back! I have here some of the most interesting Computer Programming related quotes. Enjoy! ^^

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning.
* Rick Cook (or Rich Cook?) [citation needed]

The effective exploitation of his powers of abstraction must be regarded as one of the most vital activities of a competent programmer.
* Edsger W. Dijkstra, The Humble Programmer, 1972 Turing Award Lecture, Communications of the ACM 15 (10), (October 1972): pp. 859–866

There is no programming language, no matter how structured, that will prevent programmers from making bad programs.
* Larry Flon

No matter how slick the demo is in rehearsal, when you do it in front of a live audience the probability of a flawless presentation is inversely proportional to the number of people watching, raised to the power of the amount of money involved.
* Mark Gibbs

To me programming is more than an important practical art. It is also a gigantic undertaking in the foundations of knowledge.
* Grace Hopper, quoted in Management and the Computer of the Future (1962) by Sloan School of Management, p. 277

Premature optimization is the root of all evil.
* Donald Knuth, "Structured Programming with Goto Statements". Computing Surveys 6:4 (December 1974), pp. 261–301, §1.

Computer Science is embarrassed by the computer.
* Alan Perlis, "Epigrams on Programming"

Computer programmers never die, they just become lost in the processing.
* Anonymous

Computers can never replace human stupidity.
* Anonymous

Good programming is 99% sweat and 1% coffee.
* Anonymous


Read More ..

Fun Comic Strips

src: http://xkcd.com
Just click the comic strip to view a clearer image of it.
Enjoy! ^^

Game Theory


Qwertial Aphasia




Estimation


Cutting Edge


Extrapolating


Period

Read More ..

Increasing Virtual Memory In XP

I have posted here an easy and affordable tip to solve your 'low memory' problems in Windows XP.

To give you an overview, we are going to increase the system paging file size of your computer. System paging file is also called virtual memory. Virtual memory is part of a secondary memory that is used as if it were primary memory.


To increase the virtual memory of your computer, follow the steps below:

1) Go to 'System Properties' via the 'Control Panel' then click the 'Advanced' tab.

2) Inside the 'Performance Options' panel click the 'Settings' button.


3) Click the 'Advanced' tab then press the 'Change' button.


4) Select the disk volume you would like to use.

5) Set the 'Initial Size' and 'Maximum Size' according to your preference.


That's it, you're done. ^^

Note:
There are some OS's that automatically adjusts the virtual memory for you when you are encountering a 'low memory' problem.

Read More ..