Click here to Skip to main content
15,917,005 members
Home / Discussions / Algorithms
   

Algorithms

 
AnswerRe: critical number Pin
73Zeppelin9-Oct-08 5:47
73Zeppelin9-Oct-08 5:47 
GeneralRe: critical number Pin
Paul Conrad9-Oct-08 7:00
professionalPaul Conrad9-Oct-08 7:00 
GeneralRe: critical number Pin
jonig199-Oct-08 7:03
jonig199-Oct-08 7:03 
GeneralRe: critical number Pin
73Zeppelin9-Oct-08 9:43
73Zeppelin9-Oct-08 9:43 
GeneralRe: critical number Pin
Paul Conrad9-Oct-08 10:15
professionalPaul Conrad9-Oct-08 10:15 
GeneralRe: critical number [modified] Pin
73Zeppelin9-Oct-08 23:21
73Zeppelin9-Oct-08 23:21 
AnswerRe: critical number Pin
cp987610-Oct-08 2:26
cp987610-Oct-08 2:26 
QuestionTwin Prime Conjecture Pin
Bassam Abdul-Baki8-Oct-08 3:01
professionalBassam Abdul-Baki8-Oct-08 3:01 
AnswerRe: Twin Prime Conjecture Pin
Kevin McFarlane12-Oct-08 5:03
Kevin McFarlane12-Oct-08 5:03 
QuestionAlgorithm or not? [modified] Pin
MNoordam6-Oct-08 3:46
MNoordam6-Oct-08 3:46 
AnswerRe: Algorithm or not? Pin
Alan Balkany7-Oct-08 8:28
Alan Balkany7-Oct-08 8:28 
GeneralRe: Algorithm or not? Pin
MNoordam7-Oct-08 10:30
MNoordam7-Oct-08 10:30 
GeneralRe: Algorithm or not? Pin
Alan Balkany8-Oct-08 7:24
Alan Balkany8-Oct-08 7:24 
GeneralRe: Algorithm or not? Pin
MNoordam8-Oct-08 8:54
MNoordam8-Oct-08 8:54 
GeneralRe: Algorithm or not? Pin
MNoordam16-Oct-08 1:15
MNoordam16-Oct-08 1:15 
GeneralRe: Algorithm or not? Pin
Alan Balkany16-Oct-08 3:19
Alan Balkany16-Oct-08 3:19 
GeneralRe: Algorithm or not? [modified] Pin
MNoordam16-Oct-08 3:41
MNoordam16-Oct-08 3:41 
GeneralRe: Algorithm or not? Pin
Alan Balkany17-Oct-08 3:54
Alan Balkany17-Oct-08 3:54 
QuestionMonte carlo Rabin_Karp Search Pin
Angelinna2-Oct-08 14:17
Angelinna2-Oct-08 14:17 
AnswerRe: Monte carlo Rabin_Karp Search Pin
Robert.C.Cartaino2-Oct-08 16:23
Robert.C.Cartaino2-Oct-08 16:23 
GeneralRe: Monte carlo Rabin_Karp Search Pin
Angelinna2-Oct-08 17:07
Angelinna2-Oct-08 17:07 
GeneralSign of the times... PinPopular
CPallini2-Oct-08 21:52
mveCPallini2-Oct-08 21:52 
GeneralRe: Monte carlo Rabin_Karp Search Pin
Paul Conrad3-Oct-08 6:28
professionalPaul Conrad3-Oct-08 6:28 
GeneralRe: Monte carlo Rabin_Karp Search PinPopular
Tim Craig3-Oct-08 18:34
Tim Craig3-Oct-08 18:34 
GeneralArray Rearrangement trick [modified] Pin
abhigad1-Oct-08 9:53
abhigad1-Oct-08 9:53 
Let’s say we have an array of integers

int[] myArray = new int[] {1,2,3,4,5};

So the length of this array is 4 [i.e. n=4] since C# array index starts at 0

Yes the length will be 5 and not 4 as pointed out in the next post. Its my bad - Sorry!

Define integer k such that 0<= k < n [n = length of an array]

For example, If k = 2 then the output should be
{3,4,5,1,2} i.e starting from kth position move all the array elements to the top of an array.

If k = 3, output would be
{4,5,1,2,3}

Here is the challenge.
Yes this is trivial if we write a loop that starts at 0 and goes up to n like

for(int i =0;i<n;i++){}

We want to optimize this loop so that it would not loop till n-1. anything less than n-1 is a good solution.

[Tip: if you want to reverse this array like 5,4,3,2,1 – you can use the loop like
for(int i=0;i<n/2;i++)

modified on Wednesday, October 1, 2008 5:23 PM

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.