SlideShare a Scribd company logo
1 of 31
Linear Search
&
Binary Search
Abdul Kahir
&
Abdul Mohaimin Rahat
What is algorithm and Algorithm design?
• An Algorithm is a Step by Step solution of a specific
mathematical or computer related problem.
• Algorithm design is a specific method to create a
mathematical process in solving problems.
Sorted Array
• Sorted array is an array where each element is sorted in
numerical, alphabetical, or some other order, and placed at
equally spaced addresses in computer memory.
1 2 3 4
0.2 0.3 1 1.5
Unsorted Array
• Unsorted array is an array where each element is
not sorted in numerical, alphabetical, or some other order,
and placed at equally spaced addresses in computer memory.
1 2 3 4
0.2 0.3 1.5 1
What is searching?
• In computer science, searching is the process of finding an item with
specified properties from a collection of items.The items may be stored as
records in a database, simple data elements in arrays, text in files, nodes in
trees, vertices and edges in graphs, or maybe be elements in other search
place.
• The definition of a search is the process of looking for something or
someone
• Example : An example of a search is a quest to find a missing person
Why do we need searching?
Searching is one of the core computer science algorithms. We know that today’s
computers store a lot of information.To retrieve this information proficiently we need
very efficient searching algorithms.
Types of Searching
• Linear search
• Binary search
Linear Search
• The linear search is a sequential search, which uses a loop to step
through an array, starting with the first element.
• It compares each element with the value being searched for, and
stops when either the value is found or the end of the array is
encountered.
• If the value being searched is not in the array, the algorithm will
unsuccessfully search to the end of the array.
Linear Search
• Since the array elements are stored in linear order searching the
element in the linear order make it easy and efficient.
• The search may be successful or unsuccessfully.That is, if the
required element is found them the search is successful other wise
it is unsuccessfully.
Unordered linear/ Sequential search
int unorderedlinearsearch (int A[], int n, int data)
{
for (int i=0; i<n; i++)
{
if(A[i] == data)
return i;
}
return -1;
}
Advantages of Linear search
• If the first number in the directory is the number you
were searching for ,then lucky you!!.
• ●Since you have found it on the very first page,now its
not important for you that how many pages are there in
the directory.
• The linear search is simple - It is very easy to
understand and implement
• It does not require the data in the array to be stored in
any particular order
• ●So it does not depends on no. on elements in the
directory.Hence constant time .
Disadvantages of Linear search
• It may happen that the number you are searching for is the last number of
directory or if it is not in the directory at all.
• In that case you have to search the whole directory.
• Now number of elements will matter to you.if there are 500 pages ,you have to
search 500;if it has 1000 you have to search 1000.
• Your search time is proportional to number of elements in the directory.
• It has very poor efficiency because it takes lots of comparisons to find a
particular record in big files
• The performance of the algorithm scales linearly with the size of the input
• Linear search is slower then other searching algorithms
Analysis of Linear Search
How long will our search take?
In the best case, the target value is in the first element of the array.
So the search takes some tiny, and constant, amount of time.
In the worst case, the target value is in the last element of the array.
So the search takes an amount of time proportional to the length of
the array.
Analysis of Linear Search
In the average case, the target value is somewhere in the array.
In fact, since the target value can be anywhere in the array, any element
of the array is equally likely.
So on average, the target value will be in the middle of the array.
So the search takes an amount of time proportional to half the length
of the array
The worst case complexity is O(n), sometimes known an O(n) search
Time taken to search elements keep increasing as the number of
elements are increased.
Abdul Kahir
161-15-7173
Binary Search
The general term for a smart search through sorted data is a binary search.
1. The initial search region is the whole array.
2. Look at the data value in the middle of the search region.
3. If you’ve found your target, stop.
4. If your target is less than the middle data value, the new search region
is the lower half of the data.
5. If your target is greater than the middle data value, the new search
region is the higher half of the data.
6. Continue from Step 2.
17
Binary Search
© Reem Al-Attas
Binary Search
2. Calculate middle = (low + high) / 2.
= (0 + 8) / 2 = 4.
If 37 == array[middle]  return middle
Else if 37 < array[middle]  high = middle -1
Else if 37 > array[middle]  low = middle +1
7/25/2017 © Reem Al-Attas 19
Binary Search
Repeat 2. Calculate middle = (low + high) / 2.
= (0 + 3) / 2 = 1.
If 37 == array[middle]  return middle
Else if 37 < array[middle]  high = middle -1
Else if 37 > array[middle]  low = middle +1
7/25/2017 © Reem Al-Attas 20
Binary Search
Repeat 2. Calculate middle = (low + high) / 2.
= (2 + 3) / 2 = 2.
If 37 == array[middle]  return middle
Else if 37 < array[middle]  high = middle -1
Else if 37 > array[middle]  low = middle +1
©The McGraw-Hill Companies, Inc. Permission required for reproduction or
display.
Chapter 11 - 21
Binary Search Routine
public int binarySearch (int[] number, int searchValue) {
int low = 0,
high = number.length - 1,
mid = (low + high) / 2;
while (low <= high && number[mid] != searchValue) {
if (number[mid] < searchValue) {
low = mid + 1;
} else { //number[mid] > searchValue
high = mid - 1;
}
mid = (low + high) / 2; //integer division will
truncate
}
if (low > high) {
mid = NOT_FOUND;
}
return mid;
}
Binary Search Performance
• Successful Search
– Best Case – 1 comparison
– Worst Case – log2N comparisons
• Unsuccessful Search
– Best Case =
Worst Case – log2N comparisons
• Since the portion of an array to search is cut into half after every
comparison, we compute how many times the array can be
divided into halves.
• After K comparisons, there will be N/2K elements in the list. We
solve for K when N/2K = 1, deriving K = log2N.
Comparing N and log2N Performance
Array Size Linear – N Binary – log2N
10 10 4
50 50 6
100 100 7
500 500 9
1000 1000 10
2000 2000 11
3000 3000 12
4000 4000 12
5000 5000 13
6000 6000 13
7000 7000 13
8000 8000 13
9000 9000 14
10000 10000 14
Important Differences:
Input data needs to be sorted in Binary Search and not in Linear
Search
Linear search does the sequential access whereas Binary search
access data randomly.
Time complexity of linear search -O(n) , Binary search has time
complexity O(log n).
Linear search performs equality comparisons and Binary search
performs ordering comparisons
Greedy Algorithm
• A greedy algorithm is an algorithmic paradigm that follows
the problem solving heuristic of making the locally optimal
choice at each stage with the hope of finding a global
optimum.
Usage of greedy algorithm
• The greedy choice property: A globally optimal solution can
be arrived at by making a locally optimal (greedy) choice.
• The optimal substructure property:The optimal solution
contains within its optimal solutions to subproblems.
Method
• Casting the optimization problem as one for which:
we make a choice and are left with only one sub problem to solve
• Proving the greedy choice:
there is always an optimal solution to the original problem that
makes the greedy choice
• Proving the optimal structure:
the greedy choice + an optimal solution to the resulting Sub
problem leads to an optimal solution.
Simple Example on greedy Algorithm
method
• $6.64 = $2 +$2 + $1 + $1
.25 + .25 + .10 +
.01 + .01 + .01 +.01
• 10$= $5 + $5
When Greedy Algorithm Fails
The summation of two 5$ is 10$ but the summation of three 5$
cannot be 10 if its fixed.
For example,
$5 + $5 = $10
But,
$5 + $5 + $5 ≠ $10
Importance of Algorithm Design
• It is used to store and access large quantities of data
efficiently.
• It is used to solve complex computational problems and to
design of good programs
• It is important to justify an algorithm correctness
mathematically
• It provides clear , simple and unambiguous description
Conclusion
• At last it may said that , the so called program name
Algorithm design is one of the most enforceable solution
program that can be used to solve any complicated , complex
, and hard program.
• Under considering the above case the concerned authority
included the jubilant students should prefer this program with
great care.

