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

Small code have missing part, #question. /* * * * * * * * * * * * * * * * *...

#question. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Description: *

What is .net technology?, What is .NET TECHNOLOGY? .NET technological ...

What is .NET TECHNOLOGY? .NET technological innovation was presented by Enthusiasm, to get the industry from the SUN's Coffee. Few in the past, Enthusiasm had only VC++ and VB

Create xml document to save calendar information, Prepare an XML document t...

Prepare an XML document that contains calendar information such as the following text describes: The calendar is owned by a person (e.g. John Smith) and has a few paragraphs tha

Introduction to c#, All programs have to be done in console application. Pr...

All programs have to be done in console application. Program 1, 2 and 3 are due on 2/11/12 Program 4, 5, and 6 are due on 2/18/12 Program 7, 8, and 9 are due on 2/25/12 Program 10

Program for simulate part of the game of yahtzee, This assignment will make...

This assignment will make use of arrays and functions to simulate a game. ASSIGNMENT DESCRIPTION This program will simulate part of the game of Yahtzee! The player will

Irenecereno, Using the concept of structures, write a program to assign pas...

Using the concept of structures, write a program to assign passenger seats in an airplane. Assume a small airplane with seats numbered as follows: 1 A B C D 2 A B C D 3 A

Expression Tree, For this assignment you will read a file expression.txt an...

For this assignment you will read a file expression.txt and create an expression tree. The expression will be a valid infix expression with the all the necessary parentheses so tha

For loop , I am trying to get right side triangle in visual logic using for...

I am trying to get right side triangle in visual logic using for loop

No Linux Audible, Why no Audible support for Linux? Maybe they should use a...

Why no Audible support for Linux? Maybe they should use a browser interface?

Data analytics, can i get assignments on Data analytics?

can i get assignments on Data analytics?

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