Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,557 members, 7,809,028 topics. Date: Thursday, 25 April 2024 at 09:19 PM

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

Nairaland Forum / Science/Technology / Programming / Please What Is This Algorithm That Compares............ (1313 Views)

7 Important Google Algorithm That Affect Your Website Or Blog SEO In (2018) / Simple Algorithm Exercise / Pls Programmers Help With Similarities Of Pseudocode & Algorithm (2) (3) (4)

(1) (Reply) (Go Down)

Please What Is This Algorithm That Compares............ by cheghoon01: 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): 4:43pm On Mar 16, 2016
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: 5:52pm On Mar 16, 2016
<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: 5:54pm On Mar 16, 2016
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)

Please Explain This Script To Me Php OOP / Guys What Is A Hackathon? / The Website Called Codefight

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 14
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.