Friday, July 31, 2009

Data structure issues

Problem 1: Reverse any message like "A cat goes here" to produce result like "here goes cat a".
Solution1: In First pass, use pointer from end, keep coming backwards and keep writing the characters. This leads to sth like "ereh seog tac A". Second Pass: reverse characters of each word to get result like "here goes cat a".

Problem2: HashMap vs ArrayList performance using Big-O notation.

Problem 3: How many number of bits are in an integer eg 7. Hint: use Bitwise operators of Java.

Problem 4: Given a log file, find which IPAddress appears max no of times in it.

River in South America

GIS Latitude Longitude Navigation Mapping

Convert Spherical Coordinates to Decimal form
Latitude Longitude are usually expressed in Spherical form. eg 29 degress, 41 minutes, 32 seconds North; Sign for degrees is small o on top right of value; sign for minutes is 41', and seconds as 32''. Thease spherical values are based on Round shape of earth, as a sphere.
How to convert these values to be used in mathematical calculations(decimal form):
Decimal form of above will be 29 + 41/60 + 32/3600, which comes to about 29.69222.

Next step, use Haversine formula to calculate distance between two points.

Sunday, July 26, 2009

IPTv

IPTV technology is about sending Video compressed signals over DSL/telephone lines. User scenario: If your house has telephone wire, we can input this wire to SetTopBox(STB), a customer premise equipment. The STB will decompress video signals which you can input in your TV to watch Digital TV and On Demand Movies, listen to Music, and use various applications to enhance User experience.

IPTV middleware product is client server application where Java client runs on STB. The J2EE server runs on UNIX machine and manages subscribers and their permissions, content metadata, billing packages, billing transactions, STB metadata, STB-subscriber allocations and other configurations.

Or,

IPTV product is 3 tier Java application used to broadcast Digital TV and Music, show on demand Video, provide Walled garden Internet access, and other interactive applications.
MX, the Java client application, runs on J2ME platform, the Customer Premise Equipment Set Top Boxes. The client application follows MVC design. The Model is populated with matadata pushed from server over multicast streams or pulled from server using unicast HTTP requests. The View is customized AWT solution which renders based on text layout files enabling separation of rendering procedure and rendered metadata. The Controllers manage various feature sets.
TX server is the J2EE middleware tier which manages subscribers and their permissions, content metadata, billing packages, billing transactions, Customer Premise Equipment metadata and their subscriber allocation, and other configurations.

design is important

what is the biggest challenge with designing a complex system from scratch?
The biggest challenge at this stage is the Design of the Complex system.
At the start of a complex project, we have the least amount of knowledge about the technical challenges we will face as the product gets developed. A wrong design decision here could turn into a monster when it is found later in the product development stage; leading to great cost in terms of time, resources and product stability to fix it.
Hence design should be based on sound computer science principles. The design should be flexible enough to incorporate changes as new issues, challenges and knowledge becomes apparent during the product development cycle.

multi threading

There are two approaches to multi threading I have seen:
a. Avoid multi threading if possible. Multi threaded code is generally complex. In a team with multiple developers of varying capabilities, it's easy to mess up multi threaded code, or fix a bug and create two more. Or do some coding which affects performance. Single threaded model is simpler to develop and maintain. Use the KISS (Keep it Simple Stupid) principle.
b. Use multi threaded with utmost care. If we are faced with performance issues with single threaded model or forced to use multi threaded code by any factors, Be very cautious. Firstly design the multi threaded code correctly, list all improvements expected and how, develop xUnit test cases to thoroughly test your code, and then take the plunge. Be afraid, be very afraid:) and cautious!

Someone I know wrote this

I was Technical Lead of X Product for NAM(North American Market). When I was made lead of this product, I got a product which was not in commercially deployable state, with customers threatening to switch to competitors. The reasons as I understood were: pressure from Project management and QA to fix the issues ASAP, developers hacking code to fix issues without any design considerations, developers not utilizing Object Oriented development mindset, and such bug fixes creating even more spaghetti code.
The things I did were: take full responsibility for this product and communicate this to everyone; create two codelines with all developers doing fixes in development codeline and ONLY me integrating satisfactory fixes in Release codeline; discussing with developers my design thoughts about fixes I did not like and why, which overall led to better quality; negotiating with Project stakeholders to prioritize issues and reduce scope of each release effectively giving developers more time to make better fixes.
We were able to release the first commercial grade software in 3 months with no Priority 1 issues in core features, and in later 3 month cycles we fixed other customer reported issues, show stopper issues on priority, and most Priority 2 issues. We only fixed Priority 3 issues if they were easy to fix or did not impact the design too much.
In short, for the last almost 3 years, my codeline has been the most stable out of all X product codelines, and customers have been most satisfied.
Questions?

Technology work hierarchy

Similar on Maslow's need Hierarchy, this is what I believe is technology work hierarchy:
Lowest level: Survival, do what you are told esp things like bug fixing, need minimum understanding of design and language features.
Next level: Understand language and bit of design, make better software, but still what needs to be done is dictated by others(designers/managers)
3rd Level: Understand language/design in detail; ability to teach others the technical concepts in simple language, Expert. But still work is defined by Others.
4the Level: creativity Level, When one sees new uses of current knowledge, start being creative, stats defining new applications of technology or improvements to technology. Self actualization level.

Friday, July 17, 2009

Palindome

In a language of your choice write a function that takes a string and returns the longest palindrome contained in that string. A palindrome is a symmetrical string – it reads the same from left to right and from right to left. Please make sure your solution really works and provide a few interesting test cases for it. Try to make the code as efficient as you can. For extra credit provide a complexity analysis for your solution.


