-
-
- A
self-organizing
data structure is a data structure that has somerule(s)
oralgorithm
attached to theaccess
method for eachnode
in the data structure. - These rule(s) or algorithms
result in changing
the structure or order of the data structure in an attempt tospeed up
the problem ofsearching
for data in the data structure[AW05]
. - The access method is a function or function that searches for the data in the data structure and
returns
the data. - The main goal of a self-organizing data structure is to
move away
from alookup time
ofO(n)
and towards an instant lookup time ofO(1)
. Examples of self-organizing data structures areself-organizing lists
,binary trees
andm-way trees
.
- A
-
- A treap is a variation of a
randomized
search tree algorithm. Treaps differ from standard binary search trees in the following ways:-
- Nodes in a standard binary search tree
only
has a data member which stores thedata
of the node. - This differs from treaps in the sense that nodes has an
additional
member which is thepriority
of the node.
- Nodes in a standard binary search tree
-
- Standard Binary Search trees only maintain the
property
that data that issmaller
than the current node's data is part of theleft
subtree
of the node and data that isgreater
than the current node's data are part of theright
subtree
of the node. - With treaps, an additional property is introduced. The
max heap property
. This property states that the data of node n isgreater or equal
to either of itschildren
[ASSS86]
. - Treaps combine the idea of
Heaps
(where the aforementioned property originated from) andBinary SearchTrees
. Thus Treaps maintain themax heap
property of heaps as well as theefficient search
property ofBinary Search Trees
. - The max heap property is applied to the
priority
of each treap node and the binary search is applied to thedata
of each treap node.
- Standard Binary Search trees only maintain the
-
- Treaps
assign
priorities randomly
to each node which originates from therandomized
search tree algorithm. This allows for theaverage
case of the treap to beperfectly balanced
[SA96]
. - The
standard
implementation of a treap is to use anarray
but for this implementation I will be implementing the treap as atree
.
- A treap is a variation of a
-
- This implementation will also put a
twist
on the standard treap in the sense that we add the idea ofself-organizing
data structures on top of the treap. - Thus with each
access
of a node, thepriority
of the node willincrease
and arotation
may be required tomaintain
the max heap property.
- This implementation will also put a
-
- A database is usually a
collection
ofrows
that are somehowrelated
to each other. - It is possible to have
unstructured
databases(e.g. NoSQL)
databases but for this implementation, I will be implementing a structured database. -
- A structured database refers to a database that has a
strict
structure thatcannot
be changed or will result inpossibly undefined behavior
. - A database's structure is described by a
set of properties
the data has which will be calledcolumns
. Rows in the database are agrouping
of data that has all the properties and that are closely related to each other. - Thus each row's properties are somehow closely related to each other. Usually, databases have
multiple
tables tomodel
thereal world
more accurately. - Due to
complexity
, this implementation will only be implementing asingle-tabled
database. Databases usually have the following set of operationsInsert
Update
Delete
Search
- And I will also implement these operations.
- A structured database refers to a database that has a
- A database is usually a
-
- Searching is one of the most important features of a database. A
naive
approach is tolinearly search
through the database for arecord
or possiblymultiple records
. - But this implementation will try to
optimize
this naive approach. - In databases especially relational databases is to
index
columns that are used to search through often. - Indexing implies
building
anexternal
data structure
that will increase theefficiency
of thesearching
algorithm when searching for data. Usually, this is accomplished by using aB+
orB*
tree. - This implementation will attempt to use a different data structure:
Self Organizing Treaps
. This will hopefully increase the efficiency of the searching algorithm over the linear searching algorithm
- Searching is one of the most important features of a database. A
-
-
- Relational Databases
- Treap
- Indexing
- Self-Organizing Data Structures
- Exceptions
- [ASSS86] Michael D Atkinson, J-R Sack, Nicola Santoro, and Thomas Strothotte. Min-max heaps and generalized priority queues.
Communications of the ACM
, 29(10):996–1000, 1986. - [AW05] Susanne Albers and Jeffery Westbrook. Self-organizing data structures. Online Algorithms:
The state of the art
, pages 13–51, 2005. - [SA96] Raimund Seidel and Cecilia R Aragon.
Randomized search trees
. Algorithmica, 16(4-5):464–497, 1996
-
-
-
-
Database(["ID","Computer Scientist Name","Research Area","Year of First Publication"], 15)
-
-
-
CREATE DATABASE IF NOT EXISTS computer_scientists; USE computer_scientists; CREATE TABLE IF NOT EXISTS computer_scientists ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(255) NOT NULL, research_area VARCHAR(255) NOT NULL, year_first_publication INT NOT NULL );
-
-
-
-
-
insert(["16","Edmund Clarke","Model Checking","1982"])
-
-
-
INSERT INTO computer_scientists (id, name, research_area, year_first_publication) VALUES (16, 'Edmund␣Clarke', 'Model␣Checking', 1982);
-
-
-
-
-
removeFirstWhere("research area", "Algorithms")
-
-
-
DELETE FROM computer_scientists WHERE research_area = 'Algorithms' LIMIT 1;
-
-
-
-
-
removeAllWhere("research area","Algorithms")
-
-
-
DELETE FROM computer_scientists WHERE research_area = ’Algorithms ’;
-
-
-
-
-
findFirstWhere("year first publication", "1962")
-
-
-
SELECT * FROM computer_scientists WHERE year_first_publication = 1962 LIMIT 1;
-
-
-
-
-
findAllWhere("year first publication", "1962")
-
-
-
SELECT * FROM computer_scientists WHERE year_first_publication = 1962;
-
-
-
-
-
updateFirstWhere("research area","Artificial Intelligence", "AI")
-
-
-
UPDATE computer_scientists SET research_area = 'AI' WHERE research_area= 'Artificial␣Intelligence' LIMIT 1;
-
-
-
-
-
updateAllWhere("research area","Artificial Intelligence", "AI")
-
-
-
UPDATE computer_scientists SET research_area = 'AI' WHERE research_area= 'Artificial␣Intelligence';
-
-
-
-
-
generateIndexOn("research area")
-
-
-
CREATE INDEX idx_research_area ON computer_scientists (research_area);
-
-
-
-
-
generateIndexAll()
-
-
-
CREATE INDEX idx_id ON computer_scientists (id); CREATE INDEX idx_name ON computer_scientists (name); CREATE INDEX idx_research_area ON computer_scientists (research_area); CREATE INDEX idx_year_first_publication ON computer_scientists(year_first_publication);
-
-
-
-
-
countOccurrences("year first publication", "1962")
-
-
-
SELECT COUNT(*) FROM computer_scientists WHERE year_first_publication=1962;
-
-
- Install an IDE that compiles and runs Java codes. Recommendation
VS Code
- link: How to setup
WSL Ubuntu
terminal shell and run it from Visual Studio Code - link: How to Install Java
JDK 17
onWindows 11
-
- Run WSL as Administrator
- set -ex
- NB: Update links for other JDK Versions
- export JDK_URL=http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.tar.gz
- export UNLIMITED_STRENGTH_URL=http://download.oracle.com/otn-pub/java/jce/8/jce_policy-8.zip
- wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" ${JDK_URL}
- Extract the archive: tar -xzvf jdk-*.tar.gz
- Clean up the tar: rm -fr jdk-*.tar.gz
- Make the jvm dir: sudo mkdir -p /usr/lib/jvm
- Move the server jre: sudo mv jdk1.8* /usr/lib/jvm/oracle_jdk8
- Install unlimited strength policy: wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" ${UNLIMITED_STRENGTH_URL}
- unzip jce_policy-8.zip
- mv UnlimitedJCEPolicyJDK8/local_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/
- mv UnlimitedJCEPolicyJDK8/US_export_policy.jar /usr/lib/jvm/oracle_jdk8/jre/lib/security/
- sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/oracle_jdk8/jre/bin/java 2000
- sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/oracle_jdk8/bin/javac 2000
- sudo echo "export J2SDKDIR=/usr/lib/jvm/oracle_jdk8 export J2REDIR=/usr/lib/jvm/oracle_jdk8/jre export PATH=$PATH:/usr/lib/jvm/oracle_jdk8/bin:/usr/lib/jvm/oracle_jdk8/db/bin:/usr/lib/jvm/oracle_jdk8/jre/bin export JAVA_HOME=/usr/lib/jvm/oracle_jdk8 export DERBY_HOME=/usr/lib/jvm/oracle_jdk8/db" | sudo tee -a /etc/profile.d/oraclejdk.sh
NB: A makefile Is Included to compile and run the codes on the terminal with the following commands:=
- make clean
- make
- make run
default:
javac *.java
run:
java Main
clean:
rm -f *.class
reset
clear
tar:
tar -cvz *.java makefile -f BINARY_TREE_VARIATIONS.tar.gz
unZip_unTar:
tar -zxvf BINARY_TREE_VARIATIONS.tar.gz