Code Monkey home page Code Monkey logo

cs165p1's Introduction

CS165P1

Private project repo for john lin and christ schlacta to solve the following problem:

<<<<<<< HEAD

  • Implement a subroutine doalg( n, k ) to do the following ** Initialize a private array of n random distinctly-valued elements (indexed from 1 to n) by invoking COMPARE( 0, n ) ** Compare the two array elements at indices x and y by invoking COMPARE( x, y ) ** Find the indices of the array elements that have the k largest values, in descending value order, by using a sequence of COMPARE() instructions, and store the k indices in an integer array Best[] *** For example, for n=7 and k=3, if the private array (indexed from 1 to 7) contains the values: 3,5,4,7,2,6,1 then the integer array Best[] (indexed from 1 to 3) should hold: 4,6,2 *** NOTE: This requires a careful design of an efficient algorithm. ** Check that Best[] does indeed contain the largest k array element indices in the correct order by invoking COMPARE( -1, k, Best[] ) which returns the number of element comparisons performed (the number of previous COMPARE invocations) if Best[] is correct or returns a negative value if there were any errors ** Your doalg() routine should be capable of handling values of n up to 10,000 and values of k up to 500
  • Implement a main routine with the following characteristics ** Call the doalg( n, k ) routine for the following values of ⟨n,k⟩ : *** n = 15, k = 3 *** n = 100, k = 10 *** n = 1000, k = 20 *** n = 10000, k = 40 ** Each ⟨n,k⟩ pair should be run at least 1,000 times ** Output the worst case and average number of element comparisons (to three decimal places) performed for each ⟨n,k⟩ pair On the basis of algorithmic theory, state the worst case number of element comparisons (upper bound) performed by your doalg( n, k ) routine as a function of n and k, including all constants. ** Do not use O-notation ** Justify your statement ** Compare your theoretical upper bound with your empirical observations and explain any discrepancies ======= Implement a subroutine doalg( n, k ) to do the following Initialize a private array of n random distinctly-valued elements (indexed from 1 to n) by invoking COMPARE( 0, n ) Compare the two array elements at indices x and y by invoking COMPARE( x, y ) Find the indices of the array elements that have the k largest values, in descending value order, by using a sequence of COMPARE() instructions, and store the k indices in an integer array Best[] For example, for n=7 and k=3, if the private array (indexed from 1 to 7) contains the values: 3,5,4,7,2,6,1 then the integer array Best[] (indexed from 1 to 3) should hold: 4,6,2 NOTE: This requires a careful design of an efficient algorithm. Check that Best[] does indeed contain the largest k array element indices in the correct order by invoking COMPARE( -1, k, Best[] ) which returns the number of element comparisons performed (the number of previous COMPARE invocations) if Best[] is correct or returns a negative value if there were any errors Your doalg() routine should be capable of handling values of n up to 10,000 and values of k up to 500 Implement a main routine with the following characteristics Call the doalg( n, k ) routine for the following values of ⟨n,k⟩ : n = 15, k = 3 n = 100, k = 10 n = 1000, k = 20 n = 10000, k = 40 Each ⟨n,k⟩ pair should be run at least 1,000 times Output the worst case and average number of element comparisons (to three decimal places) performed for each ⟨n,k⟩ pair On the basis of algorithmic theory, state the worst case number of element comparisons (upper bound) performed by your doalg( n, k ) routine as a function of n and k, including all constants. Do not use O-notation Justify your statement Compare your theoretical upper bound with your empirical observations and explain any discrepancies

3efb1ab0f494f02ef66594bd8b270068854fffe9

cs165p1's People

Contributors

aarcane avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.