public class Palindome {

public static void main(String [] args){
Palindome palindome = new Palindome();
if (args.length > 0){
System.out.println("The first argument will be tested if it's palin!");
palindome.findIt(args[0]);
}else{
System.out.println("The first argument will be tested if it's palin!");
}
}

int testStringLength = 0;
String successString = null;

/*
* the main method of the algorithm, Find the length of SubStrings to be tested, starting from lagest to smallest
*/
public String findIt(String testString){
/* String testString1 = "papa I Never even get to do any things";
*/ testStringLength = testString.length();

boolean palinFound = false;
for(int i =0; i System.out.println("testString length = "+ testStringLength);
palinFound = isThereAnyPalinOfThisLength(testString, testString.length());
if(palinFound){
System.out.println("palinFound!! String successString = "+ successString);
return successString;
}
}
return successString;
}

/*
* Find all SubStrings possible of specified length.
*
*/
public boolean isThereAnyPalinOfThisLength(String testString, int testLength){
boolean b = false;
System.out.println("testString length = "+ testStringLength);
for(int i = 0; i < (testStringLength); i++){
String str = testString.substring(i, testLength);
System.out.println("Current String To Be tested : "+ str);
b = isThisPalin(str);
if(b){
successString = str;
return b;
}
}
return b;
}

/*
* This method checks whether "this exact" String is palindome or not?
*/
public boolean isThisPalin(String s){
int startPointer = 0;
int endPointer = s.length()-1;
boolean noMatch = true;
System.out.println("Is this palin = "+ s);
while(startPointer < endPointer ){
if(s.charAt(startPointer) != s.charAt(endPointer)){
noMatch = false;
break;
}
startPointer++;
endPointer--;
}
return noMatch;
}


/*
* We need to find the Largest Palindome String, We don't care if smaller Palindomes are present or not.
* Step1: Recursively find the largest to smallest strings that can be made out of the test string.
* 1a. Check whether thye whole string is palindome or not.
* 1b. If not, Check whether all Strings possible of (length-1) are palindome or not.
* 1c. If not, Check whether all Strings possible of (length-2) are palindome or not.
* 1d. continue till the time When EVEN "at least 2 characters Strings" are not Palindome:(
* Step2:
* Create all possible SubStrings of length l, and check each of them.
* Step3: check each SubString if it is palindome!
*
*
* ToDo:
* 1. Remove all special characters from the String to be tested eg All ,; $ etc. ONLY characters should remain.
* 2. When checking for character equality in isThisPalin(String s), must make sure that capital Letters and small letters are matched too!
* 3. The String should be sent from Junit test case.
*
Complexity analysis:
String length: n
Worst Case:
No of strings compared: 1(one string of length n)+2 (2 stings of length n-1)+3+.. +n
No of character comparisons: n/2; (n-1)/2...
Total char compared: n/2 + (n-1) + (n-2)....
Order of: n squared

Best Case:
No of Strings compared: 1 (The whole String is a Palindrome)
No of characters comparisons: n/2
Order of : n

Average case:
No of Strings compared: 1+2+3+ ...+ n/2
No of character comparisons: n/2; (n-1)/2...+ (n/2 -1)/2
Total char compared: n/2 + (n-1) + (n-2)....+ ((n/2-1)/2)*(n/2)
Order of: (n squared)/8



Monday, July 13, 2009

Objective C part 1

What is ObjectiveC:
Objective-C is a reflective, object-oriented programming language, which adds Smalltalk-style messaging to the C programming language.
ObjectiveC is subset of C?
No. Objective-C is a very thin layer on top of C, and moreover is a strict superset of C. That is, it is possible to compile any C program with an Objective-C compiler, and to freely include C code within an Objective-C class.
What does it mean by "Smalltalk-style messaging" in ObjectiveC?
Objective-C derives its object syntax from Smalltalk. All of the syntax for non-object-oriented operations (including primitive variables, preprocessing, expressions, function declarations, and function calls) is identical to that of C, while the syntax for object-oriented features is an implementation of Smalltalk-style messaging.
Explain Messages in ObjectiveC?
Messages are central concept in ObjectiveC. The Objective-C model of object-oriented programming is based on sending messages to object instances.
In Objective-C one does not call a method; one sends a message. There is no concept of called method being executed. In ObjectiveC, the message sent to an object is executed! In fact, the calling object just sends method NAME to the called object. The called object received the method NAME at runtime, then figures out what to do (at runtime).
This means there is no type checking(the signatures of called method should match the call from calling object) at compile time.
And there is no guarantee that the receiving object will respond to any message sent to it; it may just ignore it(and send back null as response).
Explain Message syntax:
[obj message:parameter];
message is being sent with parameter(s) to the obj(receiving object).
Any quick advantage/disadvantage with messages:
Advantage: ObjectiveC allows messages to go unimplemented - for example, a collection of objects may all be sent a message, of which the programmer knows only some will respond, without fear of producing runtime errors. eg. The Cocoa platform takes advantage of this, as all objects in a Cocoa application are sent the awakeFromNib: message as the application launches, to which objects may respond by executing any initialisation required at launch.
Disadvantage:
Due to the overhead of interpreting the messages, an Objective-C message takes at best over three times as long as a C++ virtual method call. What comparing times with C++ virtual method call: because just like messages need not have implementation in ObjC, C++ virtual methods need not have implementation(if it is called, it needs implementation; but one can only declare virtual method, never implement it and never call it).

Let's talk interface, implementation, instantiation:

Inteface:
@interface classname : superclassname {
// instance variables
}
+classMethod1;
+(return_type)classMethod2;
+(return_type)classMethod3:(param1_type)parameter_varName;

-(return_type)instanceMethod1:(param1_type)param1_varName :(param2_type)param2_varName;
-(return_type)instanceMethod2WithParameter:(param1_type)param1_varName andOtherParameter:(param2_type)param2_varName;
@end

Plus signs denote class methods(aka static), minus signs denote instance methods. Class methods have no access to instance variables.
Note that instanceMethod2WithParameter demonstrates Objective C's named parameter capability for which there is no direct equivalent in C/C++. Todo: explain this.
Return types can be any standard C type, a pointer to a generic Objective-C object, or a pointer to a specific type of object such as NSArray *, NSImage *, or NSString *. The default return type is the generic Objective-C type id.
Todo: explain this.

Method arguments begin with a colon followed by the expected argument type in parentheses followed by the argument name. In some cases (e.g. when writing system APIs) it is useful to add descriptive text before each parameter.

-(void) setRange:(int)start :(int)end;
-(void) importDocumentWithName:(NSString *)name withSpecifiedPreferences:(Preferences *)prefs beforePage:(int)insertPage;

http://en.wikipedia.org/wiki/Objective-C