Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Suppose that a is a sorted (in increasing order) array of n distinct positive integers a[0]a[n1] where n is a multiple of 4 . Given

image text in transcribedimage text in transcribedimage text in transcribed

Suppose that a is a sorted (in increasing order) array of n distinct positive integers a[0]a[n1] where n is a multiple of 4 . Given a positive integer x and the array a, an algorithm S finds, by comparing values, the index of x in the array. If x is not in a the algorithm S returns 1. S can be modelled by the following decision tree: Suppose that a is a sorted (in increasing order) array of n distinct positive integers a[0]a[n1] where n is a multiple of 4 . Given a positive integer x and the array a1 an algorithm S finds, by comparing values, the index of x in the array. If x is not in a the algorithm S returns 1. S can be modelled by the following decision tree: (a) For n=12 what is the worst case number of key comparisons performed by S ? [ 2 marks] (b) Give a general expression for W(n), the worst case performance (with respect to comparisons) of S. You may assume here and in part (c) below that only one key comparison is required to determine whether xa[i]. [4 marks] (c) Suppose that, if x is in the array, it is equally likely to be in any position. Derive an expression for As(n), the average case performance for a successful search. [14 marks] Suppose that a is a sorted (in increasing order) array of n distinct positive integers a[0]a[n1] where n is a multiple of 4 . Given a positive integer x and the array a, an algorithm S finds, by comparing values, the index of x in the array. If x is not in a the algorithm S returns 1. S can be modelled by the following decision tree: (a) For n=12 what is the worst case number of key comparisons performed by S ? [2 marks] (b) Give a general expression for W(n), the worst case performance (with respect to comparisons) of S. You may assume here and in part (c) below that only one key comparison is required to determine whether xa[1]. [4 marks] (c) Suppose that, if x is in the array, it is equally likely to be in any position. Derive an expression for As(n), the average case performance for a successful search. [14 marks]

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

Build It For The Real World A Database Workbook

Authors: Wilson, Susan, Hoferek, Mary J.

1st Edition

0073197599, 9780073197593

More Books

Students also viewed these Databases questions