ActiveState!

ActivePerl Documentation
Table of Contents

(Usage Statistics)
(about this ver)


* Getting Started
    * Welcome To ActivePerl
    * Release Notes
    * Readme
    * ActivePerl Change Log
* Install Notes
    * Linux
    * Solaris
    * Windows
* ActivePerl Components
    * Overview
    * PPM
    * Windows Specifics
       * OLE Browser
       * PerlScript
       * Perl for ISAPI
       * PerlEZ
* ActivePerl FAQ
    * Introduction
    * Availability & Install
    * Using PPM
    * Docs & Support
    * Windows Specifics
       * Perl for ISAPI
       * Windows 9X/NT/2000
       * Quirks
       * Web Server Config
       * Web programming
       * Programming
       * Modules & Samples
       * Embedding & Extending
       * Using OLE with Perl
* Windows Scripting
    * Active Server Pages
    * Windows Script Host
    * Windows Script Components

Core Perl Documentation


* perl
* perlfaq
* perltoc
* perlbook

* perlsyn
* perldata
* perlop
* perlreftut
* perldsc
* perllol

* perllexwarn
* perldebug

* perlrun
* perlfunc
* perlopentut
* perlvar
* perlsub
* perlmod
* perlpod

* perlstyle
* perlmodlib
* perlmodinstall
* perltrap
* perlport
* perlsec

* perlref
* perlre
* perlform
* perllocale
* perlunicode

* perlboot
* perltoot
* perltootc
* perlobj
* perlbot
* perltie

* perlipc
* perlnumber
* perlfork
* perlthrtut

* perldiag
* perlfaq1
* perlfaq2
* perlfaq3
* perlfaq4
* perlfaq5
* perlfaq6
* perlfaq7
* perlfaq8
* perlfaq9

* perlcompile

* perlembed
* perlxstut
* perlxs
* perlguts
* perlcall
* perlfilter
* perldbmfilter
* perlapi
* perlintern
* perlapio
* perltodo
* perlhack

* perlhist
* perldelta
* perl5005delta
* perl5004delta

* perlamiga
* perlcygwin
* perldos
* perlhpux
* perlmachten
* perlos2
* perlos390
* perlvms
* perlwin32

Pragmas


* attributes
* attrs
* autouse
* base
* blib
* bytes
* charnames
* constant
* diagnostics
* fields
* filetest
* integer
* less
* lib
* locale
* lwpcook
* open
* ops
* overload
* perllocal
* re
* sigtrap
* strict
* subs
* utf8
* vars
* warnings

Libraries


* ActivePerl
    * DocTools
        * TOC
            * RDF
* AnyDBM_File
* Archive
    * Tar
* AutoLoader
* AutoSplit
* B
    * Asmdata
    * Assembler
    * Bblock
    * Bytecode
    * C
    * CC
    * Debug
    * Deparse
    * Disassembler
    * Lint
    * Showlex
    * Stackobj
    * Terse
    * Xref
* Benchmark
* Bundle
    * LWP
* ByteLoader
* Carp
    * Heavy
* CGI
    * Apache
    * Carp
    * Cookie
    * Fast
    * Pretty
    * Push
    * Switch
* Class
    * Struct
* Compress
    * Zlib
* Config
* CPAN
    * FirstTime
    * Nox
* Cwd
* Data
    * Dumper
* DB
* Devel
    * DProf
    * Peek
    * SelfStubber
* Digest
    * HMAC
    * HMAC_MD5
    * HMAC_SHA1
    * MD2
    * MD5
    * SHA1
* DirHandle
* Dumpvalue
* DynaLoader
* English
* Env
* Errno
* Exporter
    * Heavy
* ExtUtils
    * Command
    * Embed
    * Install
    * Installed
    * Liblist
    * MakeMaker
    * Manifest
    * Miniperl
    * Mkbootstrap
    * Mksymlists
    * MM_Cygwin
    * MM_OS2
    * MM_Unix
    * MM_VMS
    * MM_Win32
    * Packlist
    * testlib
* Fatal
* Fcntl
* File
    * Basename
    * CheckTree
    * Compare
    * Copy
    * CounterFile
    * DosGlob
    * Find
    * Glob
    * Listing
    * Path
    * Spec
        * Functions
        * Mac
        * OS2
        * Unix
        * VMS
        * Win32
    * stat
* FileCache
* FileHandle
* FindBin
* Font
    * AFM
* Getopt
    * Long
    * Std
* HTML
    * AsSubs
    * Element
    * Entities
    * Filter
    * Form
    * FormatPS
    * Formatter
    * FormatText
    * HeadParser
    * LinkExtor
    * Parse
    * Parser
    * TokeParser
    * TreeBuilder
* HTTP
    * Cookies
    * Daemon
    * Date
    * Headers
        * Util
    * Message
    * Negotiate
    * Request
        * Common
    * Response
    * Status
* I18N
    * Collate
* IO
    * Dir
    * File
    * Handle
    * Pipe
    * Poll
    * Seekable
    * Select
    * Socket
        * INET
        * UNIX
* IPC
    * Msg
    * Open2
    * Open3
    * Semaphore
    * SysV
* LWP
    * Debug
    * MediaTypes
    * MemberMixin
    * Protocol
    * RobotUA
    * Simple
    * UserAgent
* Math
    * BigFloat
    * BigInt
    * Complex
    * Trig
* MD5
* MIME
    * Base64
    * QuotedPrint
* NDBM_File
* Net
    * Cmd
    * Config
    * Domain
    * DummyInetd
    * FTP
    * hostent
    * libnetFAQ
    * netent
    * Netrc
    * NNTP
    * PH
    * Ping
    * POP3
    * protoent
    * servent
    * SMTP
    * SNPP
    * Time
* O
* ODBM_File
* Opcode
* Pod
    * Checker
    * Find
    * Html
    * InputObjects
    * Man
    * Parser
    * ParseUtils
    * Plainer
    * Select
    * Text
        * Color
        * Termcap
    * Usage
* POSIX
* PPM
    * SOAPClient
    * SOAPServer
* Safe
* SDBM_File
* Search
    * Dict
* SelectSaver
* SelfLoader
* SHA
* Shell
* SOAP
    * Defs
    * Envelope
    * EnvelopeMaker
    * GenericHashSerializer
    * GenericInputStream
    * GenericScalarSerializer
    * Lite
    * OutputStream
    * Packager
    * Parser
    * Transport
        * HTTP
            * Apache
            * CGI
            * Client
            * Server
        * LOCAL
        * MAILTO
        * POP3
        * TCP
    * TypeMapper
* Socket
* Symbol
* Sys
    * Hostname
    * Syslog
* Term
    * ANSIColor
    * Cap
    * Complete
    * ReadLine
* Test
    * Harness
* Text
    * Abbrev
    * ParseWords
    * Soundex
    * Tabs
    * Wrap
* Thread
    * Queue
    * Semaphore
    * Signal
    * Specific
* Tie
    * Array
    * Handle
    * Hash
    * RefHash
    * Scalar
    * SubstrHash
* Time
    * gmtime
    * Local
    * localtime
    * tm
* UDDI
    * Lite
* UNIVERSAL
* URI
    * data
    * Escape
    * file
    * Heuristic
    * ldap
    * URL
    * WithBase
* User
    * grent
    * pwent
* Win32
    * AuthenticateUser
    * ChangeNotify
    * Clipboard
    * Console
    * Event
    * EventLog
    * File
    * FileSecurity
    * Internet
    * IPC
    * Mutex
    * NetAdmin
    * NetResource
    * ODBC
    * OLE
        * Const
        * Enum
        * NEWS
        * NLS
        * TPJ
        * Variant
    * PerfLib
    * Pipe
    * Process
    * Registry
    * Semaphore
    * Service
    * Sound
    * TieRegistry
* Win32API
    * File
    * Net
    * Registry
* WWW
    * RobotRules
        * AnyDBM_File
* XML
    * Element
    * Parser
        * Expat
    * PPD
    * PPMConfig
    * ValidatingElement
* XSLoader

 Graph::Kruskal - Kruskal's Algorithm for Minimal Spanning Trees in Graphs


NAME

Graph::Kruskal - Kruskal's Algorithm for Minimal Spanning Trees in Graphs

Computes the Minimal Spanning Tree of a given graph according to some cost function defined on the edges of the graph.


SUPPORTED PLATFORMS

  • Linux
  • Solaris
  • Windows
This module is not included with the standard ActivePerl distribution. It is available as a separate download using PPM.

SYNOPSIS

  • use Graph::Kruskal qw(define_vortices define_edges heapify makeheap heapsort find union kruskal example);

  • use Graph::Kruskal qw(:all);

  • &define_vortices(2,3,5,7,11,13,17,19,23,29,31);

    Define a list of vortices (integers > 0)

  • &define_edges( 2,13,3, 3,13,2, 5,13,1, 3,5,2, 3,29,21 );

    Define (non-directed) edges on the vortices previously defined (always in triplets: ``from'' vortice, ``to'' vortice and cost of that edge)

  • &heapify($i,$n);

    Main subroutine for sorting the edges according to their costs

  • &makeheap($n);

    Routine to initialize sorting of the edges

  • &heapsort($n);

    The famous heapsort algorithm (not needed for Kruskal's algorithm as a whole but included here for the sake of completeness) for sorting the edges according to their costs

  • &find($i);

  • &union($i,$j);

    Disjoint (!) sets are stored as trees in an array in this algorithm. Each element of some set (a cell in the array) contains a pointer to (the number of) another element, up to the root element that does not point anywhere, but contains the (negative) number of elements the set contains. The number of the root element is also used as an identifier for the set.

    Example:

                i  : |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
        -------------+-----+-----+-----+-----+-----+-----+-----+-----+
         parent[i] : | -4  | -3  |  1  |  2  |  1  | -1  |  3  |  4  |

    This array contains the three sets S1, S2 and S6:

                        1           2           6
                       / \          |
                      3   5         4
                     /              |
                    7               8

    ``find'' returns the number of the root element (= the identifier of the set) of the tree in which the given element is contained:

          find(a) := i  so that  a in Si

    It also reduces the height of that tree by changing all the pointers from the given element up to the root element to point DIRECTLY to the root element.

    Example:

        find(7) returns "1" and modifies the array as follows:
                i  : |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
        -------------+-----+-----+-----+-----+-----+-----+-----+-----+
         parent[i] : | -4  | -3  |  1  |  2  |  1  | -1  |  1  |  4  |
                        1           2           6
                       /|\          |
                      3 5 7         4
                                    |
                                    8

    ``union'' takes the identifiers of two sets (= the numbers of their respective root elements) and merges the two sets by appending one of the two trees to the other. It always appends the SMALLER set to the LARGER one (to keep the height of the resulting tree as small as possible) and updates the number of elements contained in the resulting set which is stored in the root element's cell of the array.

    Example:

        union(2,6) does the following:
                i  : |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
        -------------+-----+-----+-----+-----+-----+-----+-----+-----+
         parent[i] : | -4  | -4  |  1  |  2  |  1  |  2  |  1  |  4  |
                        1           2
                       /|\         / \
                      3 5 7       4   6
                                  |
                                  8
        complexity for O(n) "find" operations: O( G(n) n )
        complexity for one "union" operation: O(1)
        complexity for O(n) ( "find" + "union" ) operations: O( G(n) n )
        where  G(n) := min{ j | F(j) >= n }
        and    F(j) := 1            for j = 0
               F(j) := 2 ^ F(j-1)   for j > 0
        also,  G(n) <= ld n         for all n

  • &kruskal();

    This routine carries out the computations associated with Kruskal's algorithm.

    Returns an array of hashes (each hash containing the keys ``from'', ``to'' and ``cost'' and the corresponding values) representing the minimal spanning tree of the graph previously defined by calls to ``define_vortices'' and ``define_edges''.

    The result can also be found in @Graph::Kruskal::T.

    See the implementation of the subroutine ``example'' to see how to access this array directly (remember to fully qualify the name of this array in your program, i.e., use ``@Graph::Kruskal::T'' instead of just ``@T'', since this array is not exported - or your program will not work!)

  • &example();

    Demonstrates how to use the various subroutines in this module.

    Computes the minimal spanning tree of a sample graph.

    Just say ``use Graph::Kruskal qw(example);'' and ``&example();'' in a little Perl script to see it ``in action''.


DESCRIPTION

This algorithm computes the Minimal Spanning Tree of a given graph according to some cost function defined on the edges of that graph.

Input: A set of vortices which constitute a graph (some cities on a map, for example), a set of edges (i.e., roads) between the vortices of the (non-directed and connected) graph (i.e., the edges can be traveled in either direction, and a path must exist between any two vortices), and the cost of each edge (for instance, the geographical distance).

Output: A set of edges forming a spanning tree (i.e., a set of edges linking all vortices, so that a path exists between any two vortices) which is free of circles (because it's a tree) and which is minimal in terms of the cost function defined on the set of edges.

See Aho, Hopcroft, Ullman, ``The Design and Analysis of Computer Algorithms'' for more details on the algorithm.


SEE ALSO

Math::MatrixBool(3), Math::MatrixReal(3), DFA::Kleene(3), Set::IntegerRange(3), Set::IntegerFast(3), Bit::Vector(3).


VERSION

This man page documents ``Graph::Kruskal'' version 2.0.


AUTHOR

Steffen Beyer <sb@sdm.de>.


COPYRIGHT

Copyright (c) 1995, 1996, 1997 by Steffen Beyer. All rights reserved.


LICENSE

This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 Graph::Kruskal - Kruskal's Algorithm for Minimal Spanning Trees in Graphs