AlgorithmsAlgo Puzzle - Product of Elements of an Arrayvivek, Sun, 2008-04-27 00:09I came across this interesting problem of coming up with an algorithm that would compute, for each element of an array, the product of all other elements in that array, in linear time without using the division operator (or implementing a division algorithm.) A solution is to traverse left to right computing the growing product, and then traverse right to left computing the growing product and multiplying it with the result from the previous traversal. I.e., Given,P Q R SCompute, 1 P PQ PQR x x x x QRS RS S 1 ------------------- QRS PRS PQS PQR Implemented in python,
def elProd( A ):
result = []
prod = 1
# for i from 0 up to len(A) - 1
for i in range( len( A ) ):
result.append( prod )
prod = prod * A[ i ]
prod = 1
# for i from len(A) - 1 down to 0
for i in range( len( A ) - 1, -1, -1 ):
result[ i ] = result[ i ] * prod
prod = prod * A[ i ]
return result
Knuth in a Yearvivek, Wed, 2005-06-01 00:31[img_assist|fid=60|thumb=1|alt=Reference (Resource)]
The Art of Computer Programming Reading Group is for those of us who suffer from the perpetual procrastinate-reading-knuth syndrome. Starts June 1st'05. Subscribe to the mailing list here. LR(0) Regular Expression Parser in Perlestrabd, Sat, 2005-05-07 00:34Again - a hack that I am not sure works 100%. I used the following regular expression grammar to create an SLR table by hand.
LL(1) Regular Expression Parser in Perlestrabd, Tue, 2005-05-03 21:33Microsoft Interview Questionsaura, Tue, 2005-05-03 16:18Here's a link to some Microsoft Interview Questions. QuicK Search !psindia, Mon, 2005-03-28 22:39/* Filename : Quick.c
Description : To Implement Quick Sort On arrays
Author : Vinod S R
Lisence : Free aslong as the line above is there*/
#include
#include
McCarthy 91vivek, Tue, 2004-08-03 19:53Think Recursion is cool ? Check out the McCarthy 91 recursive function. Conceived by computer scientist John McCarthy, it takes the value 91 for all positive integers less than 102. Here is the C implementation ,
Sorting Algorithmsvivek, Sat, 2004-07-31 23:54Sorting in general refers to various methods of arranging or ordering things based on criterias (numerical, chronological, alphabetical, heirarchial etc.). In Computer Science, due to obvious reasons, Sorting (of data) is of immense importance and is one of the most extensively researched subjects. It is one of the most fundamental algorithmic problems. So much so that it is also fundmental to many other fundamental algorithmic problems such as search algorithms, merge algorithms etc. It is estimated that around 25% of all CPU cycles are used to sort data. There are many approaches to sorting data and each has its own merits and demerits. This article discusses some of the common sorting algorithms. |
TopicsRecent blog posts
|
||