My QA Projects

QA Projects I was involded.

View on GitHub

Selection Sort with list

def selection_sort(arr):
    # takes an input list arr
    n = len(arr)
    # calculates the length of the list.

    # Traverse through all array elements; iterates over the entire list. 
    # Each iteration places the next smallest element at the correct position in the sorted subarray.

    for i in range(n):
        min_idx = i
         # Find the minimum element in the remaining unsorted array
         # initializes the minimum index to the current position of the outer loop.
        for j in range(i+1, n):
            # iterates through the unsorted part of the list to find the index of the smallest element.
            if arr[j] < arr[min_idx]:
                # updates the minimum index if a smaller element is found.
                min_idx = j
        # Swap the found minimum element with the first element of the unsorted part
        arr[i], arr[min_idx] = arr[min_idx], arr[i]

# Example
arr = [64, 25, 12, 22, 11]
selection_sort(arr)
print("Sorted array:", arr)

Step 2. Finding the Minimum:

Step 3. Swapping:

Step 4. Repeat:

Selection Sort with tuple

def sort_tuple(data):
"""Sorts a tuple using Selection Sort.
Returns a new sorted tuple.
"""
  n = len(data)
  sorted_data = []  # Use a list to store sorted elements
  for i in range(n):
    min_index = i
    for j in range(i + 1, n):
      if data[j] < data[min_index]:
        min_index = j
    sorted_data.append(data[min_index])  # Add to list
  return tuple(sorted_data)  # Convert list to tuple

my_tuple = (5, 2, 8, 1, 9)
sorted_tuple = selection_sort_tuple(my_tuple)
print(sorted_tuple)  # Output: (1, 2, 5, 8, 9)

Selection Sort with tuple

def selection_sort_set(data):
  """Sorts a set using Selection Sort and returns a sorted list."""
  n = len(data)
  sorted_data = []
  for i in range(n):
    min_element = min(data)  # Find the minimum element directly
    data.remove(min_element)  # Remove it from the set
    sorted_data.append(min_element)  # Add it to the list
  return sorted_data

my_set = {5, 2, 8, 1, 9}
sorted_list = selection_sort_set(my_set)
print(sorted_list)  # Output: [1, 2, 5, 8, 9]