₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,190 members, 8,420,737 topics. Date: Friday, 05 June 2026 at 10:19 AM

Toggle theme

Please What Is This Algorithm That Compares............ - Programming - Nairaland

Nairaland ForumScience/TechnologyProgrammingPlease What Is This Algorithm That Compares............ (1408 Views)

1 Reply (Go Down)

Please What Is This Algorithm That Compares............ by cheghoon01(op): 1:01pm On Mar 16, 2016
For example, if 10 assignments were added to the list, with the name
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
The iteration technique will get data in the following order:
Compare: 1 and 2, 1 and 3, 1 and 4, 1 and 5, 1 and 6, 1 and 7, 1 and 8, 1 and 9, 1 and 10
Compare: 2 and 3, 2 and 4, 2 and 5, 2 and 6, 2 and 7, 2 and 8, 2 and 9, 2 and 10
Compare: 3 and 4, 3 and 5, 3 and 6, 3 and 7, 3 and 8, 3 and 9, 3 and 10
Compare: 4 and 5, 4 and 6, 4 and 7, 4 and 8, 4 and 9, 4 and 10
Compare: 5 and 6, 5 and 7, 5 and 8, 5 and 9, 5 and 10
Compare: 6 and 7, 6 and 8, 6 and 9, 6 and 10
Compare: 7 and 8, 7 and 9, 7 and 10
Compare: 8 and 9, 8 and 10
Compare: 9 and 10
Re: Please What Is This Algorithm That Compares............ by tr3y(m): 4:27pm On Mar 16, 2016
An array and a loop is all you need.
Re: Please What Is This Algorithm That Compares............ by ChinenyeN(m):
As tr3y aptly stated, you simply need to loop it.

Assuming your data structure is an array or even array-like, the algorithm would then be as follows:

For each [element] 1 - 10
Take each [subsequent element] until 10
Compare [element] with [subsequent element]
Finish/Close loop
Finish/Close loop
Re: Please What Is This Algorithm That Compares............ by larisoft:
<pre>
<code>
//JAVA
for(int i = 0; i < arr.length; i++){

int firstNum = arr[i];
for(int j = i+1; j < arr.length; j++){

int secondNum = arr[j];

if(secondNum==firstNum){
//do stuff
}
}

}


//PHP

for($i = 0; $i < count($arr); $i++){

$firstNum == $arr[$i];
for($j = $i+1; $j < count($arr); $j++){
$secondNum = $arr[$j];
if($secondNum == $firstNum){
//do stuff
}
}
}

//C#

for(int i = 0; i < arr.Length; i++){

for(int j = i+1 ; j < arr.Length; j++){

if(arr[i] == arr[j]){
//do stuff
}

}

}




//Javascript

for(var i = 0; i < arr.length; i++){


for(var j = i+1; j < arr.length; j++){

if(arr[i]===arr[j]){
//do stuff
}

}

}


</code>
</pre>

Hopefully, you speak one of these langauges. All you need do now is copy and paste.
Re: Please What Is This Algorithm That Compares............ by larisoft:
Re: Please What Is This Algorithm That Compares............ by bot0k: 11:55pm On Mar 18, 2016
cheghoon01:
For example, if 10 assignments were added to the list, with the name
1, 2, 3, 4, 5, 6, 7, 8, 9, 10
The iteration technique will get data in the following order:
Compare: 1 and 2, 1 and 3, 1 and 4, 1 and 5, 1 and 6, 1 and 7, 1 and 8, 1 and 9, 1 and 10
Compare: 2 and 3, 2 and 4, 2 and 5, 2 and 6, 2 and 7, 2 and 8, 2 and 9, 2 and 10
Compare: 3 and 4, 3 and 5, 3 and 6, 3 and 7, 3 and 8, 3 and 9, 3 and 10
Compare: 4 and 5, 4 and 6, 4 and 7, 4 and 8, 4 and 9, 4 and 10
Compare: 5 and 6, 5 and 7, 5 and 8, 5 and 9, 5 and 10
Compare: 6 and 7, 6 and 8, 6 and 9, 6 and 10
Compare: 7 and 8, 7 and 9, 7 and 10
Compare: 8 and 9, 8 and 10
Compare: 9 and 10
A[] = {1,2,3......10};
for (i=1 to 10; i++)
{
for (j = i to 10; j++)
{
compare(A[i] and A[j]);
}

}

smiley
1 Reply

7 Important Google Algorithm That Affect Your Website Or Blog SEO In (2018)Simple Algorithm ExercisePls Programmers Help With Similarities Of Pseudocode & Algorithm234

How Do I Send A SMS Message To A Phone With Php.Why Are Most Nigerian Developers Freelancers?Can Someone Who Have Mastered The Basics Of Php And Can Apply It Be Called A Dev