SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
Hi is there an error in my code because i cant seem to get the output. If this does work how does
the output is supposed to look like
import random
import time
import string
class TestDataGenerator:
def __init__(self):
pass
def generateData(self, size):
data = [""] * size
for i in range(size):
length = random.randint(1, 1000)
chars = string.ascii_uppercase + string.ascii_lowercase
string_val = ''.join(random.choice(chars) for _ in range(length))
data[i] = string_val
return data
from abc import ABC, abstractmethod
# abstract class to represent a set and its insert/search operations
class AbstractSet(ABC):
# constructor
@abstractmethod
def __init__(self):
pass
# inserts "element" in the set
# returns "True" after successful insertion, "False" if the element is already in the set
# element : str
# inserted : bool
@abstractmethod
def insertElement(self, element):
inserted = False
return inserted
# checks whether "element" is in the set
# returns "True" if it is, "False" otherwise
# element : str
# found : bool
@abstractmethod
def searchElement(self, element):
found = False
return found
# abstract class to represent a synthetic data generator
class AbstractTestDataGenerator(ABC):
# constructor
@abstractmethod
def __init__(self):
pass
# creates and returns a list of length "size" of strings
# size : int
# data : list
@abstractmethod
def generateData(self, size):
data = [""]*size
return data
import sys
sys.setrecursionlimit(10000)
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
self.color = "BLACK"
import timeit
import string
import random
import sys
sys.setrecursionlimit(10000)
class Node:
def __init__(self, value):
self.value = value
self.left = None
self.right = None
self.color = "BLACK"
class BalancedSearchTreeSet(AbstractSet):
def __init__(self):
self.root = None
def rotateLeft(self, n):
x = n.right
n.right = x.left
x.left = n
x.color = n.color
n.color = "RED"
return x
def rotateRight(self, n):
x = n.left
n.left = x.right
x.right = n
x.color = n.color
n.color = "RED"
return x
def flipColor(self, n):
n.color = "RED"
n.left.color = "BLACK"
n.right.color = "BLACK"
def isRed(self, node):
if node is None:
return False
return node.color == "RED"
def insertElement(self, value):
self.root = self._insert(self.root, value)
self.root.color = "BLACK"
def _insert(self, node, value):
if node is None:
return Node(value)
if value < node.value:
node.left = self._insert(node.left, value)
else:
node.right = self._insert(node.right, value)
if self.isRed(node.right) and not self.isRed(node.left):
node = self.rotateLeft(node)
if self.isRed(node.left) and self.isRed(node.left.left):
node = self.rotateRight(node)
if self.isRed(node.left) and self.isRed(node.right):
self.flipColor(node)
return node
def searchElement(self, value):
return self._search(self.root, value)
def _search(self, node, value):
if node is None:
return None
if node.value.lower() == value.lower():
return node
if value.lower() < node.value.lower():
return self._search(node.left, value)
else:
return self._search(node.right, value)
bst_set = BalancedSearchTreeSet()
data_generator = TestDataGenerator()
# Test parameters
data_sizes = [100, 1000, 10000]
num_runs = 5
# Test with varying data sizes and distributions
for size in data_sizes:
print(f"Data size: {size}")
data = data_generator.generateData(size)
sorted_data = sorted(data)
reversed_data = list(reversed(sorted_data))
datasets = {"Random": data, "Sorted": sorted_data, "Reversed": reversed_data}
for dist, dataset in datasets.items():
print(f" Data distribution: {dist}")
# insertion time
insert_time = timeit.timeit(
lambda: [bst_set.insertElement(x) for x in dataset], number=num_runs
) / num_runs
# search time
search_time = timeit.timeit(
lambda: [x in bst_set for x in dataset], number=num_runs
) / num_runs
# Print the results
print(f" Insertion time: {insert_time:.6f} seconds")
print(f" Search time: {search_time:.6f} seconds")
print()
# Edge cases
edge_cases = [
("Empty set search", []),
("Duplicate insertion", data),
("Nonexistent element search", ["nonexistent_element"]),
]
for test_name, edge_data in edge_cases:
print(f"Edge case: {test_name}")

Contenu connexe

Similaire à Hi is there an error in my code because i cant seem to get the outpu.pdf

# Imports# Include your imports here, if any are used. import.pdf
 # Imports# Include your imports here, if any are used. import.pdf # Imports# Include your imports here, if any are used. import.pdf
# Imports# Include your imports here, if any are used. import.pdfgulshan16175gs
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical filePranav Ghildiyal
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionIban Martinez
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfrajatxyz
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfkeerthu0442
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdfarihantelehyb
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfvishalateen
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdfaathmaproducts
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdfaathiauto
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdfrushabhshah600
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with GroovyArturo Herrero
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx16115yogendraSingh
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 

Similaire à Hi is there an error in my code because i cant seem to get the outpu.pdf (20)

