User Tools

Site Tools


products:ict:python:sorting_questions

What is sorting in Python? Answer: Sorting is the process of arranging a list of items in a specific order, such as ascending or descending order.

What are the different types of sorting algorithms in Python? Answer: Some of the commonly used sorting algorithms in Python are Bubble Sort, Selection Sort, Insertion Sort, Merge Sort, Quick Sort, and Heap Sort.

What is Bubble Sort in Python? Answer: Bubble Sort is a simple sorting algorithm that repeatedly compares adjacent elements in a list and swaps them if they are in the wrong order.

What is Selection Sort in Python? Answer: Selection Sort is a sorting algorithm that selects the smallest element from an unsorted list in each iteration and places it at the beginning of the list.

What is Insertion Sort in Python? Answer: Insertion Sort is a sorting algorithm that iterates through a list and compares each element with the elements before it, and inserts it into its correct position in the sorted list.

What is Merge Sort in Python? Answer: Merge Sort is a sorting algorithm that divides a list into two halves, sorts each half separately, and then merges them back together in sorted order.

What is Quick Sort in Python? Answer: Quick Sort is a sorting algorithm that partitions a list into two sub-lists, one containing elements less than a pivot element and the other containing elements greater than the pivot element. It then recursively sorts the sub-lists.

What is Heap Sort in Python? Answer: Heap Sort is a sorting algorithm that creates a binary heap from a list and repeatedly extracts the root element to obtain a sorted list.

What is the time complexity of Bubble Sort in Python? Answer: The time complexity of Bubble Sort in Python is O(n^2), where n is the number of elements in the list.

What is the time complexity of Selection Sort in Python? Answer: The time complexity of Selection Sort in Python is also O(n^2).

What is the time complexity of Insertion Sort in Python? Answer: The time complexity of Insertion Sort in Python is O(n^2) in the worst case, but O(n) in the best case when the list is already sorted.

What is the time complexity of Merge Sort in Python? Answer: The time complexity of Merge Sort in Python is O(n log n) in all cases.

What is the time complexity of Quick Sort in Python? Answer: The time complexity of Quick Sort in Python is O(n log n) in the average case, but O(n^2) in the worst case.

What is the time complexity of Heap Sort in Python? Answer: The time complexity of Heap Sort in Python is also O(n log n).

What is stable sorting in Python? Answer: Stable sorting is a type of sorting algorithm that maintains the relative order of equal elements in the list.

Is Bubble Sort a stable sorting algorithm in Python? Answer: Yes, Bubble Sort is a stable sorting algorithm in Python.

Is Selection Sort a stable sorting algorithm in Python? Answer: No, Selection Sort is not a stable sorting algorithm in Python.

Is Insertion Sort a stable sorting algorithm in Python? Answer: Yes, Insertion Sort is a stable sorting algorithm in Python.

Is Merge Sort a stable sorting algorithm in Python? Answer: Yes, Merge Sort is a stable sorting algorithm in Python.

Is Quick Sort a stable sorting algorithm in Python? Answer: No, Quick Sort is not a stable sorting algorithm in Python.

products/ict/python/sorting_questions.txt · Last modified: 2023/05/06 16:04 by wikiadmin