Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following problem: You are given a number n and an array A of n numbers, indexed from 1 to n. Design an algorithm

Consider the following problem: You are given a number n and an array A of n numbers, indexed from 1 to n. Design an algorithm that decides if A contains the numbers 1, 2, 3,..., n, arranged in any order. For example, suppose that n=5, and A = [4, 1, 5, 2, 3], then the answer would be yes, but if A= [1, 2, 3, 4, 10] the answer would be no. Remember that you will be marked on the clarity and time efficiency of your algorithm.

a) [9 marks] Describe the main ideas of your algorithm in words, then describe your algorithm in pseudocode (try to use pseudocode which is similar to that in the textbook).

b) [4 marks] Do a worst case analysis of your algorithm, counting both the comparison of the numbers in A with anything, AND counting the number of times you write a number to an array. Use n as your input size. Be sure to explain your analysis.

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

Students also viewed these Databases questions