Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
Ex 07

Ex 07

Ratings: (0)|Views: 118|Likes:
Published by rajasoty

More info:

Published by: rajasoty on Oct 15, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Assignment Number Assignment Number Assignment Number Assignment Number 7777
Given: 24/06/08Due: 08/07/08
Before doing the exercise, please read very carefully the submission guidelines. If youhave any questions about the exercise, please refer to theFAQpage first. If your questionis not answered there send an email.If the user enters invalid input your program should print "
" and main should returnthe value -1.
Ex 7.1 – Merge Sort
Write a program that recursively sorts an array of numbers. It first sorts the left half of thearray, then the right half of the array and then merges to the two into a single sorted array.The program:
Reads an integer number, which tells how many numbers are in the array
Reads an array of integers.
Sorts the array.
Prints the sorted array.Assumptions:
You will be given the first number.
You have to check that it is a valid number.
If it is valid then it gives the correct number of elements in the array.
There are going to be up to 100 elements in the array.
If there are more than 100 characters then the input is invalid.You must write the following functions:
The function recursively sorts the array.
voidmergeArrays(int*leftArr,intleftSize, int*rightArr,intrightSize, int*destArr )
The function merges the left and right arrays into destArr.
The function copies the source array into the destination array.Example:
1010 9 8 7 6 5 4 3 2 1
1 2 3 4 5 6 7 8 9 10
The file name should be:
Ex 7.2 – Binary Search
Write a program that performs a binary search on a sorted array of integers.Given a sorted array of elements and a query element, you compare the query against theelement in the middle of the array (marked in green). If they are the same then there isnothing more to do. Otherwise, if the query is smaller than the element in the middle of the array, then it must appear before it in the array. So you need to search in the left half (marked in white). If it is bigger, then you need to search the right half (marked inyellow).You repeat this until, you find the element, or you can't divide the array no more.The program:
Reads an integer number, which tells how many numbers are in the array
Reads the sorted array of integers.
Reads an integer number, which will be the search query.
Prints a message telling if the number appears in the array or not.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->