Lab-Tasks
Part 1: Searching Algorithms
1. Linear Search
Task: Implement a linear search algorithm.
Input: An array of integers and a target value.
Output: The index of the target value if found, otherwise -1.
Steps:
1. Return the index of the target if found; otherwise, return -1.
2. Binary Search
Task: Implement a binary search algorithm.
Input: A sorted array of integers and a target value.
Output: The index of the target value if found, otherwise -1.
Steps:
1. Return the index of the target if found; otherwise, return -1.
Part 2: Sorting Algorithms
1. Bubble Sort
Task: Implement the bubble sort algorithm.
Input: An array of integers.
Output: The sorted array.
Steps:
1. Swap adjacent elements if they are in the wrong order.
2. Continue until the list is sorted.
2. Selection Sort
Task: Implement the selection sort algorithm.
Input: An array of integers.
Output: The sorted array.
Steps:
1. Repeatedly select the smallest (or largest) element from the
unsorted region and move it to the sorted region.
3. Insertion Sort
Task: Implement the insertion sort algorithm.
Input: An array of integers.
Output: The sorted array.
Steps:
1. Take each element from the unsorted section and insert it into
the correct position in the sorted section.
Part 3: Performance Analysis
1. Test Cases:
o Create a list of unsorted integers.
o Use the sorting algorithms to sort the list in both ascending
and descending order.
o Use the linear and binary search algorithms to find different
target values, both present and absent in the list.
2. Documentation:
o Write a brief report summarizing:
The implementation of each algorithm.
Test results
Observations on the efficiency of each algorithm.
Use cases where each search or sort method would be
preferred.
Submission Requirements
Submit the source code for all implemented algorithms on Slate.
Include the report summarizing findings.
Ensure code is well-commented and adheres to good programming
practices.