Linked Structures
NOTE: Use @SupressWarnings(“unchecked”)
Linked Structures
NOTE: Use @SupressWarnings(“unchecked”)
2-3 search trees
We introduce in this section a type of binary search tree where costs are guaranteed to be logarithmic. Our trees have near-perfect balance, where the height is guaranteed to be no larger than 2 lg N.
Search and insert operations in a 2-3 tree with N keys are guaranteed to visit at most lg N nodes.
Binary Trees
Homework:
Implementing Binary Search Trees: With Links
1. How are the constructors implemented?
2. Write the pseudocode for public void addElement (T element). Draw an example of adding an element to a BST.
3. Write the pseudocode for public T removeElement (T targetElement). Draw an example of removing an element to a BST.
4. Write the pseudocode for public void removeAllOccurrences (T targetElement).
November 13th, 2014
Linked lists. A linked list is a recursive data structure that is either empty (null) or a reference to a node having a generic item and a reference to a linked list. To implement a linked list, we start with a nested class that defines the node abstraction
private class Node { Item item; Node next; }
Homework:
LispList interface and the EmptyList and NonEmptyList classes implementations.
Write a test program that constructs a list and prints it.
From Wikipedia:
Lisp (historically, LISP) is a family of computer programming languages with a long history and a distinctive, fully parenthesized Polish prefix notation. Originally specified in 1958, Lisp is the second-oldest high-level programming language in widespread use today; only Fortran is older (by one year).
The name LISP derives from “LISt Processing”. Linked lists are one of Lisp language’s major data structures, and Lisp source code is itself made up of lists. As a result, Lisp programs can manipulate source code as a data structure, giving rise to the macro systems that allow programmers to create new syntax or new domain-specific languages embedded in Lisp.
Classwork:
Go to Classroom Salon to discuss the Bag Class and watch only the visual representation of stacks and queues video.
Homework: Use the API discussed in class to develop your own implementation of the Bag Class. Make sure you use generics.
Classwork:
Stack Class and its applications.
Exercise 3 – discuss it in Classroom Salon
Homework:
Exercises 4 and 7
Implement the Queue Class
September 29th, 2015
Binary Trees
Videos from mycodeschool.com
Binary Tree: Level Order Traversal
Binary Tree Traversal: Preorder, Inorder, Postorder
Delete a node from Binary Search Tree
Inorder Successor in a binary search tree
Check if a binary tree is binary search tree or not
Homework:
1. Draw the binary search tree that results from adding the following integers (34 45 3 87 65 32 1 12 17).
2. Look into the BinarySearchTreeADT in the book.
3. Read Implementing Binary Search Trees: With Links
September 25th, 2015
Trees
Tree Types
(a) and (c)–are complete
Only (c) in Figure full
Homework:
Visit edmodo.com to answer the following questions
1. What is a tree?
2. What is a node?
3. What is the root of the tree?
4. What is a leaf?
5. What is an internal node?
6. Define the height of a tree.
7. Define the level of a node.
Read Tree implementation with arrays.