Question
Working with arrays--Searching and Sorting Algorithms Task 1:Searching an Array Based List--Linear Search Write a function thatsearches if a specific value exists inan array. If
Working with arrays--Searching and Sorting Algorithms
Task 1:Searching an Array Based List--Linear Search
Write a function thatsearches if a specific value exists inan array. If the value is found, the function returns its index. If the value is not in the array, it returns -1. Assume that the data in the array is not sorted.
Note: Swift has a build-in function calledindex(of:)that does the same thing. However, our objective here is to study search algorithms. So we're going to ignore it and write our own function.
Write an algorithm and verify it with an example
Implement it in Swift and test it.
Be ready to demo
Submit your final solution for credit
Task 2:A More Efficient Search for Sorted Lists
Assume the list stored in the array is sorted in ascending order. How would you change your search algorithm to make more efficient?
write an algorithm and verify it with an example
Implement it in Swift and test it
Be ready to demo
Submit your final solution for credit
Task 3:Sorting an array based list
Assume youre given a list of numbers to sort (in either order). Develop an algorithm to sort it.
Note: Swift also has a sort function that can be used to sort arrays. But then again, our objective in this activty is to study sorting algorithm as we work with arrays. So we will develop our own sort function(s).
To develop an algorithm you need to be able to solve the problem manually first using some sample data.
Create a sample list to work with
Sort the sample list manually
Note: As you develop your algorithm, you need to assume that the list is very longto the pointthat you cant visually scan it all at once and sort the data mentally. This is to simulate the fact that the computer can only see one number at a time as it re-arranges them
Verify your algorithm with another simple example
Implement your algorithm in Swift
Test it using one of the examples you used in the steps above
Be ready to demo your algorithm and your Swift function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started