Sorry, I see nothing difficult in this problem statement. Or maybe is it just that you never wrote a program ? Or are you asking how to represent the network topology and path costs ? For a), scan the array and check if two consecutive indexes are the same. For b), scan the array and check if every pair of indexes are linked in the user-supplied topology (you need some function that will query the topology and tell you if a link exists). For c), the condition is a[5] != 5. For d), use a double loop: the outer loop from i=1 to 4, the inner loop for j=i+1 to 5. In the body of the inner loop, test a[i] == a[j]. Accumulating the path costs is also obvious once you have a query function per network link.