1. how many lines of code are normally used to swap two values? 2 5 3 4 2. after this code runs, what is the…

1. how many lines of code are normally used to swap two values? 2 5 3 4 2. after this code runs, what is the proper way to tell if the item was found or not? i = 0 while i < len(my_list) and my_listi != key: i += 1 if i == len(my_list): if my_listi != key: if my_listi == key: if i > len(my_list): 3. in the insertion sort, what does the outside loop do? selects the next element to be slid into a sorted position finds the smallest value in the list slides an element into a sorted position
Answer
Brief Explanations:
- In most programming languages, to swap two values, a temporary variable is commonly used, which typically requires 3 lines of code (assigning to temp, re - assigning one value, and then re - assigning the other using the temp).
- The given
whileloop iterates through the listmy_listuntil it finds thekeyor reaches the end of the list. If the loop finishes because the indexiis equal to the length of the list, it means the item was not found. - In insertion sort, the outer loop selects the next element from the unsorted part of the list to be inserted into its correct sorted position.
Answer:
- C. 3
- A. if i == len(my_list):
- A. Selects the next element to be slid into a sorted position