Sunday, January 23, 2011
Lessons learned from computer science interviews
In the program to understand we have logical parts such as input, output and logical main. To start with your program
:> Identify the returned stuff. Say int is returned to find max out of an array
:> Put a logical method name with proper input or receiving parameters
:> In the start of the program initialize some variables if required
- counter, start and end pointer to string, length of the string
:> if recursive program then check on null or exit conditions in start of program.
:> in recursive program the return can be associative with recursion.
- i.e. return ( node.value < node.right.value && checkTreeisBST(node.right) )
:> do a dry run after finishing the program and test it for edge conditions
A good guide to programming questions is Crack the Interview . Here the answers are wrong but questions are right. So don't trust the answer.
Wednesday, January 12, 2011
XML Parsing Techniques
Pull Parsing:
Application has to pull the next node or element from the parser. Application asks the parse to next node. Pull parsing does not do varification (checking the xml against schema) however definitely do verification.
Push Parsing:
Parser sends the notification to the application about the type of XML nodes / pieces found during parsing. It is also knows as Event Based Parsing. SAX (Simple API for XML) is fast parsing mechnism, but application has to match the speed of the SAX parser for each event. Same as above about validation and verification.
One Step Parsing:
Parser generates the tree based upon the XML document structure. DOM (Docuemnt Object Model) is one of the parsing standard. Very useful when traversing is required in the tree.
Hybrid Parsing:
The application thinks its working with one step parser that has processed the whole document while parsing process has just started. As the pplication keeps accessing more objects on the DOM tree the parsing continues incrementally.
XML Parsing Models and Their Trade-Offs:
| Model | Control of Parsing | Control of Context | Memory Efficiency | Computational Efficinecy | Simplicity |
| Pull | Application | Application | High | Highest | Low |
| Push (SAX) | Parser | Application | High | High | Low |
| One-step(DOM) | Parser | Parser | Lowest | Lowest | High |
| One-step (JDOM) | Parser | Parser | Low | Low | Highest |
| Hybrid (DOM) | Parser | Parser | Medium | Medium | High |
| Hybrid (JDOM) | Parser | Parser | Medium | Medium | Highest |
References:
http://media.techtarget.com/searchSAP/downloads/Building_Web_Services_with_Java_CH02.pdf