473,785 Members | 2,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Minimum spanning tree problem??

3 New Member
i have a problem i am very new to c++ and want to construct a minimum spanning tree for 8 stocks i have calculated in excel the relevant formulas and know the weights of each of gthe vertices but don't know how to construct it i have read numerous books and have managed to get a pseudo code for how it should be which is

Algorithm spanningTree (graph)
Determine the minimum spanning tree a network.
Pre graph contains a network
Post spanning tree determined
1 if (empty graph)
1 return
2 end if
3 loop (through all vertices)
Set inTree flags false.
1 set vertex inTree flag to false
2 loop (through all edges)
1 set edge inTree flag to false
2 get next edge
3 end loop
4 get next vertex
4 end loop
Now derive spanning tree
5 set first vertex to in tree
6 set treeComplete to false
7 loop (not treeComplete)
1 set treeComplete to true
2 set minEdge to maximum integer
3 set minEdgeLoc to null
4 loop (through all vertices)
Walk through graph checking vertices in tree.
1 if (vertex in tree AND vertex outDegree > 0)
1 loop (through all edges)
1 if (destination not in tree)
set destination inTree flag to false)
1 set treeComplete to false
2 if (edge weight < minEdge)
1. set minEdge to edge weight
2 set minEdgeLoc to edge
3 end if
2 end if
3 get next edge
2 end loop
2 end if
3 get next vertex
5 end loop
6 if (minEdgeLoc not null)
Found edge to insert into tree.
1. set minEdgeLoc inTree flag to true
2 set destination inTree flag to true
7 end if
8 end loop
end SpanningTree



the structure should be
graphHead
count
first
end graphHead

graphVertex
nextVertex
data
inDegree
outDegree
inTree
firstEdge
end graphVertex

graphEdge
destination
weight
nextEdge
inTree
end graphEdge

if any one can please give me examples in the psedo code or point out what to input and where then that wud be really helpful as i am so distressed xxx
Mar 25 '07 #1
1 2647
sicarie
4,677 Recognized Expert Moderator Specialist
It looks like you have pseudo code there for something, but I'm not sure I understand your problem. What is in the Excel sheet, and how does that relate to the spanning tree algorithm?
Mar 26 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6740
by: _mario.lat | last post by:
kruskal:minimum spanning tree. how to do? I'd like to find the minimum spanning tree with kruskal algorithm. There is a code (in C++) written? which contenitor do you suggest (Vector, set, ...)? How can I do? Thank you in advance, Mario.
7
1996
by: sugaray | last post by:
the binary search tree node here contains another structure as it's data field, programs did successfully work when data field is int, char, this time i got stucked, don't know why ? if there's something to do with dynamic data object ? thanx for your help. ================== begin of code ============================== #include <stdio.h> #include <stdlib.h>
5
1992
by: Mike | last post by:
Why does this code insert a node into a binary search tree correctly? If I only inserting going by first digit it works properly but when I try inserting going by the whole ip and the port number the inserts are totally out of order. where IPAddress is four ints Node is an IPAddress, portNumber, left pointer and right pointer Nodeptr is a pointer to a Node
2
1792
by: pyguy | last post by:
Hi all, I am running into a conceptual glitch in implementing a simple binary tree class. My insertion and printing (sorting) seems to be ok, but when I search the tree, my find method isn't doing what I thought it should. Here is the output of running my tests: >python -i trees.py ********************************************************************** File "trees.py", line 70, in __main__.BinaryTree.find Failed example:
2
2687
by: tonokio | last post by:
I wasn't sure if this was the best place to post since there isn't really an algorithm section for programming. I was curious that if you're given a MST tree of G and P is the shortest path between two nodes s and t. If we increaset the cost of each edge of G by some amount x, would P still be the shortest path between s and t, because all the values are incremented by x amount or would it change?
2
1661
by: zahit | last post by:
Hi guys, below there is a c code which caluclates given data repetition in a binary tree. typedef struct node *tree_pointer; typedef struct node{ char data; tree pointer left_child, right_child; } int repetition(tree_pointer L, char x){
3
2458
by: FARAECHILIBRU | last post by:
i'm building a binary tree the problem is when i'm reading from e text file .First i'm sending to tree builder function a empty node and e new node the function return me firt node of a tree, but when i try to built the secund node ,i dont anderstend whay, my program write to my new node and to first tree node; string readLine(istream& fin) { char buff; // Clear any remaining end of line characters if(fin.peek()=='\n') {...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9949
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8971
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.