Skip to main content

CT Week 2

Concepts: Filter and Iteration

📚

Iterator Concept Summary

Iterator Concept

An iterator is a pattern used to perform repetitive tasks systematically, ensuring that each item in a dataset is visited exactly once. This involves several key steps:

Initialization

Set up the context for the iterator to function. This might involve arranging items in a specific order or making them accessible in a certain way.

  • For example, when working with cards, this could mean arranging all cards in a single pile.
  • For a dataset of words in a paragraph, the words need to be in the same sequence as they appear in the paragraph.

Picking and Examining One Data Element

Select one item from the dataset to work on. This could be the top card from a pile, a row from a table, or any element from an unordered set.

The selected item is then examined, and specific fields or values are processed. These values might be combined with other values or written down for further use.

Marking the Data Element as Seen

After examining the chosen element, it is moved to a "seen" pile to ensure it is not re-examined.

  • This involves maintaining two piles: the original "unseen" pile and the "seen" pile. This ensures that all items are visited without repetition.
  • In tabular form, this means moving a row from the "unseen" table to the "seen" table.

Stopping

The iteration continues until there are no more items left to examine. This naturally happens when the "unseen" pile is empty.

In tabular form, this occurs when the table runs out of rows.

Steps of the Iterator

  1. Initialization Step: Arrange all items in an "unseen" pile.
  2. Continue or Exit: Check if there are any items left in the "unseen" pile. If not, exit; otherwise, continue.
  3. Repeat Step: Pick an item from the "unseen" pile, process it, and move it to the "seen" pile.
  4. Repetition: Go back to Step 2 and repeat the process until all items are processed.

Additional Notes

  • The step that checks whether to continue is placed before picking an item to handle cases where the dataset might be empty initially.
  • The repetition is driven by Step 4, which directs the process back to Step 2, ensuring continuous iteration until completion.
Iterator and Flowcharts Summary

Summary of Iterators and Flowcharts

Flowcharts

Flowcharts provide a visual representation of step-wise processes, making it easier to understand and communicate procedures. They are particularly useful for explaining protocols or procedures to others, such as customers or business partners.

Main Symbols Used in Flowcharts

We primarily use four symbols in flowcharts:

Terminal Symbol

Denotes the start or end of the flowchart.

Process Symbol

Represents any activity that needs to be performed.

Decision Symbol

Checks a condition and branches based on true/false.

Arrow

Shows progress from one step to another.

The Generic Iterator Flowchart

The generic iterator flowchart uses the symbols mentioned above to represent the iteration process. It starts with initialization, followed by a decision to continue or stop the iteration. If the iteration continues, it repeats the steps and returns to the decision box.

Iterator Flowchart for Cards

This flowchart is a specific example of the generic iterator, applied to a set of cards. It involves arranging cards in an "unseen" pile and moving them to a "seen" pile after examination. The decision step checks if there are more cards in the "unseen" pile.

Here are some example.

One thing to be notes is in computational thinking == means equality(we are checking values), = means we have assigned the value, fixed the value.

Try to form flowchart of following pseudocode.

Embed PDFs

Some examples on flowchart:

PA:

GA:

Comments

Popular post

IITM Notes

Course Overview “These handwritten notes encompass topics in data science and civil services. The beauty of knowledge is that you don’t need to belong to any specific group; simply maintain your curiosity, and knowledge will find its way to you. I hope these notes are helpful. If they are, please consider leaving a comment below and follow my blog for updates.” Mathematics 1 👉 Select Week Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9 Week 10 Week 11 Revision Statistics 1 👉 Select Week Week 1 Week 2 Week 3 Week 4 Week 5 Week 6 Week 7 Week 8 Week 9 Week 10 Week 11

Maths 1 week 1 Summary

Number System and Set Theory 📚 Number System and Set Theory This week, our teacher covered the basics of the number system. We were instructed to consider 0 as part of the natural numbers, as it will be treated as such in future subjects like Python. However, in exams, it will be explicitly stated whether 0 should be considered a natural number. The key topics from this week include set theory and the relationship between two sets. In set theory, we focused on three Venn diagram problems. In the context of relations, we discussed the concepts of reflexive, symmetric, transitive, and equivalence relations. Detailed Explanation 1.Union of Two Sets The union of two sets A and B is the set of elements that are in either A , B , or both. It is denoted as A ∪ B . 2.Intersection of Two Sets The intersection of two sets A and B is the set of elements that are in both A and B . It is denoted as A ∩ B . 3.Subt

Community page

Welcome To our IITM BS Students Community This community is a student commune where IIT Madras Bachelor of Science students are studying. Our community is managed by 15 community admins who oversee our WhatsApp community, Discord, and Telegram profiles. With more than 1000+ active members, we study together, share memes, watch movies, play games, and have fun. Our goal is to bring all online IITM students together to excel in exams while having fun. Community Admins Agampreet LinkedIn Ansh Ashwin Ambatwar Arti Dattu Dolly Elango Koushik Shrijanani Saksham Shivamani Shivam Instagram LinkedIn Join Our Community Subscribe to our YouTube page Join our meme team on