Quiz 3: Data Structures and Algorithms - Chapters 5 & 6 - Prof. Joseph D. Sloan, Quizzes of Data Structures and Algorithms

A quiz for students in cosc 350 at wofford education, covering topics on trees, traversals, depth-first and breadth-first searches, binary heaps, and graphs. Students are required to identify tree properties, perform tree traversals, find paths, represent binary heaps, choose appropriate data structures, sketch graphs, and apply dijkstra's and prim's algorithms.

Typology: Quizzes

Pre 2010

Uploaded on 08/18/2009

koofers-user-ruh
koofers-user-ruh 🇺🇸

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
SWELLA Wofford Educa tion Page 1 of 5 2/2/2009
COSC 350: Fall 2008 Your Name ___________________
Quiz 3: Chapters 5 & 6
Be sure to answer each question carefully and completely.
A
/ \
/ \
B C
/ \ \
D E F
/ \ /
G H I
/ \ /
J K L
1. (12 pts.) For the tree sketched above, identify or answer each of the following:
a. type of tree
b. leave(s)
c. ancestor(s) of G
d. sibling(s) of D
e. level of H
f. subtree rooted at G
2. (8 pts.) For the tree sketched above, give the output if its nodes were visited and
printed in:
a. a preorder traversal
b. a in-order traversal
pf3
pf4
pf5

Partial preview of the text

Download Quiz 3: Data Structures and Algorithms - Chapters 5 & 6 - Prof. Joseph D. Sloan and more Quizzes Data Structures and Algorithms in PDF only on Docsity!

COSC 350: Fall 2008 Your Name ___________________

Quiz 3: Chapters 5 & 6

Be sure to answer each question carefully and completely. A /
/
B C / \
D E F / \ / G H I / \ / J K L

  1. (12 pts.) For the tree sketched above, identify or answer each of the following: a. type of tree b. leave(s) c. ancestor(s) of G d. sibling(s) of D e. level of H f. subtree rooted at G
  2. (8 pts.) For the tree sketched above, give the output if its nodes were visited and printed in: a. a preorder traversal b. a in-order traversal
  1. (8 pts.) Give the path from A to X for the following tree: A /
    /
    B C / \
    D E X / \ /
    G X I J / \ / /
    K X M N O / \ / /
    P Q X S T a) when doing a depth-first search b) when doing a breadth-first search
  2. (12 pts.) In the space below, answer the questions that follow regarding this binary heap tree organized using an alphabetical ordering: A /
    /
    C D / \ /
    L K Q N /
    W X a) Give the internal Python representation used in your text. b) Draw the final tree after B is added. c) Draw the final tree after A is deleted.
  1. (8 pts.) Starting at Node a , use Dijkstra’s Algorithm to calculate the minimal cost for visiting each node. Write that cost on the node. Below the graph, list the nodes in the order that you expanded them.
  2. (8 pts.) Starting at Node a , use Prim’s Algorithm the find a minimal spanning tree. Below the graph, list the edges you added to the spanning tree in the order that you added them. (List edges as ordered pairs of nodes. For example, (a, b) is the edges with weight 10 in the graph.)
  3. (8 pts.) Give the parse tree for the expression 2 / 3 + 4 * 5 – 6
  1. (20 pts.) Using a list representation, implement in Python the following functions from an ADT for a binary search tree : a) binaryTree() creates a new binary tree. b) getLeftChild() returns the binary tree that is the left sub-tree of the current node. c) setRootValue(val) stores val in the root of the current node. d) insertLeft(val) creates a new binary tree and inserts it as the left child of the current node. Pledged: ________________________________________________________________