Urgent !!!Plzzz Help me my assignment!!! Pseudocode for an algorithm

pls help me Gentle men and ladies

Question 1

Write the pseudocode for an algorithm that receives an integer and then prints the number of digits in the integer and the sum of the digits. For example, given 13254 it would print that there are 5 digits with a sum of 15.

Question 2

Design an algorithm that tests whether or not two input lists of size n have at least one element in common. Give formulas for best case b(n) and worst case w(n) for your algorithm.

Thanks so much help me pls :(


  • [code]
    int n = 123;
    int remainder = 0;
    int arr[20];
    int counter = 0;
    n = fabs(n);
    while(n>0) {
    remainder = n%10;
    arr[counter++] = remainder;
    n = n/10;

    sum = sum of all the elements in the array arr
    Number of elements = counter +1

    This is a very inefficient algorithm. Since you didnt mention any complexity, i didnt bother to think about the solution.If incase you have any efficiency criteria, do let me know.
  • let the two arrays be a[n] and b[n].

    int i =0;
    int j=0;

    for(i=0;i<n;i++) {
    for(j=0;j<n;j++) {
    if(a[i] == b[j]) break;



    Best Case = When the first element is same = O(1)
    Worst Case = O(n^2)
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion