You are not logged in. Please login at www.codechef.com to post your questions!

×

Sorting large array of long long int

Hey guys, i'm working on a problem where I have to sort large array of long long int ( array size of nearly 1000000). I've tried to do it with merge sort as it has a complexity of O(n*log(n)) in worst case but still getting TLE. So , is there's a most efficient way (time speaking) to sort all this data ? thank you :)

asked 09 Mar '14, 20:21

the_aviator's gravatar image

2★the_aviator
26114
accept rate: 0%

edited 09 Mar '14, 21:04


i dont know why but qsort() didnt work for me when i tried to sort %lld, so i used sort(a, a+n) from <algorithm>

link

answered 09 Mar '14, 23:26

garakchy's gravatar image

1★garakchy
1.1k163048
accept rate: 1%

Same thing. I tried a different version where I used a vector and the sort function from <algorithm> but still getting TLE :/

link

answered 10 Mar '14, 03:17

the_aviator's gravatar image

2★the_aviator
26114
accept rate: 0%

i dont know vectors. why dont you use maps, which automatically sorts

(10 Mar '14, 04:13) garakchy1★

I don't get it. what do you mean by using maps ?

(10 Mar '14, 04:29) the_aviator2★

Advice: shortn your long integer to their decimals by dividing it to {100,1000 or 1000000}.

put them in new array , apply function "Sort" on the new array, then arange your real 'the long' array according to the positions of the small array.

Note: this way is way successful with diffrent long Numbers array, but i don't now for simlar big no. with least digits changes, for ex: 966662.. 966661.. 966663.. 9666631..

link

answered 11 Mar '14, 14:02

eng_ghanima's gravatar image

0★eng_ghanima
70124
accept rate: 11%

edited 16 Mar '14, 12:14

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×1,901
×776
×47

question asked: 09 Mar '14, 20:21

question was seen: 4,381 times

last updated: 16 Mar '14, 12:14