Class VII Ch-5
Class VII Ch-5
Class- VII
4. What are the different types of modifications that we can perform on collections?
● Modifications include adding, removing, updating elements, and clearing the collection.
1. Draw a flowchart for the customized algorithm for finding the square of numbers
that we learnt in this chapter.
● Flowchart:
○ Start
○ Input the number
○ Multiply the number by itself
○ Output the result (square of the number)
○ End
def is_prime(num):
if num < 2:
return False
if num % i == 0:
return False
return True
print(prime_numbers)
3. Draw a flowchart to explain the flow of selection sort techniques in programming.
● Flowchart:
○ Start
○ Input the array
○ Set outer loop from the first to the second-last element
○ Set the minimum element as the current index
○ Inner loop to find the smallest element in the unsorted array
○ Swap the minimum element with the first unsorted element
○ Repeat until the array is sorted
○ End
4. Write an algorithm to sort the below list in descending order using the selection
sort technique: [10, 21, 45, 67, 12].
Algorithm:
1. Start with the first element as the largest.
2. Iterate through the list and find the largest element in the unsorted portion.
3. Swap the largest element with the current element.
4. Move to the next element and repeat until the entire list is sorted.
5. Output the sorted list.
● First Pass: Largest is 67, swap with 10 → [67, 21, 45, 10, 12]
● Second Pass: Largest is 45, swap with 21 → [67, 45, 21, 10, 12]
● Third Pass: Largest is 21, no swap → [67, 45, 21, 10, 12]
● Fourth Pass: Largest is 12, swap with 10 → [67, 45, 21, 12, 10]