# Algorithm problem

*label*Other

*timer*Asked: Feb 24th, 2016

**Question description**

Algorithms to write and analyse their complexities in term of big-O:

1- Sequential Search: (array elements need not to be sorted)

generate n numbers at random in an array of size n; and search for a given number in the array; if found return its location in the array, else return -1,

2- Binary Search: (array elements must be sorted)

generate n numbers at random in an array of size n; use any sort algorithm you know to order the numbers in the array, i.e. quick_sort, bubble_sort,... ;

and search for a given number in the array; if found return its location in the array, else return -1,

for the search function: use both methods: iteration, and recursion

Use 0<n<1000, and generated numbers must be less than 5 digits.

Class Time is used for grading your finished programs along with and their calculated complexities.

Be prepared and equiped with your laptops and finished programs.

HELP TO START:

#include <ctime>

#include <iostream>

using namespace std;

int a[10000], n=100;

//Here is a bubble sort code:

void sort() {for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(a[i]>a[j]) {int t; t=a[i]; a[i]=a[j]; a[j]=t;}}

//Here is a print code:

void print() { for(int i=0;i<n;i++) cout<<a[i]<<endl;}

//Here is a data generation code:

void generate() { srand(time(0)); for(int i=0;i<n;i++) a[i] = rand()%1000;}