anonymous
  • anonymous
Your task is to find the number of inversions in the file given (every row has a single integer between 1 and 100,000). Assume your array is from 1 to 100,000 and ith row of the file gives you the ith entry of the array. Write a program and run over the file given. The numeric answer should be written in the space. So if your answer is 1198233847, then just type 1198233847 in the space provided without any space / commas / any other punctuation marks. You can make upto 5 attempts, and we'll count the best one for grading. (We do not require you to submit your code, so feel free to choose th
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
anonymous
  • anonymous
are you doing http://algo-class.org
anonymous
  • anonymous
yup... u 2?
anonymous
  • anonymous
I havent found the time to sit and watch lectures/do assignments :(

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
the answer to this problem is probably one line in Python (a really slow line though). I am wondering what's the right way to do this one... maybe some guru will show up :-D
anonymous
  • anonymous
same here.... :D simply cant figure how to take a 100000 size array... or an equivalent data structure...
anonymous
  • anonymous
what is an inversion in an array of integers?
anonymous
  • anonymous
here philips chk his out http:// http://en.wikipedia.org/wiki/Inversion_(discrete_mathematics)
anonymous
  • anonymous
import random #to get some random numbers SIZE = 1000 #size of dataset to use # set up an array of random integers (may repeat numbers) dataset = {} for i in range(SIZE): dataset[i] = int(random.random() * SIZE) #count the number of inversions count = 0 for i in range(SIZE): for j in range(i,SIZE): if dataset[i] > dataset[j]: count += 1 print count
anonymous
  • anonymous
hey philips i want help on how to feed 100000 numbers in an array, as tc compiler simply just wont accept an array of that size... as fr the code i hv managed to work it out... thanx fr d help anyways.... :D
anonymous
  • anonymous
Where is the datafile? You have piqued my curiosity now. if this old browser box of mine can crunch a 100k integer array, almost anything else should be able to do it too.
anonymous
  • anonymous
here is the txt file i hv to find the number of inversions fr...
1 Attachment
anonymous
  • anonymous
any luck philips?
anonymous
  • anonymous
Yes; I have this question as well. How do we enter a file into our program?
anonymous
  • anonymous
to read in a file in python: dataset = [] with open(FILENAME, 'r') as f: dataset = f.readlines()
anonymous
  • anonymous
sry i dunno python as well...
anonymous
  • anonymous
i know hw to take input in c++, bt prob is 100000 size fr array in c++
anonymous
  • anonymous
You must be using a POS (painful operating system) and compiler. Is there a compiler option to tell it to go ahead and make a decent sized heap? Well, anyway, thanks for the challenge. I have not touched C++ in over 10 years. Probably more like 20 but I don't want to think about that. This loaded your file fine for me, using gnu c++ on a very old Ubuntu Linux box: int c = 0; ifstream infile("countinvfind.txt"); int dataset[100000]; while (infile >> dataset[c++]) ; Make sure you use a long int to count the inversions. There are billions to find. And best of luck with what I assume is Microsoft (64k is enough for anyone) Windows. Meanwhile, you have me wasting all of my free time the next few days finding out why my Python script found 100million fewer inversions than this C++ did on the same file. That's around a 5% discrepancy. And the interpreter took about an hour to grind it out, while this executable did it in a couple minutes.

Looking for something else?

Not the answer you are looking for? Search for more explanations.