The document discusses various searching and sorting algorithms that use the divide and conquer approach. It describes linear search, binary search, and merge sort algorithms. Linear search has a time complexity of O(n) as it must examine each element to find the target. Binary search has a time complexity of O(log n) as it divides the search space in half each iteration. Merge sort also has a time complexity of O(n log n) as it divides the list into single elements and then merges them back together in sorted order.
Searching is a fundamental operation in data structures and algorithms, and it involves locating a specific item within a collection of data. Various searching techniques exist, and the choice of which one to use depends on factors like the data structure, the nature of the data, and the efficiency requirements.
Searching is a fundamental operation in data structures and algorithms, and it involves locating a specific item within a collection of data. Various searching techniques exist, and the choice of which one to use depends on factors like the data structure, the nature of the data, and the efficiency requirements.
Sorting in data structures is a fundamental operation that is crucial for optimizing the efficiency of data retrieval and manipulation. By ordering data elements according to a defined sequence (numerical, lexicographical, etc.), sorting makes it possible to search for elements more quickly than would be possible in an unsorted structure, especially with algorithms like binary search that rely on a sorted array to operate effectively.
In addition, sorting is essential for tasks that require an ordered dataset, such as finding median values, generating frequency counts, or performing range queries. It also lays the groundwork for more complex operations, such as merging datasets, which requires sorted data to be carried out efficiently.
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of array.
Sorting in data structures is a fundamental operation that is crucial for optimizing the efficiency of data retrieval and manipulation. By ordering data elements according to a defined sequence (numerical, lexicographical, etc.), sorting makes it possible to search for elements more quickly than would be possible in an unsorted structure, especially with algorithms like binary search that rely on a sorted array to operate effectively.
In addition, sorting is essential for tasks that require an ordered dataset, such as finding median values, generating frequency counts, or performing range queries. It also lays the groundwork for more complex operations, such as merging datasets, which requires sorted data to be carried out efficiently.
Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of array.
Explore our comprehensive data analysis project presentation on predicting product ad campaign performance. Learn how data-driven insights can optimize your marketing strategies and enhance campaign effectiveness. Perfect for professionals and students looking to understand the power of data analysis in advertising. for more details visit: https://bostoninstituteofanalytics.org/data-science-and-artificial-intelligence/
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Data and AI
Round table discussion of vector databases, unstructured data, ai, big data, real-time, robots and Milvus.
A lively discussion with NJ Gen AI Meetup Lead, Prasad and Procure.FYI's Co-Found
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...John Andrews
SlideShare Description for "Chatty Kathy - UNC Bootcamp Final Project Presentation"
Title: Chatty Kathy: Enhancing Physical Activity Among Older Adults
Description:
Discover how Chatty Kathy, an innovative project developed at the UNC Bootcamp, aims to tackle the challenge of low physical activity among older adults. Our AI-driven solution uses peer interaction to boost and sustain exercise levels, significantly improving health outcomes. This presentation covers our problem statement, the rationale behind Chatty Kathy, synthetic data and persona creation, model performance metrics, a visual demonstration of the project, and potential future developments. Join us for an insightful Q&A session to explore the potential of this groundbreaking project.
Project Team: Jay Requarth, Jana Avery, John Andrews, Dr. Dick Davis II, Nee Buntoum, Nam Yeongjin & Mat Nicholas
2. Divide and conquer
• it is the process of dividing a complex problem into two or more sub-
problems of the same type until the sub-problems are easy enough to be
solved directly and recursively,
• and then these solutions are combined to give a solution to the initial problem.
• It is the foundation of efficient algorithms for many different problems,
• including sorting problems and the discrete Fourier transform.
• main steps of the divide and conquer paradigm
1. Divide the problem into two (or more) sub-problems
2. Conquer these sub problems recursively
3. Combine the solutions to the sub problems in order to get a solution to
the original problem.
3. Advantages of divide and conquer paradigm
• It allows us to solve difficult and often impossible looking problems, such
as the Tower of Hanoi
• it reduces the degree of difficulty since it divides the problem into sub problems
• Runs faster than other algorithms would
• it often plays a part in finding other efficient algorithms, and in fact it was
the central role in finding the quick sort and merge sort algorithms.
• It also uses memory caches effectively.
• when the sub problems become simple enough, they can be solved within a cache,
without having to access the slower main memory
4.
5. Disadvantages
• The recursion is slow
• It can become more complicated than a basic iterative approach,
• especially in cases with a large n (add a large amount of numbers together)
• sometimes once the problem is broken down into sub problems, the same
sub problem can occur many times.
• these algorithms can be carried out by a non-recursive program that will
store the different sub problems in things called explicit stacks (not call
stacks),
• which gives more freedom in deciding just which order the sub problems should be
solved.
6. Some algorithms
• Binary Search,
• the Merge Sort Algorithm,
• the Quick sort algorithm,
• Matrix Multiplication,
• and the fast Fourier transform
7. Searching algorithms: linear search
• Searching is the process of finding some particular element in the list.
• If the element is present in the list,
• then the process is called successful and the process returns the location of that
element,
• otherwise the search is called unsuccessful.
• There are two popular search methods that are widely used
• Linear Search / Sequential Search
• Binary search
8. Linear Search / Sequential Search
• Linear search, also called as sequential search
• is a very simple method used for searching an array for a particular value.
• It works by comparing the value to be searched with every element of the array one
by one
• mostly used to search an unordered list of elements
• int A[ ] = {10, 8, 1, 21, 7, 32, 5, 11, 0};
9. LINEAR_SEARCH(A, N, VAL)
Step 1: [INITIALIZE] SET POS = -1
Step 2: [INITIALIZE] SET I = 0
Step 3: Repeat Step 4
while
I<=N
Step 4: IF A[I] = VAL
SET POS = I
PRINT POS
Go to Step 6
[END OF IF]
SET I=I+1
[END OF LOOP]
Step 5: IF POS = –1
PRINT "VALUE IS NOT PRESENTIN
THE ARRAY"
[END OF IF]
Step 6: EXIT
Write a program to search an element in an array using the linear
search technique.
#include<stdio.h>
void main ()
{
int a[10] = {10, 23, 40, 1, 2, 0, 14, 13, 50, 9};
int item, i,flag;
printf("nEnter Item which is to be searchedn");
scanf("%d",&item);
for (i = 0; i< 10; i++){
if(a[i] == item){
flag = i+1;
break;}
else
flag = 0;}//end of loop
if(flag != 0){
printf("nItem found at location %dn",flag);
}
else{
printf("nItem not foundn");}
} //end of main method
10. Advantages of a linear search
• Will perform fast searches of small to medium lists.
• With today's powerful computers, small to medium arrays can be searched
relatively quickly.
• The list does not need to be sorted.
• Unlike a binary search, linear searching does not require an ordered list.
• Not affected by insertions and deletions.
• As the linear search does not require the list to be sorted, additional elements can
be added and deleted.
• As other searching algorithms may have to reorder the list after insertions or
deletions, this may sometimes mean a linear search will be more efficient.
11. Disadvantages of a linear search
• Slow searching of large lists.
• For example, when searching through a database of everyone in Ethiopia to find a
particular name,
• it might be necessary to search through 120 million names before you found the
one you wanted.
• This speed disadvantage is why other search methods have been developed.
• Space and time complexity
• Space complexity
• It takes up no extra space;
• its space complexity is O(n) for an array of n elements.
12. Complexity of Linear Search Algorithm
• Best Case Complexity
• The element being searched could be found in the first position.
• In this case, the search ends with a single successful comparison.
• Thus, in the best-case scenario, the linear search algorithm performs O(1)
operations.
• Worst Case Complexity
• The element being searched may be at the last position in the array or not at all.
• The search succeeds in ‘n’ comparisons or the search fails after ‘n’ comparisons.
• Thus, the linear search algorithm performs O(n) operations.
• Average Case Complexity
• When the element to be searched is in the middle of the array, the average case of
the Linear Search Algorithm is O(n).
13. BINARY SEARCH
• works efficiently on the sorted lists
• follows divide and conquer approach
• the list is divided into two halves and the item is compared with the middle element
of the list.
• If the match is found then,
• the location of middle element is returned otherwise,
• we search into either of the halves depending upon the result produced through the match.
• Let us consider an array arr = {1, 5, 7, 8, 13, 19, 20, 23, 29}. Find the
location of the item 23 in the array.
14. • Let us consider an array arr = {1, 5, 7, 8, 13, 19, 20, 23, 29}. Find the
location of the item 23 in the array.
In 1st step :
1. BEG = 0
2. END = 8
3. MID = 4
4. a[mid] = a[4] = 13 < 23,
therefore
in Second step:
1. Beg = mid +1 = 5
2. End = 8
3. mid = 13/2 = 6
4. a[mid] = a[6] = 20 < 23,
therefore
in third step:
1. beg = mid + 1 = 7
2. End = 8
3. mid = 15/2 = 7
4. a[mid] = a[7]
5. a[7] = 23 = item;
6. therefore, set location
= mid;
7. The location of the item
15.
16. BINARY_SEARCH(A,lower_bound, upper_bound, VAL)
Step 1: [INITIALIZE] SET BEG = lower_bound
END = upper_bound, POS = - 1
Step 2: Repeat Steps 3 and 4 while BEG <= END
Step 3: SET MID = (BEG + END)/2
Step 4: IF A[MID] = VAL
SET POS = MID
PRINT POS
Go to Step 6
ELSE IF A[MID] > VAL
SET END = MID - 1
ELSE
SET BEG = MID + 1
[END OF IF]
[END OF LOOP]
Step 5: IF POS = -1
PRINT “VALUE IS NOT PRESENT IN THE ARRAY”
[END OF IF]
Step 6: EXIT
int binarySearch(int a[], int beg, int end,
int item){
int mid;
if(end >= beg){
mid = (beg + end)/2;
if(a[mid] == item){
return mid+1;}
else if(a[mid] < item){
return binarySearch(a,mid+1,end,item);
}else{
return binarySearch(a,beg,mid-1,item);
}}
return -1;
17. Advantages
• It eliminates half of the list from further searching by using the result of
each comparison.
• It indicates whether the element being searched is before or after the
current position in the list.
• This information is used to narrow the search.
• For large lists of data, it works significantly better than linear search.
18. Disadvantages
• It employs recursive approach which requires more stack space.
• Programming binary search algorithm is error prone and difficult.
• The interaction of binary search with memory hierarchy i.e. caching is poor.
(because of its random access nature)
• Complexity of Binary Search Algorithm
• As it disposes off one part of the search case during every step of binary
search, and perform the search operation on the other half,
• this results in a worst case time complexity of O(logN).
• What is the best case and average case time complexity ?
19. Sequential Search Binary Search
Time complexity is O(n) Time complexity is O(log n)
Finds the key present at first position in
constant time
Finds the key present at center position in
constant time
Sequence of elements in the container does
not affect.
The elements must be sorted in the
Container
Arrays and linked lists can be used to
implement this
It cannot be implemented directly into the
linked list. We need to change the basic
rules of the list to implement this
Algorithm is iterative in nature Algorithm technique is Divide and
Conquer.
Algorithm is easy to implement, and
requires less amount of code.
Algorithm is slightly complex. It takes
more amount of code to implement.
N number of comparisons are required for
worst case.
Log n number of comparisons are
sufficient in worst case.
20. Sorting Algorithms: Merge-sort
• It is one of the well-known divide-and-conquer algorithms
• is a simple and very efficient sorting algorithm.
• Steps
• Divide: Split Array A into two sub-sequences, each of size roughly n/2 .
• Conquer: Sort each subsequence (by calling MergeSort recursively on each).
• Combine: Merge the two sorted sub-sequences into a single sorted list.
• The dividing process ends when we have split the sub-sequences down to
a single item.
• It works top-down splitting up the list into smaller sub-lists
• The “conquer and combine” phase works bottom-up, merging sorted lists
together into larger sorted lists.
21. • Algorithm:
1. Divide the array in to two halves.
2. Recursively sort the first n/2 items.
3. Recursively sort the last n/2 items.
4. Merge sorted items (using an auxiliary array).
23. Merge(L,R, A)
{
nLlength(L)
nRlength(R)
ijk0
while(i<nL && j<nR){
If(L[i]<=R[j]) {
A[k]L[i]
ii+1
}
Else{
A[k]R[j]
Jj+1
}
Kk+1
}
While(i<nL)
{
A[k]L[i]
Ii+1
Kk+1
}
While(j<nR)
{
A[k]R[j]
jj+1
Kk+1
}
}
Merge_sort(A)
{
Nlength(A)
If(N<2)
Return
Midn/2
Leftarray of size(mid)
Rightarray of size(n-mid)
For i0 to mid-1
Left[i]A[i]
For imid to n-1
Right[i-mid]A[i]
Merge_sort(left)
Merge_sort(Right)
Merge(left,right,A)
}
24. Advantages and disadvantages
• Advantages :
• is best case for sorting slow-access data e.g) tape drive.
• is better at handling sequential - accessed lists.
• Disadvantages:
• Slower comparative to the other sort algorithms for smaller tasks.
• Merge sort algorithm requires additional memory space of 0(n) for the temporary
array .
• It goes through the whole process even if the array is sorted.
25. • Complexity of Merge Sort
• The running time of merge sort in the average case and the worst case can be given
as O(n logn).
• Although merge sort has an optimal time complexity, it needs an additional space
of O(n) for the temporary array TEMP.
• Applications
• Merge Sort is useful for sorting linked lists in O(nLogn) time.
• Inversion Count Problem
• Used in External Sorting