0% found this document useful (0 votes)
4 views

assignment 2

The document compares various searching algorithms (Linear and Binary) and sorting algorithms (Bubble, Selection, Insertion, Merge, Quick, Bucket, Count, Radix, and Heap) based on their pros and cons, practical applications, and comparisons with each other. It highlights the efficiency of binary search for sorted datasets and the advantages of merge sort for large datasets. Additionally, it discusses the suitability of different algorithms for specific scenarios, such as counting sort for limited ranges and quick sort for general-purpose sorting.

Uploaded by

sohanxt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

assignment 2

The document compares various searching algorithms (Linear and Binary) and sorting algorithms (Bubble, Selection, Insertion, Merge, Quick, Bucket, Count, Radix, and Heap) based on their pros and cons, practical applications, and comparisons with each other. It highlights the efficiency of binary search for sorted datasets and the advantages of merge sort for large datasets. Additionally, it discusses the suitability of different algorithms for specific scenarios, such as counting sort for limited ranges and quick sort for general-purpose sorting.

Uploaded by

sohanxt
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Department of Computer Science and Engineering

ASSIGNMENT - 2

Course Code - CSEC0613103


Course Title – Data Structure And Algorithms

Topic On :
Compare the searching algorithms (Linear & Binary), sorting algorithms (Bubble,
Selection, Insertion, Merge, Quick, Bucket, Count, Radix, & Heap) on the basis of
following terms:

 Pros & Cons


 comparison with each other (i.e. why merge over quick sort or why quick sort over
radix sort etc.)
 Practical implementation/applications

Submitted To : Submitted by:


Nahida Islam ABU SAHID SOHAN
Lecturer, ID : 2241081098
Department of CSE Batch : CSE 61 A (Regular)
Uttara University

Deadline: 25/11/2024
Comparison of Searching and Sorting Algorithms
Searching Algorithms

1. Linear Search
Pros:
- Simple and easy to implement.
- Works well for small datasets or unsorted arrays.
- Does not require the dataset to be sorted.

Cons:
- Slow for large datasets (O(n)).
- Inefficient when the dataset grows in size.

Applications:
- Suitable for small arrays or where unsorted data is common.
- Searching in linked lists.

2. Binary Search
Pros:
- Much faster than linear search (O(log n)).
- Ideal for sorted datasets.
- Divide-and-conquer approach makes it efficient.

Cons:
- Dataset must be sorted.
- Slightly more complex to implement than linear search.

Applications:
- Searching in sorted arrays or datasets.
- Used in applications like dictionary lookup, finding roots in numerical analysis.

1|Page
Sorting Algorithms
Algorithm Pros Cons Applications
Bubble Sort Simple, easy to Very slow for large Used in educational purposes
understand, and datasets (O(n^2)). and small datasets where
implement. simplicity is valued.
Selection Does not require Inefficient for large Useful for small datasets
Sort additional memory, datasets (O(n^2)). where memory is limited.
and swaps are
minimized.
Insertion Efficient for small Inefficient for large, Used in online algorithms
Sort datasets or nearly randomly ordered (data arrives in a stream) and
sorted data (O(n) datasets (O(n^2)). nearly sorted datasets like
for almost-sorted library books.
datasets).
Merge Sort Very efficient for Requires additional External sorting (e.g., sorting
large datasets, and memory (O(n)) for data stored on a disk),
has a predictable temporary arrays. scenarios requiring stable
runtime (O(n log sorting like sorting names by
n)). alphabetical order.
Quick Sort Extremely efficient Worst-case General-purpose sorting
on average (O(n performance is O(n^2) where efficiency is key, used
log n)) and uses in- (can be avoided with in libraries like Python's
place sorting. good pivot selection). sorted().
Heap Sort Efficient for large Comparatively slower Used in scenarios where
datasets, and does than quick sort in memory usage needs to be
not require practice. minimized, and stability is
additional memory not required.
(O(1) auxiliary
space).
Bucket Sort Very fast for data Requires prior Used for datasets with
uniformly knowledge of the known distributions (e.g.,
distributed over a distribution, and sorting numbers in a specific
range (O(n + k)). performance depends range).
on bucket count.
Counting Fast and efficient Not suitable for large Suitable for digit-based
Sort for integer keys in range keys, and not problems like counting
a limited range comparison-based frequencies or specific
(O(n + k)). (cannot sort non- datasets (e.g., age groups in a
integer data). population).
Radix Sort Works well for Limited to numeric or Used for large numeric
data with fixed- fixed-width data. datasets, sorting phone
length numbers, or other datasets
representations with fixed lengths.
(O(nk)).

2|Page
Detailed Comparisons
1. Linear Search vs Binary Search:
- Binary search is far more efficient for sorted datasets, as it reduces the search space
exponentially.
- Linear search is versatile since it works for unsorted data but is inefficient for larger
datasets.

2. Bubble Sort vs Selection Sort:


- Bubble sort involves frequent swapping, making it slower.
- Selection sort minimizes swaps but still has the same time complexity.

3. Insertion Sort vs Merge Sort:


- Insertion sort is better for small or nearly sorted datasets.
- Merge sort is better for large datasets due to its predictable O(n log n) performance but
requires additional space.

4. Quick Sort vs Merge Sort:


- Quick sort is faster on average and uses in-place sorting, making it memory efficient.
- Merge sort is stable and better for linked lists but has additional memory overhead.

5. Quick Sort vs Radix Sort:


- Quick sort works for general-purpose datasets and strings but has worst-case O(n^2).
- Radix sort is highly efficient for fixed-width numeric data but cannot handle general data
types.

6. Heap Sort vs Quick Sort:


- Heap sort guarantees O(n log n) even for the worst case but is slower in practice.
- Quick sort is preferred for its speed and simplicity in typical cases.

7. Counting Sort vs Radix Sort:


- Counting sort is optimal for limited ranges but cannot handle non-integer data.
- Radix sort extends counting sort for large numeric datasets with fixed-length
representations.

3|Page

You might also like