Friday, October 28, 2011

Linked List - Reverse & identifying the cycle

Linked List- another interesting and simple data structure. Most of the interviewers ask for reverse and identifying the cycle in linked list.

Identifying the cycle
Traversal of a linked list with a cycle will never end, so there needs to be some method to keep track of what nodes have been encountered.


One idea is to mark nodes that have been seen, either by adding a flag to the node itself or storing information about the node in a separate data structure. Unfortunately, this method requires modification of the node and/or additional space.


Interviewers won't accept this way as they want to understand/see how we traverse across nodes.

Another idea is to move the pointers in different speed to identify a cycle as below. To make one pointer faster than the other, just advance it two nodes instead of one.

public static boolean hasCycle(Node head) {

Node fast = head;
Node slow = head;

while (true) {
if (fast == null || fast.next == null)
return false;
else if (fast == slow || fast.next == slow)
return true;
else {
fast = fast.next.next;
slow = slow.next;
}
}
}
Reverse


With three pointers, reverse will be pretty straight forward to move on.



Node previous = null;
Node current = head;
Node forward;

while (current != null) {
forward = current.next;
current.next = previous;
previous = current;
current = forward;
}

Download the code (Just copy & paster in your editor)

Saturday, October 22, 2011

Social Commerce - my view

What is Social commerce?

Social commerce is a another dimension of e-commerce. With the social media interaction and user contributions in its side, it will promote/drive online user to buy and sell products or services.

Why it gets big hype in recent timings?
E-commerce sites target the big user bank in social networking sites like Facebook, Twitter etc. E-commerce sites want to drive traffic to their site with these platform which they can convert as a purchase.

Why Facebook is in the top compared to other sites?
It's because of its user bank -
More than 800 million active users
Average user has 130 friends
More than 70 languages available on the site
More than 7 million apps and websites are integrated with Facebook
More than 350 million active users currently access Facebook through their mobile devices
Data from http://www.facebook.com/press/info.php?statistics

Which industries are getting hot?
Fashion (Clothing & shoes) , Electronics (which includes mobile phones, tech gadets)

How I see its different from traditional E-commerce?
  • Group Buy – With friends and family, I can buy and make them buy.Buying something together.
  • Advise - I can get friend's advice on a prospective purchase. Same I can provide too.
  • Recommend/Review - suggesting a specific item to a friend who is looking for one with some review.
  • Share - Something like show off, what I own
  • Trust - Trust will be/can be created not only by item description but from my friends and family.
Readymade Solutions:
IBM social commerce, Microsoft Commerce

Though we can say solutions, but it has to be tied with different departments Marketing, Analytics, PR etc

Prediction: $30billion revenue from social commerce market in 2015