1. Home
  2. Explore
  3. Computer Science
  4. Linked Lists Introduction

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Linked Lists Introduction

  • 24Unfamiliar
  • 0Learning
  • 0Familiar
  • 0Mastered
Topic: Linked List Fundamentals
  • spaceFlip card
  • KI knew it
  • DI didn't know it
  • ←Previous card
  • →Next card

What is a linked list?

Tap to flipClick to flipspace

A data structure made up of nodes that are linked together via pointers (next references).

Or swipe the card

24 cards

  1. What is a linked list?

    A data structure made up of nodes that are linked together via pointers (next references).

  2. What is a node in a linked list?

    A container that stores a value and a reference (next pointer) to the next node.

  3. What is the head of a linked list?

    The first node of the linked list.

  4. What is the tail of a linked list?

    The last node of the linked list, whose next pointer points to null.

  5. Is a linked list an ordered data structure?

    Yes, because you can traverse sequentially from head to tail via next pointers.

  6. How are nodes of a linked list stored in memory compared to array elements?

    Linked list nodes are not stored contiguously; they can be scattered anywhere in memory.

  7. How is an array stored in memory?

    An array is stored contiguously; all elements are placed next to each other.

  8. What is the time complexity of inserting an element into an array at an arbitrary position?

    O(n), because elements after the insertion point must be shifted.

  9. What is the time complexity of inserting a node into a linked list at an arbitrary position (assuming you have a reference to the node before the insertion point)?

    O(1), because only a couple of pointer adjustments are needed, regardless of list length.

  10. How do you traverse a linked list iteratively?

    Initialize a current pointer to the head. While current is not null, process the node, then set current = current.next.

  11. How do you traverse a linked list recursively?

    Base case: if head is null, return. Else process head, then recursively call the function on head.next.

  12. What common mistake should be avoided when writing a traversal loop condition?

    Checking current.next !== null instead of current !== null; this would skip processing the last node.

  13. How do you implement the Linked List Values problem (return array of all values) iteratively?

    Initialize an empty array. Use a current pointer starting at head. While current !== null, push current.val into the array, then current = current.next. Return the array.

  14. How do you implement the Linked List Values problem recursively?

    Create a helper function that takes head and a values array. If head is null, return. Else push head.val and call helper on head.next. The main function initializes an empty array, calls helper, and returns the array.

  15. How do you implement the Sum List problem (return sum of all values) iteratively?

    Initialize sum = 0. Use a current pointer. While current !== null, add current.val to sum, then current = current.next. Return sum.

  16. How do you implement the Sum List problem recursively?

    Base case: if head is null, return 0. Else return head.val + sumList(head.next).

  17. How do you implement the Linked List Find problem (return true if target value exists) iteratively?

    Use a current pointer. While current !== null, if current.val === target, return true. After loop, return false.

  18. How do you implement the Linked List Find problem recursively?

    Base cases: if head is null, return false; if head.val === target, return true. Else return find(head.next, target).

  19. How do you implement the Get Node Value problem (return value at given index) iteratively?

    Initialize count = 0 and current = head. While current !== null, if count === index, return current.val; else increment count and set current = current.next. If loop ends, return null.

  20. How do you implement the Get Node Value problem recursively?

    Base cases: if head is null, return null; if index === 0, return head.val. Else return getNodeValue(head.next, index - 1).

  21. How do you implement the Reverse List problem (reverse in place and return new head) iteratively?

    Initialize prev = null, current = head. While current !== null, store next = current.next, set current.next = prev, then prev = current and current = next. After loop, return prev.

  22. How do you implement the Reverse List problem recursively?

    Base case: if head is null, return prev (default null). Else store next = head.next, set head.next = prev, then call reverseList(next, head) and return that result.

  23. How do you implement the Zipper List problem (merge two lists alternating, starting with first node of list1) iteratively?

    Set tail = head1, current1 = head1.next, current2 = head2, count = 0. While current1 and current2 are not null: if count % 2 === 0, set tail.next = current2, current2 = current2.next; else tail.next = current1, current1 = current1.next; tail = tail.next; count++. After loop, if current1 is not null, tail.next = current1; else tail.next = current2. Return head1.

  24. How do you implement the Zipper List problem recursively?

    Base cases: if head1 is null, return head2; if head2 is null, return head1. Else set head1.next = head2, then set head2.next = zipperLists(head1.next, head2.next), and return head1.

Card 1 of 24
Card 1 of 24

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent