Algorithm of sort the given array remove the repeated value, Programming Languages

Short Arrays:

Array = randi(10,1,randi(6,1,1)+4)-5

This command will generate an array which you should be able to evaluate by hand (and also have your code evaluate for testing purposes).

Long Arrays:

Array = randi(200,1,randi(500,1,1)+50)-100

This command will generate an array which will be too large to evaluate by hand, but which your code should still work with.

Sort the given array 

Remove the repeated values (as asked for extra credit)

Intialize solution vector

Find the last negative element in shorted array , assume its index be last_n

Outer loop

  From 1st element up to last negative element

       First atom  = array(I,i)

          Inner loop

              From last element to first positive element in array

                     Second atom = array (1,j)

                     Find the third element

                            Third element = 0- (first atom + second atom)

                            Check (third_elemnt <= second atom) % this step is to avoid repetition of same solution

                                           Search the element inarray

                                            If it is present add this to solution vector

                     Else proceed for next iteration

            Close inner loop

Close outer loop

Advantage now there are no repeated results , the number of loops has been reduced using the algorithm.


Input array   = [5    -3     5     2    -4    -2     1     5     5  0]

sorted array =   -4    -3    -2     0     1     2     5     5     5     5 

Unique array and sorted = -4    -3    -2     0     1     2     5

Index of last negative number =3

Outer loop  i=1:1:3

Inner loop  j =7:-1:5


sol =


    -4     2     2

    -3     5    -2

    -3     2     1

    -2     5    -3

    -2     2     0

    -2     1     1

There are no repeated solution

Each vector  is unique.

Posted Date: 7/23/2012 2:52:54 AM | Location : United States

Related Discussions:- Algorithm of sort the given array remove the repeated value, Assignment Help, Ask Question on Algorithm of sort the given array remove the repeated value, Get Answer, Expert's Help, Algorithm of sort the given array remove the repeated value Discussions

Write discussion on Algorithm of sort the given array remove the repeated value
Your posts are moderated
Related Questions
write a program to draw a cow. Now, draw a cow standing amongst the grass, with (say) 500 blades of grass. Each blade of grass should be a separate random green line. Do all your d

wat is- m=5; n=3; x=m++-n+++m;

I have constantly been emailing to get the task i had paid for to be done correctly but no replies from anyone. Not even one acknowledging my emails. Been phoning all the way from

Hi, Can you do exercises: D2, D3, D4, and D5 on page 230 of the following book: . The book can be downloaded for free from t

i(t)=(V/R) * (1-e^-(R/L)(t)) (a) Defi ne an anonymous function answerE that returns i(t) given input t. (b) The fi nal value for the current is 2 amps. Find a time tm when the curr

I can attach or send the assignment instructions, but they''re rather long. 90% of the code is already written and given to us. The assignment is primarily rewriting and rearrangin

Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4

How does a program provide "input" to one of its functions?

XYZ International is a large Institute; Management in this institute wants to create Proper Student management System. There for they contact you and asked you to create Propto typ

Eclipse Jsp Project. I am making a a project on my website and i was making a help support page on which the user can submit their question and the question is saved to a text file