Data Structures: Trees Quiz
41 Questions
2 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 does the assignment operator '=' do in Python?

  • Applies an arithmetic operation
  • Compares two values for equality
  • Defines a new data type
  • Binds a variable to an object (correct)
  • Which of the following correctly demonstrates a multi-line string in Python?

  • str = """This is a long string""" (correct)
  • str = "This is a long string"
  • str = 'This is a long string'
  • str = '''This is a long string''' (correct)
  • What will the following code output? x = 5 / 2

  • 2.5
  • An error because variable x needs to be declared first
  • 3
  • 2 (correct)
  • Which statement is true about variable names in Python?

    <p>Variable names can include letters, numbers, and underscores but cannot start with a number.</p> Signup and view all the answers

    What does it mean that Python determines the type of a reference automatically?

    <p>The type can change based on the value assigned to the variable.</p> Signup and view all the answers

    What command is used to make a Python file executable in Unix?

    <p>chmod a+x fact.py</p> Signup and view all the answers

    In a Python script, how do you indicate that the file should be executed with a specific interpreter?

    <p>By adding the line '#!/usr/bin/python' at the start</p> Signup and view all the answers

    What does the function 'fact()' compute in the provided script?

    <p>The factorial of its argument</p> Signup and view all the answers

    What is the purpose of making a file executable in Python?

    <p>To allow the script to run without calling the interpreter</p> Signup and view all the answers

    How can a Python program function as both a script and a module?

    <p>By having conditions that check for <strong>name</strong> == '<strong>main</strong>'</p> Signup and view all the answers

    What is a characteristic of leaf nodes in a tree data structure?

    <p>They have zero children.</p> Signup and view all the answers

    Which term describes nodes that have the same parent in a tree?

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

    What does the degree of a node indicate in a tree?

    <p>The number of its child nodes.</p> Signup and view all the answers

    What is the unique path from the root to a node in a tree called?

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

    Which statement accurately describes the height of a tree?

    <p>It is defined as the maximum depth of any node in the tree.</p> Signup and view all the answers

    What is a subtree in the context of a tree data structure?

    <p>Any node with its descendant nodes.</p> Signup and view all the answers

    Which type of tree is characterized by the order of children being irrelevant?

    <p>Unordered tree</p> Signup and view all the answers

    Which of the following is true about internal nodes?

    <p>They have at least one child node.</p> Signup and view all the answers

    Which statement best describes an ancestor in a tree?

    <p>A node that exists on the path from the root to another node.</p> Signup and view all the answers

    What is the relationship of node A to node B if a path exists from A to B?

    <p>A is an ancestor of B.</p> Signup and view all the answers

    Which term refers to when order matters in a tree structure?

    <p>Ordered trees</p> Signup and view all the answers

    What does the depth of a node refer to in a tree?

    <p>The number of edges in the unique path from the root to that node.</p> Signup and view all the answers

    How many parents does a non-root node have in a tree structure?

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

    What is the output of the expression t[1:4] given t = (23, 'abc', 4.56, (2,3), 'def')?

    <p>('abc', 4.56, (2,3))</p> Signup and view all the answers

    Which statement about the in operator is correct when applied to lists?

    <p>It returns True if a value exists in the list.</p> Signup and view all the answers

    What does the expression t[:2] return when t = (23, 'abc', 4.56, (2,3), 'def')?

    <p>(23, 'abc')</p> Signup and view all the answers

    What is the result of the expression (1, 2, 3) + (4, 5, 6)?

    <p>(1, 2, 3, 4, 5, 6)</p> Signup and view all the answers

    What does the expression t[-3] return when t = (23, 'abc', 4.56, (2,3), 'def')?

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

    Why is l2 = l1[:] different from l2 = l1 when l1 is a list?

    <p>Changes in l1 will not affect l2 in the first case.</p> Signup and view all the answers

    What is the effect of the expression (1, 2, 3) * 3?

    <p>(1, 2, 3, 1, 2, 3, 1, 2, 3)</p> Signup and view all the answers

    Identify the correct statement about lists and tuples based on mutability.

    <p>Lists can be changed after creation, but tuples cannot.</p> Signup and view all the answers

    What does the CSS rule 'h1 { color:blue; }' accomplish?

    <p>It makes all h1 headers have blue text.</p> Signup and view all the answers

    How should the CSS rule 'p u { color:red; }' be interpreted?

    <p>Only underlined text in paragraphs will be red.</p> Signup and view all the answers

    In a tree structure, what role do XML parsers play?

    <p>They transform XML into an internal tree structure.</p> Signup and view all the answers

    What does the statement 'text/decorations descendant from the underlining tag () which itself is a descendant of a paragraph tag should be coloured red' imply?

    <p>Only underlined text inside paragraphs will be red.</p> Signup and view all the answers

    What is the advantage of using a tree structure for XML?

    <p>It makes it easier for tools to process and manipulate XML data.</p> Signup and view all the answers

    How does the MathML example 'x2 + y2 = z2' utilize tree structures?

    <p>It represents mathematical expressions in a visual tree structure.</p> Signup and view all the answers

    What is a significant characteristic of tree data structures?

    <p>They can represent hierarchical relationships clearly.</p> Signup and view all the answers

    Why might a programmer want to avoid underlined items in headers being styled with random colors?

    <p>To maintain visual consistency across the application.</p> Signup and view all the answers

    What does cascading in CSS refer to?

    <p>The order of declaration decides which style applies to an element.</p> Signup and view all the answers

    What is a disadvantage of using verbose methods to describe simple equations like 'x2 + y2 = z2'?

    <p>It complicates the understanding of fundamental principles.</p> Signup and view all the answers

    Study Notes

    Trees

    • A tree data structure stores information in nodes.
    • Each node has variable references to successors, with the exception of the root node, which has none.
    • Each node, other than the root, has exactly one node pointing to it.
    • All nodes will have zero or more child nodes or children.
    • Nodes with the same parent are siblings.
    • The degree of a node is defined as the number of its children.
    • Nodes with degree zero are also called leaf nodes.
    • All other nodes are said to be internal nodes, that is, they are internal to the tree.
    • Trees are equal if the order of the children is ignored (unordered trees).
    • They are different if order is relevant (ordered trees), which will be examined in this text.
    • A path is a sequence of nodes where each node is a child of the previous node.
    • The length of a path is the number of nodes in the path minus one.
    • For each node in a tree, there exists a unique path from the root node to that node.
    • The length of this path is the depth of the node.
    • The height of a tree is defined as the maximum depth of any node within the tree.
    • If a path exists from node a to node b, a is an ancestor of b and b is a descendent of a.
    • The descendants of a node include the node itself and all of its children, grandchildren, and so on.
    • The ancestors of a node include the node itself and all of its parents, grandparents, and so on.
    • Given any node a within a tree with root r, the collection of a and all of its descendants is said to be a subtree of the tree with root a.

    XHTML and CSS

    • The XML of XHTML has a tree structure.
    • Cascading Style Sheets (CSS) use the tree structure to modify the display of HTML.
    • For example, h1 { color:blue; } indicates all text and decorations descendant from an h1 header should be blue.
    • Styles can be applied to specific descendants, such as p u { color:red; }, which indicates underlined text within paragraphs should be red.

    XML

    • Any XML can be represented as a tree.
    • XML tools make use of this feature, such as parsers that convert XML into an internal tree structure and XML transformation languages that manipulate this tree structure.

    MathML

    • MathML expressions can be represented as tree structures, allowing for a more efficient and structured way of representing mathematical formulas.
    • This is particularly useful in applications where mathematical formulas need to be processed or transformed, as it provides a consistent and standardized representation.

    Studying That Suits You

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

    Quiz Team

    Related Documents

    data structures.pdf

    Description

    Test your knowledge of tree data structures with this quiz. Explore key concepts such as nodes, paths, degrees, and the differences between ordered and unordered trees. Perfect for students learning about data structures in computer science.

    More Like This

    Mastering Tree Data Structures
    5 questions
    Tree Data Structures Quiz
    10 questions

    Tree Data Structures Quiz

    AltruisticChocolate avatar
    AltruisticChocolate
    Counting Nodes in a Binary Tree
    24 questions
    Use Quizgecko on...
    Browser
    Browser