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

Fire - Anna #17

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open

Fire - Anna #17

wants to merge 10 commits into from

Conversation

annakim93
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Well done Anna, you hit the learning goals here. Nice work!

Comment on lines +32 to +38
# method to find if the linked list contains a node with specified value
# returns true if found, false otherwise
# Time Complexity: O(n)
# >> Must check every single node in linked list
# Space Complexity: O(1)
# >> Just checking for membership; only ever store current_node
def search(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +18 to +25
# method to add a new node with the specific data value in the linked list
# insert the new node at the beginning of the linked list
# Time Complexity: O(1)
# >> Constant num of actions - create new node,
# set next to old head, set head pointer to new node
# Space Complexity: O(1)
# >> Always adding 1 new node
def add_first(value)

Choose a reason for hiding this comment

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

👍

Comment on lines +50 to +52
# method to return the max value in the linked list
# returns the data value and not the node
def find_max

Choose a reason for hiding this comment

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

👍

Comment on lines +68 to +72
# Time Complexity: O(n)
# >> have to traverse entire linked list (unless we know it's sorted...)
# Space Complexity: O(1)
# >> store current_node and min regardless of how long LL is
def find_min

Choose a reason for hiding this comment

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

👍

Comment on lines +247 to +252
# Time Complexity: O(n)
# >> get length of LL (pass through all n nodes)
# >> go through half of those nodes
# Space Complexity: O(1)
# >> store mid_index, current_node, current_node_num
def find_middle_value

Choose a reason for hiding this comment

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

👍

Comment on lines +255 to +257
mid_index = length / 2
current_node = @head
current_node_num = 0

Choose a reason for hiding this comment

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

This works, but could you do something similar to the method to find a cycle.

Copy link
Author

Choose a reason for hiding this comment

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

Ah I see - I think India mentioned in the previous CS Fun session that you could move a slow and fast pointer and when fast reaches the end, slow will be at the middle

Comment on lines +269 to +275
# Time Complexity: O(n)
# >> pass through all nodes to get length
# >> at worst pass through all nodes again to get 0th node from end
# >> 2n --> n
# Space Complexity: O(1)
# >> store len, index, current_node, curr_node_num
def find_nth_from_end(n)

Choose a reason for hiding this comment

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

👍 Good use of length.

Comment on lines +295 to +304
# Time Complexity: O(n)
# >> If no cycle, 'fast' and 'slow' pointers will go through LL once
# >> If cycle, 'slow' pointer will go through the list at most once
# >> b/c 'fast' cannot lap / overtake the 'slow' pointer if 'fast'
# >> moves two nodes at a time while 'slow' 1 node at a time
# >> if DID skip over --> slow --> fast
# >> previous step would mean both pointers were at the same node
# Space Complexity: O(1)
# >> fast and slow nodes
def has_cycle

Choose a reason for hiding this comment

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

👍

Comment on lines +320 to +324
# Time Complexity: O(n)
# >> worst case node has to be placed at end
# Space Complexity: O(1)
# >> store new_node and current_node
def insert_ascending(value)

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants