Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added LCA and tests #88

Merged
merged 13 commits into from
Mar 5, 2020
Merged

Added LCA and tests #88

merged 13 commits into from
Mar 5, 2020

Conversation

nethish
Copy link

@nethish nethish commented Jan 30, 2020

Fixes #62
Added algorithms for Lowest common ancestors for binary search trees.
Added tests for LCA.

@codecov
Copy link

codecov bot commented Jan 30, 2020

Codecov Report

Merging #88 into master will increase coverage by 0.436%.
The diff coverage is 95%.

@@              Coverage Diff              @@
##            master       #88       +/-   ##
=============================================
+ Coverage   97.385%   97.821%   +0.436%     
=============================================
  Files           30        20       -10     
  Lines         1721      1423      -298     
=============================================
- Hits          1676      1392      -284     
+ Misses          45        31       -14
Impacted Files Coverage Δ
pydatastructs/trees/binary_trees.py 96.651% <95%> (+0.214%) ⬆️
...astructs/miscellaneous_data_structures/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/graphs/__init__.py 100% <0%> (ø) ⬆️
pydatastructs/linear_data_structures/__init__.py 100% <0%> (ø) ⬆️
...datastructs/linear_data_structures/linked_lists.py 100% <0%> (ø) ⬆️
...tructs/trees/tests/test_space_partitioning_tree.py
pydatastructs/utils/tests/test_misc_util.py
...ydatastructs/graphs/tests/test_adjacency_matrix.py
pydatastructs/graphs/tests/test_adjacency_list.py
...neous_data_structures/tests/test_binomial_trees.py
... and 10 more

Impacted file tree graph

@nethish nethish requested a review from czgdp1807 January 30, 2020 07:53
@czgdp1807
Copy link
Member

czgdp1807 commented Jan 31, 2020

Do not close this PR. Just push the updates in master branch using the remote of your fork. The PR will be updated automatically.

curr_root = self.tree[curr_root].right
if curr_root == u or curr_root == v:
return curr_root
u_left = self.comparator(self.tree[u].key, self.tree[curr_root].key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this into two lines. Doesn't look clean.

u, v = self.search(j), self.search(k)
if (u is None) or (v is None):
return None
u_left = self.comparator(self.tree[u].key, self.tree[curr_root].key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

if (u is None) or (v is None):
return None
u_left = self.comparator(self.tree[u].key, self.tree[curr_root].key)
v_left = self.comparator(self.tree[v].key, self.tree[curr_root].key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

if curr_root == u or curr_root == v:
return curr_root
u_left = self.comparator(self.tree[u].key, self.tree[curr_root].key)
v_left = self.comparator(self.tree[v].key, self.tree[curr_root].key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Parameter
=========

key:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key: Python object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't addressed.

key:
node to be searched

path:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path: list
Though I don't think it is needed in the API.

Comment on lines 443 to 445
if self._simple_path(key, self.tree[root].left, path) or \
self._simple_path(key, self.tree[root].right, path):
return True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert this into iterative logic using pydatastructs.Stack as Python has a finite recursion limit irrespective of the size of heap memory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stack hasn't been implemented yet.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I made all the changes you have mentioned except this.
pydatastruct.stack is still abstract.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just now saw that.
Ill start making the changes

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@czgdp1807
Copy link
Member

@nethish Are you participating through JMOC?

@czgdp1807
Copy link
Member

@nethish Would you still like to work on it? Thanks.

@nethish
Copy link
Author

nethish commented Feb 15, 2020

Yes.

@czgdp1807
Copy link
Member

@nethish Any news on this?

@nethish
Copy link
Author

nethish commented Mar 5, 2020

I have made all the changes.

Returns
=======

bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
bool:
path[::-1]: bool


if curr_root is None:
return curr_root
return self.tree[curr_root].key
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key may not always be an integer. So, this conflicts with the doc string.

curr_root = self.root_idx
u, v = self.search(j), self.search(k)
if (u is None) or (v is None):
return None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A value error would have been better to let the user know that they are searching for garbage values.

@czgdp1807
Copy link
Member

Will merge when the tests will pass.

@czgdp1807 czgdp1807 merged commit 0428473 into codezonediitj:master Mar 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add algorithms for LCA in BinaryTree.
2 participants