Capability3 Assignment

You might also like

You are on page 1of 5

Basecamp Capability 3 Assignments

Introduction:
This document covers list of assignments/exercises related to third capability of
Basecamp program:

 Use sorting and searching algorithms to solve given problem scenario

Observations:
KO: 1. Ability to do a sort correctly with the given requirements - at least two sorting
techniques (preferably bubble and insertion sorting)
KO: 2. Ability to do a search correctly with the given requirements -using both linear and
binary search algorithms
3. Ability to do the same with increased complexity - Applying sorting and searching
algorithms for array of user defined objects
4. Ability to merge two different data sets - Merging two different arrays of primitive
elements

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Exercise 1: Bubble Sort


Write an application to store ‘N’ numbers of type integers and sort it using below
explained logic (Bubble sort). Your program should display the sorted numbers in a
formatted way
Learn the concept from following tutorial: https://www.geeksforgeeks.org/bubble-
sort/

Exercise 2: Linear Search


Write a method which accepts an integer array and key element to search. It should
return ‘true’ if given key element found otherwise ‘false’
Learn the concept from following tutorial: https://www.geeksforgeeks.org/linear-
search/

1
Basecamp Capability 3 Assignments

Exercise 3: Binary Search


Write a menu driven program to implement binary search algorithm on both integer
elements and strings.
Menu:
1. Binary search for Integer elements
2. Binary search for Strings
3. Exit
Write two methods:
a) Boolean findElement(int arr[], int key): Should return ‘true’ if key element
found otherwise ‘false’
b) Boolean findString(String names[], String name): Should return ‘tru’ if name
found in the list otherwise ‘false’.

Learn the concept from following tutorial: https://www.geeksforgeeks.org/binary-


search/

Exercise 4: Insertion Sort


Write a method which accepts array of unsorted integer elements and display elements
in sorted order. Use insertion sort algorithm to sort.
Refer below diagram to understand how insertion sort works.

2
Basecamp Capability 3 Assignments

Source: https://www.w3resource.com/java-exercises/sorting/java-sorting-algorithm-
exercise-7.php

Exercise 5: Sort and search Strings


Write menu driven program to sort set of given strings and search String in a string
array.
Menu:
1. Sort using Bubble sort
2. Sort using Insertion sort
3. Search a string
4. Exit
Create different method/function for each of the option given in the menu.

Exercise 6: Search an Element in a set


Write a program which helps to find position of given number in the list of distinct
numbers: a1, a2, a3….

Note:
- Assume array indexing starts from 0

3
Basecamp Capability 3 Assignments

- If array has any duplicate element then it should display error message and exit.

Input:
12345
4

Output:
3

Exercise 7: Max Element

Write a method to return the index of the maximum value between two given indexes in
a given array.

Input:
A[] = {2, -5, 10, 21, 30}
Index1 = 2
Index 2= 3
Output:
21

Note: If given index values are not in the valid range then program must through an
error and exit.

4
Basecamp Capability 3 Assignments

Exercise 8: Merge Multiple Sorted Array

Given M sorted lists each containing N elements, print them in sorted order.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Summary:
You must have learnt following concepts:
 How to work with sorting algorithms: Bubble and insertion sort
 How to work with search algorithms: Linear and binary search
 How apply sorting and searching algorithms for user defined objects?
 How to merge multiple arrays based on business conditions?

You might also like