document.write( "Question 1209467: Given an array 𝑎[1..𝑛] containing half zeros and half ones, we need to find a position in 𝑎 that contains the value 1. Consider the following two algorithms:
\n" );
document.write( "Algorithm 1:
\n" );
document.write( "i = 1
\n" );
document.write( "while a[i] != 1:
\n" );
document.write( " i += 1
\n" );
document.write( "return i\r
\n" );
document.write( "\n" );
document.write( "Algorithm 2:
\n" );
document.write( "while True:
\n" );
document.write( " i = random(1, n)
\n" );
document.write( " if a[i] == 1:
\n" );
document.write( " return i
\n" );
document.write( "The function random(1, n) returns a random integer between 1 and 𝑛.
\n" );
document.write( "a) Compare the two algorithms.
\n" );
document.write( "b) Which algorithm is better? \n" );
document.write( "
Algebra.Com's Answer #848896 by ikleyn(52926) You can put this solution on YOUR website! .\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( "In this post, the question is like this:\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( "Which algorithm would you prefer: one slow algorithm, but giving 100% precise answer with 100% reliability \n" ); document.write( "or another potentially faster algorithm which probably will NOT give you the 100% precise answer with 100% reliability ?\r \n" ); document.write( " \n" ); document.write( " \n" ); document.write( "\n" ); document.write( "It reminds me a dialog of two mocks in the classic/famous novel \"Gargantua and Pantagruel\" \n" ); document.write( "by the French writer Francois Rabelais (written in 16th century). \r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( " One monk asks another :\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( " - If you had to travel to Causak (the city in France), what would you prefer - \n" ); document.write( " - to ride a goose or to pull a pig on a string?\r \n" ); document.write( " \n" ); document.write( "\n" ); document.write( " To which the other monk replies: - I prefer to drink.\r \n" ); document.write( " \n" ); document.write( " \n" ); document.write( "\n" ); document.write( " \n" ); document.write( " |