Help top algorith optimization

Hi.

Actually I am looking for help to optimize my dependencies calculation algorithm.

I will give you a light implementation of my actual functions ( I removed errors controls and messages)

def getRequiredDependencies(software : ISM::SoftwareInformation) : Array(ISM::SoftwareDependency)
            dependencies = Hash(String,ISM::SoftwareDependency).new
            currentDependencies = [software.toSoftwareDependency]
            nextDependencies = Array(ISM::SoftwareDependency).new

            dependenciesTree = [[software.toSoftwareDependency]]

            loop do

                currentLevelDependenciesTree = Array(ISM::SoftwareDependency).new

                if currentDependencies.empty?
                    break
                end

                currentDependencies.each do |dependency|

                    dependencyInformation = dependency.information

                    #Software not available
                    if dependencyInformation.name == ""
                        #exitProgram
                    end

                    #Version not available
                    if dependencyInformation.version == ""
                        #exitProgram
                    end

                    #Need multiple version or need to fusion options
                    if dependencies.has_key?(dependency.hiddenName)

                        #Multiple versions of single software requested
                        if dependencies[dependency.hiddenName].version != dependency.version
                            dependencies[dependency.versionName] = dependency
                            nextDependencies += dependency.dependencies
                        end
                    else
                        dependencies[dependency.hiddenName] = dependency
                        nextDependencies += dependency.dependencies
                    end

                    currentLevelDependenciesTree = currentLevelDependenciesTree+dependency.dependencies

                end

                #Inextricable dependencies problem
                dependenciesTree.each do |branch|

                    if branch.size == currentLevelDependenciesTree.size && branch & currentLevelDependenciesTree == branch
                        #exitProgram
                    end
                end

                dependenciesTree.push(currentLevelDependenciesTree.uniq)

                currentDependencies = nextDependencies.dup
                nextDependencies.clear

            end

            return dependencies.values
        end

        def getDependenciesTable(softwareList : Array(ISM::SoftwareInformation)) : Hash(String,Array(ISM::SoftwareDependency))
            dependenciesTable = Hash(String,Array(ISM::SoftwareDependency)).new

            softwareList.each do |software|

                key = software.toSoftwareDependency.hiddenName

                dependenciesTable[key] = getRequiredDependencies(software)

                dependenciesTable[key].each do |dependency|

                    dependencyInformation = dependency.information

                    if !softwareIsInstalled(dependencyInformation)
                        dependenciesTable[dependency.hiddenName] = getRequiredDependencies(dependencyInformation)
                    end

                end

            end

            return dependenciesTable
        end