# Imports# Include your imports here, if any are used. import.pdf
 # Imports# Include your imports here, if any are used. import.pdf # Imports# Include your imports here, if any are used. import.pdf
# Imports# Include your imports here, if any are used. import.pdf
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
 
Javascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introductionJavascript & jQuery: A pragmatic introduction
Javascript & jQuery: A pragmatic introduction
 
python practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdfpython practicals-solution-2019-20-class-xii.pdf
python practicals-solution-2019-20-class-xii.pdf
 
Practicle 1.docx
Practicle 1.docxPracticle 1.docx
Practicle 1.docx
 
python_lab_manual_final (1).pdf
python_lab_manual_final (1).pdfpython_lab_manual_final (1).pdf
python_lab_manual_final (1).pdf
 
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
(Parent reference for BST) Redefine TreeNode by adding a reference to.pdf
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdfInspect the class declaration for a doubly-linked list node in Node-h-.pdf
Inspect the class declaration for a doubly-linked list node in Node-h-.pdf
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Need to be done in C Please Sorted number list implementation with.pdf
Need to be done in C  Please   Sorted number list implementation with.pdfNeed to be done in C  Please   Sorted number list implementation with.pdf
Need to be done in C Please Sorted number list implementation with.pdf
 
Need to be done in C++ Please Sorted number list implementation wit.pdf
Need to be done in C++  Please   Sorted number list implementation wit.pdfNeed to be done in C++  Please   Sorted number list implementation wit.pdf
Need to be done in C++ Please Sorted number list implementation wit.pdf
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
1sequences and sampling. Suppose we went to sample the x-axis from X.pdf
 
Functional Programming with Groovy
Functional Programming with GroovyFunctional Programming with Groovy
Functional Programming with Groovy
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
SDC - Einführung in Scala
SDC - Einführung in ScalaSDC - Einführung in Scala
SDC - Einführung in Scala
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 

Plus de aggarwalshoppe14

I am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdfI am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdfaggarwalshoppe14
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfaggarwalshoppe14
 
I receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdfI receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdfaggarwalshoppe14
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfaggarwalshoppe14
 
I need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdfI need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdfaggarwalshoppe14
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfaggarwalshoppe14
 
I need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdfI need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdfaggarwalshoppe14
 
His Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdfHis Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdfaggarwalshoppe14
 
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdfHIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdfaggarwalshoppe14
 
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdfHile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdfaggarwalshoppe14
 
Hi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdfHi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdfaggarwalshoppe14
 
Hi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdfHi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdfaggarwalshoppe14
 
HHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdfHHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdfaggarwalshoppe14
 
Hello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdfHello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdfaggarwalshoppe14
 
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdfHealth Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdfaggarwalshoppe14
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfaggarwalshoppe14
 
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdfHere is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdfaggarwalshoppe14
 
Here are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdfHere are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdfaggarwalshoppe14
 
help write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdfhelp write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdfaggarwalshoppe14
 
I need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdfI need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdfaggarwalshoppe14
 

Plus de aggarwalshoppe14 (20)

I am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdfI am sure you have heard the adage �my word is my bond�. We do not k.pdf
I am sure you have heard the adage �my word is my bond�. We do not k.pdf
 
I really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdfI really need some help if I have this right so far. Please Resub.pdf
I really need some help if I have this right so far. Please Resub.pdf
 
I receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdfI receive this answer for one of my questions, I need the reference .pdf
I receive this answer for one of my questions, I need the reference .pdf
 
I really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdfI really need some help if I have this right so far. PLEASE CHANG.pdf
I really need some help if I have this right so far. PLEASE CHANG.pdf
 
I need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdfI need this code, to show ALL inventory items, then with the remove .pdf
I need this code, to show ALL inventory items, then with the remove .pdf
 
I need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdfI need help with the last 2 methods only in Huffman.java file the me.pdf
I need help with the last 2 methods only in Huffman.java file the me.pdf
 
I need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdfI need help creating this flutter applicationPlease provide a com.pdf
I need help creating this flutter applicationPlease provide a com.pdf
 
His Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdfHis Majesty�s Government report that 20 of officials arrive late fo.pdf
His Majesty�s Government report that 20 of officials arrive late fo.pdf
 
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdfHIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
HIVin RNA genomu, bir RNA ablonundan bir DNA genomunu sentezlemek i.pdf
 
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdfHile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
Hile ��geni bileenlerini a�klar. Tannm bir kriminolog olan Donald .pdf
 
Hi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdfHi, I need help with this Probability question. Please show work and.pdf
Hi, I need help with this Probability question. Please show work and.pdf
 
Hi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdfHi could I get the java code for all the tasks pls, many thanks!.pdf
Hi could I get the java code for all the tasks pls, many thanks!.pdf
 
HHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdfHHI analysis indicates that many states have a highly concentrated i.pdf
HHI analysis indicates that many states have a highly concentrated i.pdf
 
Hello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdfHello I need help configuring the regression equation for this scatt.pdf
Hello I need help configuring the regression equation for this scatt.pdf
 
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdfHealth Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
Health Economics with Taxation and Agrarian ReformActivity 2 Grap.pdf
 
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdfHere is app.js, artist.js and songs.js file. Can you look at the my .pdf
Here is app.js, artist.js and songs.js file. Can you look at the my .pdf
 
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdfHere is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
Here is a short amino acid sequence mapped as polar (P) and nonpolar.pdf
 
Here are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdfHere are the instructions and then the code in a sec. Please R.pdf
Here are the instructions and then the code in a sec. Please R.pdf
 
help write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdfhelp write program Project Desoription The purpose of thi project i.pdf
help write program Project Desoription The purpose of thi project i.pdf
 
I need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdfI need a case analysis using Harvards Business School format please.pdf
I need a case analysis using Harvards Business School format please.pdf
 

Dernier

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 

Dernier (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 

Hi is there an error in my code because i cant seem to get the outpu.pdf

  • 1. Hi is there an error in my code because i cant seem to get the output. If this does work how does the output is supposed to look like import random import time import string class TestDataGenerator: def __init__(self): pass def generateData(self, size): data = [""] * size for i in range(size): length = random.randint(1, 1000) chars = string.ascii_uppercase + string.ascii_lowercase string_val = ''.join(random.choice(chars) for _ in range(length)) data[i] = string_val return data from abc import ABC, abstractmethod # abstract class to represent a set and its insert/search operations class AbstractSet(ABC): # constructor @abstractmethod def __init__(self): pass # inserts "element" in the set # returns "True" after successful insertion, "False" if the element is already in the set # element : str # inserted : bool @abstractmethod def insertElement(self, element): inserted = False return inserted
  • 2. # checks whether "element" is in the set # returns "True" if it is, "False" otherwise # element : str # found : bool @abstractmethod def searchElement(self, element): found = False return found # abstract class to represent a synthetic data generator class AbstractTestDataGenerator(ABC): # constructor @abstractmethod def __init__(self): pass # creates and returns a list of length "size" of strings # size : int # data : list @abstractmethod def generateData(self, size): data = [""]*size return data import sys sys.setrecursionlimit(10000) class Node: def __init__(self, value): self.value = value self.left = None self.right = None self.color = "BLACK" import timeit import string
  • 3. import random import sys sys.setrecursionlimit(10000) class Node: def __init__(self, value): self.value = value self.left = None self.right = None self.color = "BLACK" class BalancedSearchTreeSet(AbstractSet): def __init__(self): self.root = None def rotateLeft(self, n): x = n.right n.right = x.left x.left = n x.color = n.color n.color = "RED" return x def rotateRight(self, n): x = n.left n.left = x.right x.right = n x.color = n.color n.color = "RED" return x def flipColor(self, n): n.color = "RED" n.left.color = "BLACK" n.right.color = "BLACK" def isRed(self, node): if node is None: return False return node.color == "RED" def insertElement(self, value): self.root = self._insert(self.root, value)
  • 4. self.root.color = "BLACK" def _insert(self, node, value): if node is None: return Node(value) if value < node.value: node.left = self._insert(node.left, value) else: node.right = self._insert(node.right, value) if self.isRed(node.right) and not self.isRed(node.left): node = self.rotateLeft(node) if self.isRed(node.left) and self.isRed(node.left.left): node = self.rotateRight(node) if self.isRed(node.left) and self.isRed(node.right): self.flipColor(node) return node def searchElement(self, value): return self._search(self.root, value) def _search(self, node, value): if node is None: return None if node.value.lower() == value.lower(): return node if value.lower() < node.value.lower(): return self._search(node.left, value) else: return self._search(node.right, value) bst_set = BalancedSearchTreeSet() data_generator = TestDataGenerator() # Test parameters data_sizes = [100, 1000, 10000] num_runs = 5 # Test with varying data sizes and distributions for size in data_sizes: print(f"Data size: {size}")
  • 5. data = data_generator.generateData(size) sorted_data = sorted(data) reversed_data = list(reversed(sorted_data)) datasets = {"Random": data, "Sorted": sorted_data, "Reversed": reversed_data} for dist, dataset in datasets.items(): print(f" Data distribution: {dist}") # insertion time insert_time = timeit.timeit( lambda: [bst_set.insertElement(x) for x in dataset], number=num_runs ) / num_runs # search time search_time = timeit.timeit( lambda: [x in bst_set for x in dataset], number=num_runs ) / num_runs # Print the results print(f" Insertion time: {insert_time:.6f} seconds") print(f" Search time: {search_time:.6f} seconds") print() # Edge cases edge_cases = [ ("Empty set search", []), ("Duplicate insertion", data), ("Nonexistent element search", ["nonexistent_element"]), ] for test_name, edge_data in edge_cases: print(f"Edge case: {test_name}")