Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the

Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the index of the search key if the search key exists and return -1 if the search key doesn't exist. [10 Points]

Q2] Write a C function to implement the selection sort algorithm, to sort an array of float values and size n. The function should sort the array in ascending order [10 Points].

Q3) Write a C function using recursion to check if a given array of integer values of size n is a partially sorted array of degree m or not. The function IsPartiallySoreted will return 1 if the given array is an imperfect sorted array of degree less than or equal m and return 0 if the imperfect degree is g reater than m . [40 points]

Given an array of n elements, where each element is at most m positions away from its target position if the array was sorted correctly, we call this array an imperfect sorted array of degree m NOTE: you may assume that all the values in the array are unique (no duplicates). Examples, Is the following array is an imperfect sorted array of degree 2 ? in other words, m = 2

image text in transcribed

YES : We can see that for a sorted array the values 9, 10, 12, 14, and 11 are not in their correct positions, however, to put any of them in its correct position we only need to move it at most 2 positions, for example, 11 will move from Array[7] to Array[5] and 10 will move from Array[3] to Array[4]

Examples, The following array Is NOT an imperfect sorted array of degree 3, in other words, m = 3

image text in transcribed

NO: We can see that for value 1 to be in the correct position it has to move from Array[7] to Array[0], therefore m > 3

Q4) Write a complete C program to test your implementation of the C functions in Q1, Q2, and Q3. In addition, write/use C functions EnterArrayData( int size, int data[]) an d PrintArrayData( int size, int data[]) , to allow the user to enter the data for the array and display the array data when needed [40 Points]

Rules and Conditions

The IsPartiallySoreted ( ) MUST have the header int IsPartiallySoreted ( int size, int data[], int m, ... ) , you CAN NOT change the return type, however, you may add some additional arguments or change them if needed. If you change the return type you lose points [-10 points]

You are NOT allowed to use any iterative programming keywords to implement IsImpSortArray. You CAN NOT use for, while or do - while . If you use any of these C/C++ statements you lose point [-10 points]

You are NOT allowed to use any Global or Static variables. If you used any Global or any Static variables you lose [-10 points]

You may create some additional functions or use some of the existing functions from Q1-Q4 if needed .

| 3|1|| 10 | | 12 | 14 |1 | 7| 20 ] 14 20 | 10 | 11 | 51 | 21 | 9 | 7 | 5 | 1 | 12 | 15

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions

Question

What is job rotation ?

Answered: 1 week ago

Question

1. Define and explain culture and its impact on your communication

Answered: 1 week ago