More Related Content

What's hot

Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sortingKaushal Shah
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm03446940736
 
Linear Search
Linear SearchLinear Search
Linear SearchSWATHIR72
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation AhmedAlbutty
 
Selection sort
Selection sortSelection sort
Selection sortstella D
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...DrkhanchanaR
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear searchmontazur420
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithnKumar
 
Selection sort
Selection sortSelection sort
Selection sortamna izzat
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sortDistrict Administration
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting AlgorithmAl Amin
 

What's hot (20)

Data Structures - Searching & sorting
Data Structures - Searching & sortingData Structures - Searching & sorting
Data Structures - Searching & sorting
 
Searching
SearchingSearching
Searching
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Binary search
Binary searchBinary search
Binary search
 
Linear Search
Linear SearchLinear Search
Linear Search
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation
 
Insertion sort
Insertion sort Insertion sort
Insertion sort
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Selection sort
Selection sortSelection sort
Selection sort
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Trie Data Structure
Trie Data Structure Trie Data Structure
Trie Data Structure
 
Quick sort algorithn
Quick sort algorithnQuick sort algorithn
Quick sort algorithn
 
Selection sort
Selection sortSelection sort
Selection sort
 
Presentation on the topic selection sort
Presentation on the topic selection sortPresentation on the topic selection sort
Presentation on the topic selection sort
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 

Similar to Rahat &amp; juhith

data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxMohammed472103
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search AlgorithmFazalRehman79
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptxbhuvansaachi18
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsAnushdika Jeganathan
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)jehan1987
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptxDr.Shweta
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdfharamaya university
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfMustafaJutt4
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureBalwant Gorad
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++shahidameer8
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithmstechnologygyan
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET Journal
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingEduardo Bergavera
 

Similar to Rahat &amp; juhith (20)

data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
CPP12 - Algorithms
CPP12 - AlgorithmsCPP12 - Algorithms
CPP12 - Algorithms
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptx
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
Algorithm analysis (All in one)
Algorithm analysis (All in one)Algorithm analysis (All in one)
Algorithm analysis (All in one)
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++
 
Unit 7 sorting
Unit   7 sortingUnit   7 sorting
Unit 7 sorting
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Chapter 11 - Sorting and Searching
Chapter 11 - Sorting and SearchingChapter 11 - Sorting and Searching
Chapter 11 - Sorting and Searching
 

Recently uploaded

How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFAAndrei Kaleshka
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxBoston Institute of Analytics
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceSapana Sha
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfLars Albertsson
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)jennyeacort
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 

Recently uploaded (20)

How we prevented account sharing with MFA
How we prevented account sharing with MFAHow we prevented account sharing with MFA
How we prevented account sharing with MFA
 
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptxNLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
NLP Project PPT: Flipkart Product Reviews through NLP Data Science.pptx
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
Call Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts ServiceCall Girls In Dwarka 9654467111 Escorts Service
Call Girls In Dwarka 9654467111 Escorts Service
 
Industrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdfIndustrialised data - the key to AI success.pdf
Industrialised data - the key to AI success.pdf
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
Call Us ➥97111√47426🤳Call Girls in Aerocity (Delhi NCR)
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 

