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

Branches, C. Gutierrez #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

CEsGutierrez
Copy link

Linked List Comprehension Questions

Question Response
1. What advantages does a LinkedList have over an Array? Memory can be dispersed rather than needing a contiguous block of memory
2. When is an Array more advantageous? Because elements in an array know their index numbers, finding an index number in order to do an insertion is a lot easier, although after, an array shifts the index numbers of everything that follows, which is not very efficient whereas I feel that a linked list has less of a "ripple" after an insertion since the next variable is affected for only 1 element.
3. When is a LinkedList more advantageous? Inserting things to the head of a linked list is much easier / less impactful to a Linked-List over an array because it doesn't have the "ripple" effect that inserting things at the start of an array has. Also, it can use dispersed bits of memory rather than needing a whole block.

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.

Excellent work! You hit all the learning goals here. Well done!

# Space complexity - ?

# Time complexity - O(1)
# Space complexity - O(1)
def add_first(data)

Choose a reason for hiding this comment

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

👍

Could also be done as:

head = Node.new(data, head)

# Space complexity - ?

# Time complexity - O(1)
# Space complexity - O(1)
def get_first

Choose a reason for hiding this comment

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

👍

# Space complexity - ?

# Time complexity - O(n)
# Space complexity - O(1)
def length

Choose a reason for hiding this comment

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

👍

Comment on lines +55 to +60
elsif current.next == nil
current.next = temp
return
else
current = self.last_node
current.next = temp

Choose a reason for hiding this comment

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

This seems a little overly complicated. Can you think of a way to simplify this a bit?


current = @head

if @head == nil

Choose a reason for hiding this comment

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

🥇


current = @head

if index >= self.length

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