Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
github.com/exercism/go/exercises/binary-search-tree
Insert and search for numbers in a binary tree.
When we need to represent sorted data, an array does not make a good data structure.
Say we have the array [1, 3, 4, 5]
, and we add 2 to it so it becomes
[1, 3, 4, 5, 2]
now we must sort the entire array again! We can
improve on this by realizing that we only need to make space for the new
item [1, nil, 3, 4, 5]
, and then adding the item in the space we
added. But this still requires us to shift many elements down by one.
Binary Search Trees, however, can operate on sorted data much more efficiently.
A binary search tree consists of a series of connected nodes. Each node
contains a piece of data (e.g. the number 3), a variable named left
,
and a variable named right
. The left
and right
variables point at
nil
, or other nodes. Since these other nodes in turn have other nodes
beneath them, we say that the left and right variables are pointing at
subtrees. All data in the left subtree is less than or equal to the
current node's data, and all data in the right subtree is greater than
the current node's data.
For example, if we had a node containing the data 4, and we added the data 2, our tree would look like this:
4
/
2
If we then added 6, it would look like this:
4
/ \
2 6
If we then added 3, it would look like this
4
/ \
2 6
\
3
And if we then added 1, 5, and 7, it would look like this
4
/ \
/ \
2 6
/ \ / \
1 3 5 7
Look for a stub file having the name binary_search_tree.go and place your solution code in that file.
To run the tests run the command go test
from within the exercise directory.
If the test suite contains benchmarks, you can run these with the --bench
and --benchmem
flags:
go test -v --bench . --benchmem
Keep in mind that each reviewer will run benchmarks on a different machine, with different specs, so the results from these benchmark tests may vary.
For more detailed information about the Go track, including how to get help if you're having trouble, please visit the exercism.io Go language page.
Josh Cheek https://twitter.com/josh_cheek
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.