Skip to content

Conversation

@marks214
Copy link

@marks214 marks214 commented Dec 14, 2020

Linked List Comprehension Questions

Question Response
1. What advantages does a LinkedList have over an Array? Unlike an array, the nodes of a linked list do not need to be shifted when adding or deleting data.
2. When is an Array more advantageous? Elements can be accessed directly in an array. For example, array[9] will return the 9th element. Whereas, in a linked list you would have to traverse the list to find the node.
3. What questions do you have about linked lists? I don't really understand why we would use a linked list over a dynamic array.

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, you hit the learning goals here. Nice work.

@@ -0,0 +1,6 @@
# Default ignored files

Choose a reason for hiding this comment

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

Add .idea to your .gitignore file

Comment on lines +12 to 14
# Time complexity - O(1) - A node is added to the beginning of the list. Since this is not an array, we are not replacing an element and shifting the rest of the data over.
# 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.

👍

Comment on lines +21 to 23
# Time complexity - O(1) - We look up the first node (where the head is)
# 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.

👍

Comment on lines +28 to 30
# Time complexity - O(n) we count n nodes in the list
# 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 +41 to 43
# Time complexity - O(n) - need to traverse list of length n to find the last node and add one after that
# Space complexity - O(1)
def add_last(data)

Choose a reason for hiding this comment

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

👍

Comment on lines +53 to 55
# Time complexity - O(n) - we need to traverse the list of length n to find the last node
# Space complexity - O(1)
def get_last

Choose a reason for hiding this comment

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

👍

Comment on lines +67 to +69
index.times do
current = current.next
end

Choose a reason for hiding this comment

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

what if index > length?

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