Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 (one submission per group)

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 (one submission per group)

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

Once you figure out how to sort manually, trace your steps and write them down into an algorithm

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

This is a group activity. In every step, think about the problem individually for few minutes. Then discuss your ideas within your group to come up with a common solution.

Submit your final solution for credit (one

***the first answer returns alot of build errors

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago