[algogeeks] Re: How to solve this problem

2011-08-16 Thread Dave
@Ankur: The least significant digit of a[i], base n, is a[i]%n. The middle digit is (a[i]/n)%n, and the most signficant digit is a[i]/ (n*n). So the code looks something like int b[n], c[n], i, j; for( i = 0 ; i n ; ++i ) // sort by least significant digit c[i] = 0; for( i = 0 ; i n ; ++i )

Re: [algogeeks] Re: How to solve this problem

2011-08-15 Thread Ankur Garg
@Dave Dude can u provide a sample code...What do u mean by radix n ..also radix sort requires some other sorting algo to sort digits Regards Ankur On Sun, Aug 14, 2011 at 1:33 PM, Dave dave_and_da...@juno.com wrote: @Ankur: Use a radix sort with radix n. It will take 3 passes to sort the 3

Re: [algogeeks] Re: How to solve this problem

2011-08-15 Thread *$*
lets assume numbers are in range 0 - 4 ,and array is aarr . then range would be 0- 4^3 .. (0 - 64).. now allocate an arraay .. int *x = calloc(n^3,sizeof(int)) // can use even bits aalso .. but for simplicity of algo , using array for(int i=0;i4;i++) { x[arr[i]] = 1; } for(int i=0;i64;i++) {

[algogeeks] Re: How to solve this problem

2011-08-14 Thread Dave
@Ankur: Use a radix sort with radix n. It will take 3 passes to sort the 3 base-n digits, each of O(n), so the overall order will be O(n). On Aug 14, 10:08 am, Ankur Garg ankurga...@gmail.com wrote: This is one question from Coreman 3rd Edition - 8-3-4 --  Sort n integers in the range 0 to

[algogeeks] Re: How to solve this problem

2011-08-14 Thread Dave
@Gopi: Explain how a counting sort can be done without zeroing out an array of size n^3, and then scanning it, or explain how to do these operations in O(n). Dave On Aug 14, 10:52 am, *$* gopi.komand...@gmail.com wrote: if extra space is allowed .. can use counting sort On Sun, Aug 14,

Re: [algogeeks] Re: How to solve this problem

2011-08-14 Thread Kunal Patil
Yes..i agree with Dave..Here is what i think. As you have integers upto n^3 in your input, it would need [3*lg(n) + 1] bits to represent each integer. So take each group of r = ceil(lg(n)) bits at a time. So this becomes number of bits needed to represent single digit. Each digit thus can take 2^r

[algogeeks] Re: How to solve this problem efficiently?

2007-10-07 Thread Sticker
I guess it is binary search tree. Try this and you will get what you want. On Sep 26, 5:12 am, mukesh agrawal [EMAIL PROTECTED] wrote: What is binary index tree ? I googled it finding irrelevent information ... help needed .. On 9/25/07, Mohammad Naser Zandy [EMAIL PROTECTED] wrote: I

[algogeeks] Re: How to solve this problem efficiently?

2007-09-28 Thread mukesh agrawal
What is binary index tree ? I googled it finding irrelevent information ... help needed .. On 9/25/07, Mohammad Naser Zandy [EMAIL PROTECTED] wrote: I am agree with Sticker, I comes to write exactly what Sticker wrote. ;) It's O(N^2 / 2) that is 1+2+3+4+5+...+N. On 9/25/07, Sticker [EMAIL

[algogeeks] Re: How to solve this problem efficiently?

2007-09-24 Thread Mohammad Naser Zandy
I am agree with Sticker, I comes to write exactly what Sticker wrote. ;) It's O(N^2 / 2) that is 1+2+3+4+5+...+N. On 9/25/07, Sticker [EMAIL PROTECTED] wrote: I saw your ideas. Some of them are correct some are not. Here is what I am thinking. From the question we know that 1 ≤ M ≤ 100

[algogeeks] Re: How to solve this problem efficiently?

2007-09-22 Thread Jun
I already know how to solve it. Binary Index Tree is good approach to solve this problem. Thanks very body involved in this discussion! On Sep 22, 6:31 am, KK [EMAIL PROTECTED] wrote: On Sep 5, 11:07 am, jliang [EMAIL PROTECTED] wrote: how about a doubled linked list where you can remove

[algogeeks] Re: How to solve this problem efficiently?

2007-09-21 Thread KK
On Sep 5, 11:07 am, jliang [EMAIL PROTECTED] wrote: how about a doubled linked list where you can remove item at any index. the removing is O(1). you can also keep track of the current removing from a doubled linked list is O(1)? How? size S so if you are borrowing book at index greater

[algogeeks] Re: How to solve this problem efficiently?

2007-09-07 Thread MD
I can think of an o(n lg n) implementation that uses linked lists. Maintain LL of original book array: 26- 1- 42- 15 -3 this shrinks as books are removed. maintan LL of borrowed books: 3-4 .. Original LL now becomes 26-1-15 Sort the borrowed LL --(borrwored order may be 3-4-1 == 1-3-4) using

[algogeeks] Re: How to solve this problem efficiently?

2007-09-05 Thread Ray
I know the naive method. It's very straight. Just maintain an index array which records the index of the books. whenever one book is removed then update all elements in the index array after its index. It runs O (M N). I'd like to know is there any efficent data structure to speedup it?

[algogeeks] Re: How to solve this problem efficiently?

2007-09-05 Thread jliang
how about a doubled linked list where you can remove item at any index. the removing is O(1). you can also keep track of the current size S so if you are borrowing book at index greater than S/2, you traverse the list from the end, if index S/2, you traverse from the beginning. every time a

[algogeeks] Re: How to solve this problem efficiently?

2007-09-05 Thread adak
Of course, the index numbers lower than the book being checked out, don't need to be changed, just the higher numbers. I like using an array of structs with structure members which can group all the relevant data together that I want for that book, or student, etc. So Books[] might have: title,