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

Assignment Help:

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.

Example

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

Output

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.


Related Discussions:- Algorithm of sort the given array remove the repeated value

Game, How to make game in pascal language

How to make game in pascal language

Improved application deployment, Improved Application Deployment Data sourc...

Improved Application Deployment Data source implementation is perhaps the key to any Asp.net program implementation, and, if the database implementation is easily done, there is an

Genetic diseases, Genetic Diseases Problem Description Many human di...

Genetic Diseases Problem Description Many human diseases could be controlled by the knowledge of the gene's structure and pattern. The human gene could be represented by fou

Simulation algorithm, Please remember to read and follow all of the assignm...

Please remember to read and follow all of the assignment guidelines. This assignment will expand upon the simulation algorithm given in class to produce a program which may be u

Create an xslt stylesheet-attributes to elements , Attributes to Elements ...

Attributes to Elements Create an XSLT stylesheet that converts all attributes found in a given XML document to elements.Use the sample instance from question 2 to test the tra

I need to do coding for the last three question, i attached the assignment ...

i attached the assignment document only i need your help with following three parts: accessible areas, accessible cul-de-sacs that are all connected, entry-exit path with no in

C program with creation of child process using fork system, Problem 6. ...

Problem 6. Demonstrate how and when can you use the commands- vi, cat, chmod, grep, man, pwd, ps, kill, mkdir, rm demonstrating how and when the above 10 commands can be

Object oriented programming, I need help with this question. The problem i'...

I need help with this question. The problem i''m having is that what''s the syntax for using dynamic memory allocation of objects of one class in the constructor of some other clas

Triple eigenvalue with 3 linearly independent eigenvectors, 1 Triple Eigenv...

1 Triple Eigenvalue with 3 Linearly Independent Eigenvectors In this case we will have the eigenvalue l with the three linearly independent eigenvectors  ?h 1 , ?h 2 and  ?h

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd