Пример #1
0
def uppgift4():
    wordList = open('word3u.txt', 'rt', encoding='utf8').read().split();
    wordListEngInput = open('englishu.txt', 'rt', encoding='utf8').read().split();
    tree = Bintree();
    treeEng = Bintree();
    for word in wordList:
        tree.put(word);
    for word in wordListEngInput:
        word = word.strip('".!?, ').lower();
        if (tree.exists(word) and treeEng.put(word)):
            print(word);


        
        
            
Пример #2
0
from Bintree import Bintree

tree = Bintree()

f = open("word3.txt", "r")
lines = f.readlines()

for line in lines:
    line = line.rstrip("\n")
    if tree.exists(line):
        print(line)
    else:
        tree.put(line)

#tree.write()
Пример #3
0
from Bintree import Bintree

tree = Bintree()

f = open("word3.txt","r")
lines = f.readlines()

for line in lines:
	line = line.rstrip("\n")
	if tree.exists(line):
		print(line)
	else:
		tree.put(line)

#tree.write()
Пример #4
0
from Bintree import Bintree

sweTree = Bintree()
engTree = Bintree()

#Read the swedish words
sweFile = open("word3.txt", "r")
sweLines = sweFile.readlines()

#Insert them into a BST
for line in sweLines:
    line = line.rstrip("\n")
    if sweTree.exists(line):
        print(line)
    else:
        sweTree.put(line)

#Read english words
engFile = open("engelska.txt", "r")
engLines = engFile.readlines()

for line in engLines:
    line = line.rstrip("\n")
    line = line.split(" ")
    for word in line:
        if word == "":  #That's not much of a word is it?
            pass
        else:
            if engTree.exists(word):  #It's allready been inserted
                pass
            else:
Пример #5
0
from Bintree import Bintree

sweTree = Bintree()
engTree = Bintree()

#Read the swedish words
sweFile = open("word3.txt","r")
sweLines = sweFile.readlines()

#Insert them into a BST
for line in sweLines:
	line = line.rstrip("\n")
	if sweTree.exists(line):
		print(line)
	else:
		sweTree.put(line)

#Read english words
engFile = open("engelska.txt","r")
engLines = engFile.readlines()

for line in engLines:
	line = line.rstrip("\n")
	line = line.split(" ")
	for word in line:
		if word == "": 					#That's not much of a word is it?
			pass
		else:
			if engTree.exists(word): 	#It's allready been inserted
				pass
			else:
Пример #6
0
from Bintree import Bintree

wordTree = Bintree()
reversedTree = Bintree() #BST for printed reversed words.

f = open("word3.txt","r")
lines = f.readlines()


for line in lines:
	line = line.rstrip("\n")
	if not wordTree.exists(line):
		wordTree.put(line)
print("This app find words that are the same when reversed!")
input("Press enter to continue:")

for line in lines:
	line = line.rstrip("\n")
	reversedLine = line[::-1] 				#Reverses the string
	if not line == reversedLine: 			#Gets rid of symmetric words
		if not reversedTree.exists(line): 	#Storage of allready shown reversed words. Do this before other search since it's quicker.
			if wordTree.exists(reversedLine): 
				print(line)
				print(line[::-1])
				print()
				reversedTree.put(line)
Пример #7
0
    input("Please enter how many total entries there should be : "))

numberArray = [x for x in range(totalEntries)]
random.shuffle(numberArray)  #Randomizes the array.

for number in numberArray:  #Puts all the numbers into the binary-tree
    tree.put(number)

numberToFind = int(random.random() * totalEntries //
                   1)  #Make up a random number in the right interval.

print("\nLooking for number " + str(numberToFind) +
      " in shuffled intervall 0 - " + str(totalEntries) + "\n")

startTime = time.clock()
tree.exists(numberToFind)  #BST-SEARCH PROCESS
treeStop = time.clock()  #Time until BinarySearch was completed.

linStop = None  #Allocate memory

for number in numberArray:  #LINEAR-SEARCH PROCESS
    if number == numberToFind:
        linStop = time.clock(
        )  #If this goes through the number is found. Stop time.
        break

#Actual time consumed calculated below
treeTime = treeStop - startTime
linTime = linStop - treeStop

ratio = linTime / treeTime
Пример #8
0
print("This program compares search-time between linear search and BST-search")
totalEntries = int(input("Please enter how many total entries there should be : "))

numberArray = [x for x in range(totalEntries)] 
random.shuffle(numberArray) 				#Randomizes the array.

for number in numberArray: 				#Puts all the numbers into the binary-tree
	tree.put(number)

numberToFind = int(random.random() * totalEntries // 1) #Make up a random number in the right interval.

print("\nLooking for number " + str(numberToFind)+" in shuffled intervall 0 - " + str(totalEntries) + "\n")

startTime = time.clock()
tree.exists(numberToFind) #BST-SEARCH PROCESS
treeStop = time.clock() #Time until BinarySearch was completed.

linStop = None #Allocate memory

for number in numberArray: #LINEAR-SEARCH PROCESS
	if number == numberToFind:
		linStop = time.clock() #If this goes through the number is found. Stop time.
		break

#Actual time consumed calculated below
treeTime = treeStop - startTime
linTime = linStop - treeStop

ratio = linTime/treeTime