Rahat &amp; juhith

  • 3. What is algorithm and Algorithm design? • An Algorithm is a Step by Step solution of a specific mathematical or computer related problem. • Algorithm design is a specific method to create a mathematical process in solving problems.
  • 4. Sorted Array • Sorted array is an array where each element is sorted in numerical, alphabetical, or some other order, and placed at equally spaced addresses in computer memory. 1 2 3 4 0.2 0.3 1 1.5
  • 5. Unsorted Array • Unsorted array is an array where each element is not sorted in numerical, alphabetical, or some other order, and placed at equally spaced addresses in computer memory. 1 2 3 4 0.2 0.3 1.5 1
  • 6. What is searching? • In computer science, searching is the process of finding an item with specified properties from a collection of items.The items may be stored as records in a database, simple data elements in arrays, text in files, nodes in trees, vertices and edges in graphs, or maybe be elements in other search place. • The definition of a search is the process of looking for something or someone • Example : An example of a search is a quest to find a missing person
  • 7. Why do we need searching? Searching is one of the core computer science algorithms. We know that today’s computers store a lot of information.To retrieve this information proficiently we need very efficient searching algorithms. Types of Searching • Linear search • Binary search
  • 8. Linear Search • The linear search is a sequential search, which uses a loop to step through an array, starting with the first element. • It compares each element with the value being searched for, and stops when either the value is found or the end of the array is encountered. • If the value being searched is not in the array, the algorithm will unsuccessfully search to the end of the array.
  • 9. Linear Search • Since the array elements are stored in linear order searching the element in the linear order make it easy and efficient. • The search may be successful or unsuccessfully.That is, if the required element is found them the search is successful other wise it is unsuccessfully.
  • 10. Unordered linear/ Sequential search int unorderedlinearsearch (int A[], int n, int data) { for (int i=0; i<n; i++) { if(A[i] == data) return i; } return -1; }
  • 11. Advantages of Linear search • If the first number in the directory is the number you were searching for ,then lucky you!!. • ●Since you have found it on the very first page,now its not important for you that how many pages are there in the directory. • The linear search is simple - It is very easy to understand and implement • It does not require the data in the array to be stored in any particular order • ●So it does not depends on no. on elements in the directory.Hence constant time .
  • 12. Disadvantages of Linear search • It may happen that the number you are searching for is the last number of directory or if it is not in the directory at all. • In that case you have to search the whole directory. • Now number of elements will matter to you.if there are 500 pages ,you have to search 500;if it has 1000 you have to search 1000. • Your search time is proportional to number of elements in the directory. • It has very poor efficiency because it takes lots of comparisons to find a particular record in big files • The performance of the algorithm scales linearly with the size of the input • Linear search is slower then other searching algorithms
  • 13. Analysis of Linear Search How long will our search take? In the best case, the target value is in the first element of the array. So the search takes some tiny, and constant, amount of time. In the worst case, the target value is in the last element of the array. So the search takes an amount of time proportional to the length of the array.
  • 14. Analysis of Linear Search In the average case, the target value is somewhere in the array. In fact, since the target value can be anywhere in the array, any element of the array is equally likely. So on average, the target value will be in the middle of the array. So the search takes an amount of time proportional to half the length of the array The worst case complexity is O(n), sometimes known an O(n) search Time taken to search elements keep increasing as the number of elements are increased.
  • 16. Binary Search The general term for a smart search through sorted data is a binary search. 1. The initial search region is the whole array. 2. Look at the data value in the middle of the search region. 3. If you’ve found your target, stop. 4. If your target is less than the middle data value, the new search region is the lower half of the data. 5. If your target is greater than the middle data value, the new search region is the higher half of the data. 6. Continue from Step 2.
  • 18. © Reem Al-Attas Binary Search 2. Calculate middle = (low + high) / 2. = (0 + 8) / 2 = 4. If 37 == array[middle]  return middle Else if 37 < array[middle]  high = middle -1 Else if 37 > array[middle]  low = middle +1
  • 19. 7/25/2017 © Reem Al-Attas 19 Binary Search Repeat 2. Calculate middle = (low + high) / 2. = (0 + 3) / 2 = 1. If 37 == array[middle]  return middle Else if 37 < array[middle]  high = middle -1 Else if 37 > array[middle]  low = middle +1
  • 20. 7/25/2017 © Reem Al-Attas 20 Binary Search Repeat 2. Calculate middle = (low + high) / 2. = (2 + 3) / 2 = 2. If 37 == array[middle]  return middle Else if 37 < array[middle]  high = middle -1 Else if 37 > array[middle]  low = middle +1
  • 21. ©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 11 - 21 Binary Search Routine public int binarySearch (int[] number, int searchValue) { int low = 0, high = number.length - 1, mid = (low + high) / 2; while (low <= high && number[mid] != searchValue) { if (number[mid] < searchValue) { low = mid + 1; } else { //number[mid] > searchValue high = mid - 1; } mid = (low + high) / 2; //integer division will truncate } if (low > high) { mid = NOT_FOUND; } return mid; }
  • 22. Binary Search Performance • Successful Search – Best Case – 1 comparison – Worst Case – log2N comparisons • Unsuccessful Search – Best Case = Worst Case – log2N comparisons • Since the portion of an array to search is cut into half after every comparison, we compute how many times the array can be divided into halves. • After K comparisons, there will be N/2K elements in the list. We solve for K when N/2K = 1, deriving K = log2N.
  • 23. Comparing N and log2N Performance Array Size Linear – N Binary – log2N 10 10 4 50 50 6 100 100 7 500 500 9 1000 1000 10 2000 2000 11 3000 3000 12 4000 4000 12 5000 5000 13 6000 6000 13 7000 7000 13 8000 8000 13 9000 9000 14 10000 10000 14
  • 24. Important Differences: Input data needs to be sorted in Binary Search and not in Linear Search Linear search does the sequential access whereas Binary search access data randomly. Time complexity of linear search -O(n) , Binary search has time complexity O(log n). Linear search performs equality comparisons and Binary search performs ordering comparisons
  • 25. Greedy Algorithm • A greedy algorithm is an algorithmic paradigm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum.
  • 26. Usage of greedy algorithm • The greedy choice property: A globally optimal solution can be arrived at by making a locally optimal (greedy) choice. • The optimal substructure property:The optimal solution contains within its optimal solutions to subproblems.
  • 27. Method • Casting the optimization problem as one for which: we make a choice and are left with only one sub problem to solve • Proving the greedy choice: there is always an optimal solution to the original problem that makes the greedy choice • Proving the optimal structure: the greedy choice + an optimal solution to the resulting Sub problem leads to an optimal solution.
  • 28. Simple Example on greedy Algorithm method • $6.64 = $2 +$2 + $1 + $1 .25 + .25 + .10 + .01 + .01 + .01 +.01 • 10$= $5 + $5
  • 29. When Greedy Algorithm Fails The summation of two 5$ is 10$ but the summation of three 5$ cannot be 10 if its fixed. For example, $5 + $5 = $10 But, $5 + $5 + $5 ≠ $10
  • 30. Importance of Algorithm Design • It is used to store and access large quantities of data efficiently. • It is used to solve complex computational problems and to design of good programs • It is important to justify an algorithm correctness mathematically • It provides clear , simple and unambiguous description
  • 31. Conclusion • At last it may said that , the so called program name Algorithm design is one of the most enforceable solution program that can be used to solve any complicated , complex , and hard program. • Under considering the above case the concerned authority included the jubilant students should prefer this program with great care.