Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
J
javascript-fundamentals
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christopher Cottier
javascript-fundamentals
Commits
06dcfc7e
Commit
06dcfc7e
authored
4 years ago
by
ccottier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
array to binary search tree algo added
parent
1503bcb8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
myscript.js
myscript.js
+30
-0
No files found.
myscript.js
View file @
06dcfc7e
...
@@ -160,6 +160,36 @@ document.addEventListener("DOMContentLoaded", ()=> {
...
@@ -160,6 +160,36 @@ document.addEventListener("DOMContentLoaded", ()=> {
something
();
something
();
}
while
(
undefined
);
}
while
(
undefined
);
//algo: sorted array to balanced binary search tree
class
Node
{
constructor
(
val
,
left
,
right
){
this
.
val
=
val
;
this
.
left
=
left
;
this
.
right
=
right
;
}
}
class
BinaryTreeMaker
{
static
makeTree
(
sortedArr
){
const
midPoint
=
Math
.
floor
(
sortedArr
.
length
/
2
);
const
root
=
new
Node
(
sortedArr
[
midPoint
],
null
,
null
);
const
leftSide
=
sortedArr
.
slice
(
0
,
midPoint
);
const
rightSide
=
sortedArr
.
slice
(
midPoint
+
1
);
if
(
leftSide
.
length
){
root
.
left
=
this
.
makeTree
(
leftSide
);
}
if
(
rightSide
.
length
){
root
.
right
=
this
.
makeTree
(
rightSide
);
}
return
root
;
}
}
console
.
log
(
BinaryTreeMaker
.
makeTree
([
3
,
6
,
8
,
9
,
10
,
100
,
433
]));
console
.
log
(
"we are at the conclusion, thanks for your time."
)
console
.
log
(
"we are at the conclusion, thanks for your time."
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment