Saturday 14 April 2012

Concurrency & Parallel processing

How different is concurrent from parallel in computer science concepts? I got similar doubt on difference between function and method  which I was able to understand from my critiques comments. This doubt arose when Prof Tony Giavargis explained in his Software for embedded systems class that ‘Concurrent is an illusion of being parallel’. How far is this true, how far are they different?

Can concurrency be achieved using a single processor(share resources) whereas parallel processing requires at least two processors(independent resources)? Does this mean multithreading/multitasking is an extended concept of concurrency while distributed processing is derived from parallel processing? Is concurrency subset of Parallel processing? Is there any better way to distinguish them? What are the objectives met by adopting them - is it high availability & speed? Both involve communication cost for synchronization and aggregation of results, former acquires less communication overhead than later, but doesn't guarantee the same level of speed as later. Does this play a crucial role in deciding which one should be used?

Please share your opinion in the comments section below, if possible with example.

Reference: http://www.linux-mag.com/id/7411/

Sunday 1 April 2012

Reverse string with reduced time complexity?


I was asked to write a program for reversing a string in java using brute force method. I wrote the very general answer which uses string length and charAt() in a for loop. This method has O(n) time complexity, so I was asked to reduce its time complexity. We can use two counters, one running from first position of the string and second from last position of the string running till the middle position of the string, construct two reversed substrings which can then be concatenated to produce complete reversed string. But this will give only O(n/2) which is same as O(n). Are there any another approach to reduce the time complexity for the above program?

Please describe your approach in the below comments section.