3. WHAT IS AN
ALGORITHM?
An algorithm is a set of instructions for solving a problem or
accomplishing a task.
Every set of problem needs to be solved with
good efficiency with respect to time and
space complexities, in order to achieve these
landmarks there are some well defined
algorithms are available already.
4. TYPES OF
ALGORITHMS:
1.Simple searching – Linear search and Binary search
2.Simple sorting - insertion sort, bubble sort, selection sort
3.Divide and conquer - merge sort, quicksort
4.Two pointers - find middle of linked list, search in sorted matrix
5.Greedy - shortest path with Dijkstra’s algorithm, huffman
encoding
6.Recursion - Factorial, depth first search
7.Backtracking - detect cycle in directed graph, generate valid
parentheses
5. LINEAR SEARCH :
A linear search or sequential search is a method for finding an
element within a list. It sequentially checks each element of the
list until a match is found or the whole list has been searched.
Time Complexities :
Best Case : O(1)
Worst Case : O(n)
Average Case : O(n+1/2)
Note: The average case can be affected if the search probabilities for each element vary..
6. SELECTION SORT :
The selection sort algorithm sorts an array by repeatedly finding the minimum element (considering
ascending order) from unsorted part and putting it at the beginning. The algorithm maintains two subarrays in
a given array.
•The subarray which is already sorted.
•Remaining subarray which is unsorted.
In every iteration of selection sort, the minimum element
(considering ascending order) from the unsorted subarray is
picked and moved to the sorted subarray.
Time Complexities :
Best Case : O(N2)
Worst Case : O(N2)
Average Case : O(N2)
7. Program Explanation
This project is based on “The Phone Book Directory”. In this we can perform the
sorting and searching of database by first name, last name and phone no.
• The program first takes input from user for the size of the array followed by entering data.
• After that, it display the data on screen and display six choice three for sorting and three for
searching.
• Ask to enter a choice and perform the following task and display the output on screen
accordingly.
• These steps from displaying choice till the output on screen is inside a while loop to make it
work iteratively.
• To stop the loop user need to enter “0” (zero).