Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I need immediate help with the following C++ assignment. The objective is to write a definatition of function PRIM2, a new version of PRIM's

Hello, I need immediate help with the following C++ assignment. The objective is to write a definatition of function PRIM2, a new version of PRIM's algorithm requirements and specifications are listed below, as well as a copy of class msTreeType: ThankYou in advance... Text book C++ Programming Program Design Including Data Structures. 7th Edition D.S. Malik Chapter 20 Graphs Programing exercise #5 The algorithm to determine the minimal spanning tree given in this chapter is of the order O(n3). The following is an alternative to Prims algorithm that is of order O(n2). Write a definition of the new function (Prim2) to implement this algorithm, and add this function to the class msTreeType. Furthermore, write a program to test this new Prims algorithm. Input: A connected weighted graph G = (V, E) of N vertices, numbered 0, 1, 2,,,, n-1; starting with vertex s, with a weight matrix of W. Output: The minimal spanning tree. Prim2 (G, W, n, s) Let T = (V, E), where E = 0 for ( j = 0; j < n; j ++) to n { edgeWeights [ j ] = W(s, j); edges [ j ] = s; visited [ s ] = false; } edgeWeights [ s ] = 0; visited [ s ] = true while (not all nodes are visited) { Choose the node that is not visited and has the smallest weight, and call it k. visited [ k ] = true; E = E U { ( k, edges [ k ] ) } V = V U { k } for each node j that is not visited if (W ( k, j ) < edgeWeights [ j ]) { edgeWeights [ j ] = W ( k, j ); edges[ j ] = k; } return T;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

13-6 How will MIS help my career?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago