Posts tagged english

Why iPhone still ruleZ

I’m going to make a simple point. And because people that know me think I’m a “unfair-Google-aficionado-that-doesn’t-see-how-evil-Google-is”, I’m going to use Android as victim here.

iPhone ruleZ
iPhone ruleZ

Other OS? I’m not even taking into consideration old stuff like Symbian: is just too easy to trash it now-days (Qt is a whole different story though).
More >

Binary Tree Rebuilder

Imagine you have a Binary Tree, with those characteristics:

  • Nodes do not respect any order relation – In other words: it’s not a Binary Search Tree of any kind
  • Every node appears once and only once within the tree
A nice Binary Tree
A nice Binary Tree

Then, your little brother passes by your desk and, to upset you, deletes the tree from your computer memory/HD (yeah, I know, I’m pathetic at inventing hypothetical situations :-P ).

Fortunately though, you previously did a Pre-Order and an In-Order visit of your tree, and stored the result in an 2 nice array.

Can you rebuild the original tree structure out of this 2 array?

How are you going to rebuild it?

Yes, you can! (Sorry, I couldn’t resist). And it’s quite easy as well. What you have to do, is the following:

  • Take the first element of the PreOrder Array and use it as root of a new tree
  • Find the position of this New Node in the InOrder Array, scanning it from 0 to n-1 (n is the number of Nodes)
  • IF next element in the PreOrder Array is on the left of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from 0 to the position of the New Node in the InOrder Array -1.
  • IF next element in the PreOrder Array is on the right of the New Node in the InOrder array: call RECURSIVELY this procedure, this time taking into account the portion of InOrder array that goes from the position of the New Node in the InOrder Array +1 to n-1.
  • Return the New Node

By the way, this doesn’t work. To fix it we should be more generic, specifying things a little bit better. Things like:

  • Every recursive calls takes into account a portion of the InOrder array; in the case of the first call it’s the entire array
  • There is going to be as much recursive calls as the number of elements in the PreOrder array

Of course, is a tree what we are talking about here: recursion is a MUST. More >

Serverless chat to reduce office distance

This idea comes out for an old university-time idea: to write a serverless chat application. Of course, I’m aware of the complications and the problems that using Broadcasting could create, so this problems would be took in consideration by design.

Office

But why now? I was thinking of a way to reduce the “office distances”: making easy to connect with a person who works in your own office. I know, it sounds a bit “creepy” to depend on an application to do that. After all you could just stand up and go to the colleague’s desk. And that’s what I’d normally do: nothing impossible.

But I can see that this is not always the case for every personality, and, sometimes, I fall in the same “shyness” (since in UK, no one believes me when I say “I’m shy”, but I actually am: I just use jokes to relax and break-the-ice). So months passes by, you never learn the name of some colleagues and so on. After all how many times you work in projects where more than 10 people are involved?

Acceptance-less

A system like this could explicitly avoid concepts like “accept a contact in your contact-list”: the contact list would be the list of all the clients connected to the network, no one excluded. I know you could probably do this kind of stuff configuring accordingly some server chat, but you need:

  • Infrastructure, set up by an IT department
  • Maintenance, provided by an IT department

Both this things are normally very rare resources to have in a classical office environment. IT is always evil ;-) . Am I not right?

Cross platform by design

I have in mind Qt as the framework to build something like that. It already covers the most of the desktop environments, and it can be set to integrate nicely. Not like Java. :-P

Features? No, for now brainstorming

Yeah, I could start to write a long list of all the features I think such software should have, but this post was more to ask the micro-crowd that reads my blog “what do you think of such an idea?”. Any idea will be took in consideration.

Features

Ok, that’s what I have in mind for now:

  • Acceptance-less contact-list (I believe that’s a core one)
  • Chat layout built into a WebView: styling through plugins of CSS(3) files
  • Drag and Drop file-transfer (no-passthrough-server: imagine the speed on a lan!)
  • Encryption: communication can be encrypted, encrypting the socket traffic one has opened with another client
  • Position: this could be like a “status” info, but allowing the person to pin him/herself on a Office map, so that can be easy to find

Please advice for more ;)

And after this chat?

Just stand up and go there: it’s not like your colleague is going to harm you or something. ;)

iPad Simulator in Video and Comments

I would have just posted it on Twitter, but I have some comments about this video.


One of the first video of the iPad Simulator
  1. Watch it in Full screen at 720p: it help “feeling” the proportions used by Apple in the UI
  2. It clarify how it does execute iPhone apps: they most probably implement the iPhone API as is: indeed even the Keyboard that you get in an iPhone application is the same (no super large/super cool keyboard of the iPad
  3. I feel that 4 icons per row are too few: there a kilometers between an icon and the next one
  4. I feel that the hardware home button doesn’t fit very well proportionally: they should have used a rectangular button way larger: given the size of the device, is too small
  5. The amount of free space in the top bar (the one with Battery, Time and Signal Strength) is A JOKE. In there nice little icons of the services running in background, or tickers of latest emails… or something else SHOULD fit
  6. Integrated Spotlight is a proportional abomination: why the search bar in the TOP has the fixed size of the one used by iPhone? I mean, it takes not even half of all the width it could
  7. Notification Modal Dialogs (used to ask stuff like “Are you sure you want to delete this app?”) is SO SMALL, that in the middle of the screen looks like you should do something else around it. EVEN with the background faded in black: I believe such effect of “prioritization” works as long as the user can’t have something else to look at.
  8. File Sharing!!! It misses a proper Finder Mobile to share files through Bluetooth, USB, Wifi, as well as management of those files! I don’t want to email me stuff! And I don’t want to pay for an extra software that is not well integrated or it has always some limitations.

That’s my first set. But surely I’ll have more. I need to collect reasons to stick with my position: iPass. ;)

“Bidirectionally multiplied” array

Another small problem before I go to sleep tonight:

There is an array A[N] of N numbers.
You have to compose an array Output[N] such that Output[i] will be equal
to multiplication of all the elements of A[N] except A[i].

For example Output[0] will be multiplication of A[1] to A[N-1] and Output[1]
will be multiplication of A[0] and from A[2] to A[N-1].

Solve it without division operator and in O(n).

What is funny of the problem, is the fact that the O(n) constraint, makes it sound like is going to be hard to solve. Doesn’t it? Well, it’s not.

The solution is quite simple, so I suggest you take your 10 minutes to think about it, then continue to see the code. More >

Use Backtracking to print all Subsets

I’m “studying” this algorithmic technique: Backtracking. This is an algorithmic approach to problem solution that I trust every good Computer Scientist already uses; but taking a good theo-practical look at it is something better.

A Backtracking Tree
A Backtracking Tree

I believe you can find enough informations about it online (the 2 links I provided are more than enough), so I’ll go straight to the problem.

Problem definition

Given an integer n, and the set S = { 1 ... n }, calculate (print) all the possible subsets of S. For example, for n = 1, all the possible subsets are { 1 } and { } (empty set). For n = 2, all the possible subsets are: { 1 2 } { 1 } { 2 } { }. In general, for the set made of the first n Integers, the number of possible subsets is 2n.

Approaching the problem

A way to describe a possible subset is an array of n elements, one for every integers; every element in the array will have value TRUE if the correspondent integers is part of the subset, FALSE otherwise.

Why the Backtracking then? Because the backtracking technique is designed to generate every possible “candidate solution” once. If we design the algorithm smartly, we can get the backtracking logic to work for us and generate all the possible subsets.

Are you are asking yourself: “isn’t this a bit of a stretching of the backtracking approach?”. I believe it is: the code could be made way smaller, even though it would have the same complexity. We are going to execute the backtracking, designing the algorithm so it will never stop until it tried every possible solution. No “intermediate stopping condition” then.

More >