DO NOT WRITE CODE! EXPLAIN AN ALGORITHM You have to write an algorithm that solves the following problem: Given a collec

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
correctanswer
Posts: 43759
Joined: Sat Aug 07, 2021 7:38 am

DO NOT WRITE CODE! EXPLAIN AN ALGORITHM You have to write an algorithm that solves the following problem: Given a collec

Post by correctanswer »

DO NOT WRITE CODE! EXPLAIN AN ALGORITHM
You have to write an algorithm that solves the following
problem: Given a collection (unsorted) of n screws and n
corresponding nuts, each screw must be matched to its nut of the
same size. This should be done as fast as possible. All nut and
screws can be pairedand there will be no nuts or screws left over,
butthere may be multiple screws/ nuts of the same size. Screws and
nuts are a pair if they are the same size. For simplicity, we will
assume that the collection of nuts is given as a list ofpart
numbers (implemented as a list of integers). These are not the
sizes of the parts. The collection of screws is given in the same
way. You may also assume an operationsort(l) that sorts a list of
part numbers according to item size and runs in nlog(n) time. The
range of part numbers is not known in advance. You also have
available a functioncomp(x,y) which tests a screw with part numberx
and a nut with part number y and returns 0 if the parts with
numbersx and y have the same size, -1 if the part x is smaller than
y and +1 otherwise. Note: the sort and comp functions do so based
on size, but you do not have access to the sizes directly (i.e. no
algorithm that you write can refer to the size of a given nut or
screw).
Register for solutions, replies, and use board search function. Answer Happy Forum is an archive of questions covering all technical subjects across the Internet.
Post Reply