Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please make sure it's O(n). Try to take screenshots of the code so I can see the indentations. If it's good, I will give thumbs

image text in transcribed

Please make sure it's O(n). Try to take screenshots of the code so I can see the indentations. If it's good, I will give thumbs up 100%. Thanks.

4. Scrambled Here is a programming puzzle that you might find in the real world. It requires conditionals, loops and arrays. There is a simple O(n) algorithm to solve the problem (.e. you do not need to sort anything). Requirements 1. Create a new file called scrambled.c, containing a single function that matches this declaration: int scrambled( unsigned int arr1[], unsigned int arr2[], unsigned int len); 2. Arrays arri and arr2 are both of length len, and contain values in the range [0 .. 99] inclusive, only. 3. The function scrambled() should return 1 iff arrays arrl and arr2 contain the same values in any order, or 0 otherwise. 4. len can have any unsigned int value, including 0. 5. If len is 0 then scrambled() should return 1 (since the arrays have the same - empty - contents). 6. You must not change the contents of the arrays. 7. Use an algorithm that has run time linear in the array length n. Note that this means you can not sort the arrays since that can not be done in linear time. Examples of arrays for which scrambled should return 1: arr1 = {10,15,20), arr2 = {10,15,20) arr1 = {99), arr2 = {99) arr1 = {1,2,3,4,5), arr2 = {5,3,4,2,1) arr1 = ), arr2 = { (i.e. len = 0) arr1 = (2,1,3,4,5), arr2 = {1,2,4,3,5) Examples of arrays for which scrambled should return 0: arr1 = {1,1), arr2 = {1,2} arr1 = 10,15,20), arr2 = {10,15,21) arr1 = {1,2,3,4,5), arr2 = {5,3,4,2,2) Example of a program that uses your function: 1. #include 2. // declaration of function implemented in scrambled.c 3. int scrambled(unsigned int arril), unsigned int arr2[), unsigned int len); 5. int main(void) 6. { 7. unsigned int arr1[3] = {10, 15, 20); unsigned int arr2[3] = {10, 20, 15}; 8. 10. 11. if( scrambled( arri, arr2, 3) == 1) { printf("arr2 is a scrambled version of arri "); } else { printf( "arr2 has different contents to arri "); } 13. 15. 16. 17. return 0

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_2

Step: 3

blur-text-image_3

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

T Sql Fundamentals

Authors: Itzik Ben Gan

4th Edition

0138102104, 978-0138102104

More Books

Students also viewed these Databases questions