21st Feb, 2011 1. Inversion Vector (30) An inversion vector, I(A) of an array A is an array of n-1 elements. The ith entry of the array I(A) is the number of elements greater than A[i] preceding it in the original array A. Clearly the first entry of I(A) is always zero as no element in an array precedes its first element. If the array is sorted then all elements of inversion vector would be zero. For e.g. in the array [25,7,52,3,21], the inversion vector would be [0,1,0,3,2]. You have to write a program which takes 7 distinct non-negative integers from the stdin. Store these numbers in an array. It must then write a function which takes an int array as its argument and returns the inversion vector of the given array. The program must also print each entry of the inversion array separated by a tab character. 2. Queue (40) A queue is a first in, first out (fifo) data structure. It can store elements of any type. Queue has an inherent notion of head and tail. Elements can be read/added/removed only from the head of the queue. That is, not all the elements can be accessed directly like in the case of arrays. A queue is characterised by two operations - enqueue and dequeue. a) enqueue - this operation adds an item to the head of the queue b) dequeue - this operation removes an item from the tail of the queue, and returns this value to the caller An integer queue can be implemented using a int-array. Write a C program which implements a queue including the enqueue and dequeue operations (functions). Restrict your domain of elements in the queue to positive integers. You may like to define a global integer array as your queue and a counter to keep track of number of elements in it. Prototypes are as follows: enqueue: void enqueue(int numToQueue) dequeue: int dequeue(). Create a queue of 10 elements using enqueue operation and then remove 7 elements out of it by using dequeue. Extra Credit : Make the above program menu driven. eg . Display the following menu : 1. Enqueue 2. Dequeue 3. Exit Take input from user choosing the operation. Exit from program only if user chooses exit. 3. Polite Numbers (30) In number theory, a polite number is a positive integer that can be written as the sum of two or more consecutive positive integers. Rest of the integers are said to be impolite. For e.g. 7 and 18 are a polite numbers as 7 = 3+4 and 18=5+6+7 The first few polite numbers are 3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, ... The politeness of a positive integer is the number of ways in which we can represent the given number as sum of positive consecutive integers. For e.g. 9 has a politeness of 2 as 9 = 2+3+4 as well as 4+5. Write a function, politeFunc, which takes a positive integer and prints various ways in which it can be represented as a sum of consecutive positive integers. Each possible representation is printed in a new line. For e.g. i. output for polieFunc(10) should be 1 2 3 4 ii. output for polieFunc(10) should be 2 3 4 4 5 If the number is impolite, output the string "I am RUDE!" Check your function for powers of 2 (2,4,8,16,...).