Arrays and Searching Techniques in C: Sequential and Binary Search Algorithms, Slides of Object Oriented Programming

An introduction to arrays and their usage in c programming, followed by explanations of two common searching techniques: sequential search and binary search. Example code for each method and explanations of their respective advantages and disadvantages.

Typology: Slides

2016/2017

Uploaded on 04/05/2017

ammarriaz
ammarriaz 🇵🇰

4.5

(2)

5 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Arrays and Searching Techniques in C: Sequential and Binary Search Algorithms and more Slides Object Oriented Programming in PDF only on Docsity!

** PRESENTED BY

PRESENTED BY

* Program

#include<conio.h> #include int main() { using namespace std; int marks[10]; for(int i=0;i<10;i++) { cout<<"Enter marks"<<endl; cin>>marks[i]; } cout<<"The marks of the student are"<<endl; for(int i=0;i<10;i++) { cout<<marks[i]<<endl; } getch(); return 0; }

* Searching in

Arrays

*Searching is a process of finding the

required data in the array.

*Searching becomes more important when

the length of the array is very large.

*Two types to search an array.
*1:-Sequential search
*2:-Binary search
*If the value of array matches with the desired value,

the search is complete.

*If the value of array does not match , move to next

element and repeat same process.

** Program

Program

*#include<conio.h> *#include *int main() *{

  • using namespace std; *int arr[10]={10,20,30,40,50,60,70,80,90,100}; *int i,n,loc=-1; *cout<<"Enter value to find:"; *cin>>n; *for(i=0;i<10;i++)
  • if(arr[i]==n)
  • loc=i; *if(loc==-1)
  • cout<<"value not found in the array."; *else
  • cout<<"value found at index\t"<<loc; *getch(); *return 0; *}

**Program

Program

*#include *#include<conio.h> *int main() *{

  • using namespace std; *int arr[10]={10,20,30,40,50,60,70,80,90,100}; *int n,i,mid,start,end,loc; *loc=-1; *start=0; *end=9; *cout<<"Enter any number to find:"; *cin>>n;

* ANY

QUESTION

* ANY

QUESTION

**THANK YOU

THANK YOU