AQ 4.1 Doubt

45 views
Skip to first unread message

Pranjal Sarkar

unread,
Nov 12, 2020, 5:23:43 AM11/12/20
to Discussion forum for Computational Thinking
Hello team

In question number 2, what are the two nested iterations specified in the question?

According to my understanding, if we write the pseudo-code for this problem, then we may write it as:

while(Pile 1 has more cards)
{
      Read top card of Pile 1 and designate it as current_card;
      Note down the DOB of current_card(=x, say);
      while(Pile 1 has more cards other than current_card)
       {
                Read top card of Pile 1 and designate it as compare_card;
                 Note down the DOB of compare_card(=y, say);
                  if(x == y)
                  {
                        pair_count += 1;
                        Keep compare_card under the entire Pile 1;
                   }
       }
       Keep the current_card in another pile called Pile 2;
}

Here let us suppose pair_count was initially initialized to zero and at the end of the code we have found all the possible pairwise combinations

So here the question arises that which are the two nested loops here because I only see one nested loop.

Kindly help me with this problem as soon as possible.

Thank you
Pranjal Sarkar

Computational Thinking Support 2

unread,
Nov 12, 2020, 7:33:57 AM11/12/20
to Discussion forum for Computational Thinking, Pranjal Sarkar
Hi,
I think the pseudocode you wrote is correct. Coming to your doubt.  The code you wrote is the case of  one nested loop which has two iterations which is what we are asking in the question.
This is not the case of two nested loop.

I think your doubt will be cleared if not please write us again.

Regards,
Deepak
IITM Online Degree Team

r ab

unread,
Nov 17, 2020, 4:24:41 AM11/17/20
to Discussion forum for Computational Thinking, ct-su...@onlinedegree.iitm.ac.in, Pranjal Sarkar
what is the difference between iteration and nested loop
Reply all
Reply to author
Forward
0 new messages