0% found this document useful (0 votes)
174 views3 pages

Sorting Interview Quetions

best resources for interview

Uploaded by

Ruchi Binayake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
174 views3 pages

Sorting Interview Quetions

best resources for interview

Uploaded by

Ruchi Binayake
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 1: What is a sorting algorithm?

/ Why Sorting algorithms are


important?
Answer: A sorting algorithm is a method used to arrange elements in a specific
order, like smallest to largest or vice versa, so that data can be easily
manageable.

Question 4: What is the difference between comparison-based and non-


comparison-based sorting algorithms?
Nd ye dono b comparison-based and non-comparison-based sorting
algorithms ke types h.
Answer: Comparison-based sorting algorithms compare elements to determine
their order, while non-comparison-based algorithms use other techniques, like
counting or bucketing, to sort elements without direct comparisons.

IMP:Question 7: Which sort algorithm works best on mostly sorted data?


Answer: For mostly sorted data, Insertion Sort typically works best. It’s efficient
when elements are mostly in order because it only needs to make small
adjustments to place each element in its correct position, making it faster than
other sorting algorithms like Quick Sort or Merge Sort.

Agr pucha to ek bari read kele vasie b


Question 2: What are the different types of sorting algorithms?
Answer: There are two types of Sorting algorithms: Comparison based sorting
algorithms and non-comparison-based sorting algorithms. Comparison based
sorting algorithms include Bubble Sort, Selection Sort, Insertion Sort, Merge
Sort, Quick Sort, Heap Sort, etc. and non-comparison-based sorting algorithms
include Radix Sort, Counting Sort and Bucket Sort.

Sorting real world example


1. Flight booking = select lowest to highest ticket price
2. Same for amazon price select lowest to highest
Here are simplified definitions of the sorting algorithms:
1. Bubble Sort:
 Repeatedly compares and swaps adjacent elements if they are in the
wrong order. It "bubbles" the largest element to the end.
2. Selection Sort:
 Finds the smallest element in the unsorted part of the array and swaps it
with the first unsorted element. Repeats for the entire array.
3. Insertion Sort:
 Takes each element and places it in the correct position in the sorted
part of the array, one by one.
4. Merge Sort:
 Splits the array into smaller parts, sorts each part, and then merges them
back together in order.
5. Quick Sort:
 Picks a "pivot" element, puts smaller elements on one side and larger
ones on the other, then repeats the process for both sides.
6. Heap Sort:
 Builds a heap (a tree-like structure) and repeatedly removes the largest
element from the heap and places it at the end of the array.
3. Insertion Sort:
 Example 1: Arranging playing cards. You pick up one card at a time and
insert it into the correct spot in your hand, making sure the cards stay in
order as you go.

4. Merge Sort:
 Example 1: Combining two sorted lists of names. If you have two class
lists, one for boys and one for girls, and both are already alphabetically
sorted, you combine them by taking the first name from each list and
comparing, always adding the smaller name first.

1. Bubble Sort:
Example 2: Organizing kids by height in a line. You start from the
beginning of the line, comparing two kids, and if the one on the left is
taller, you switch their places. You do this over and over until everyone is
lined up by height.

2. Selection Sort:
Example 2: Arranging toys by size. You find the smallest toy, place it in
the first spot, then find the next smallest and put it next to the first,
repeating until all toys are lined up by size.

You might also like