TMF1434: Data Structure and Algorithms - Linked Lists (Part 2)
10 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What happens when the new item is smaller than the smallest item in the list?

  • The new item is inserted somewhere in the middle of the list
  • The new item is not inserted in the list
  • The new item goes at the end of the list
  • The new item goes at the beginning of the list (correct)
  • What is the purpose of the trailCurrent pointer in deleting a node?

  • To point to the first node of the list
  • To point to the last node of the list
  • To point to the node containing the item to be deleted
  • To point to the node just before the node pointed to by current (correct)
  • What happens when the list is initially empty and we try to delete a node?

  • An error occurs (correct)
  • The item is deleted successfully
  • The list becomes empty
  • The head pointer of the list is adjusted
  • What is the purpose of the count variable in inserting an item in an ordered linked list?

    <p>To keep track of the number of items in the list</p> Signup and view all the answers

    Where is the new item inserted when it is larger than all the items in the list?

    <p>At the end of the list</p> Signup and view all the answers

    What happens when the item to be deleted is not in the list?

    <p>Nothing happens</p> Signup and view all the answers

    What happens when the new item is to be inserted somewhere in the middle of the list?

    <p>The new item is inserted between trailCurrent and current</p> Signup and view all the answers

    What is the purpose of the current pointer in deleting a node?

    <p>To point to the node containing the item to be deleted</p> Signup and view all the answers

    What is the function used to insert an item at the head of an ordered linked list?

    <p>insert</p> Signup and view all the answers

    What is the function used to insert an item at the tail of an ordered linked list?

    <p>insert</p> Signup and view all the answers

    Study Notes

    Unordered Linked Lists

    • Unordered linked lists are derived from the abstract class linkedListType.
    • To search for a given item in an unordered linked list:
      • Compare the search item with the current node in the list.
      • If the item is found, return true; otherwise, return false.
      • Repeat the comparison until the item is found or no more data is left in the list.
    • To insert a node at the head of an unordered linked list:
      • Create a new node and set it as the first node.
    • To insert a node in the middle of an unordered linked list:
      • Use two pointers, p and q.
      • Compare the info of the new node with the info of the current node.
      • If the new node's info is less than the current node's info, insert the new node before the current node.
    • To insert a node at the tail of an unordered linked list:
      • Create a new node and set it as the last node.
    • To delete a node in an unordered linked list:
      • Consider the following cases:
        • Case 1: The list is empty.
        • Case 2: The node to be deleted is the first node.
        • Case 3: The node to be deleted is not the first node, but is somewhere in the list.
        • Case 4: The node to be deleted is not in the list.

    Ordered Linked Lists

    • Ordered linked lists are derived from the abstract class linkedListType.
    • To search for a given item in an ordered linked list:
      • Compare the search item with the current node in the list.
      • If the item is found, return true; otherwise, return false.
      • Repeat the comparison until an item in the list that is greater than or equal to the search item is found, or no more data is left in the list.
    • To insert a node in an ordered linked list:
      • Use two pointers, current and trailCurrent.
      • Consider the following cases:
        • Case 1: The list is initially empty.
        • Case 2: The new item is smaller than the smallest item in the list.
        • Case 3: The item is to be inserted somewhere in the list.
    • To delete a node in an ordered linked list:
      • Use two pointers, current and trailCurrent.
      • Consider the following cases:
        • Case 1: The list is initially empty.
        • Case 2: The item to be deleted is contained in the first node of the list.
        • Case 3: The item to be deleted is somewhere in the list.
        • Case 4: The list is not empty, but the item to be deleted is not in the list.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Description

    This quiz covers the concept of Unordered Linked Lists, including the UML class diagram of the unorderedLinkedList class and its inheritance hierarchy. It also tests your understanding of searching for a given item in an Unordered Linked List. Review your knowledge of data structures and algorithms with this quiz!

    More Like This

    Use Quizgecko on...
    Browser
    Browser