1 / 11

Using Visualization Tools

Using Visualization Tools. To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury, NZ http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/appldsal.html. Linked Lists.

evonne
Download Presentation

Using Visualization Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Using Visualization Tools To TeachData Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury, NZ http://www.cosc.canterbury.ac.nz/people/mukundan/dsal/appldsal.html

  2. Linked Lists • A linked list is a sequence of items arranged one after another, with each containing a link to the next. • Insertions may be made at either end. • Removals can only be made at the beginning. • Access is sequential starting from the first item.

  3. Queue • A queue is a “First-In, First-Out” (FIFO) data structure similar to a line of people at a ticket window. • Insertions are made at one end, called the tail. • Removals are made at the other end, called the head.

  4. Queue as Linked List • A queue is often implemented using a linked list. • The first position in the list becomes the head. • That’s the only place in a linked list where removals are possible! • The last position in the list becomes the tail.

  5. Stack • A stack is an ordered collection of items that can only be accessed at one end called the “top” of the stack. • Insertions are “pushed” onto the top. • Removals are “popped” off the top in the reverse order of insertions. • A stack is a “Last-In, First-Out” (LIFO) data structure.

  6. Stack as Linked List • A stack is often implemented using a linked list. • The first position in the list becomes the top of the stack. • That’s the only place in a linked list where both insertions and removals are possible. • The pointer to the last position in the list is unused.

  7. Linear Search • A linear search examines items sequentially. • Assuming that the items are unordered, then • The worst-case number of probes is N. • The average number of probes is N÷2.

  8. Binary Search • A binary search is similar to a dictionary search. • Items must be ordered. • Start at the middle, then search left or right half. Repeat until found. • The worst-case number of probes is log2N. • The average number of probes is (log2N)÷2.

  9. Pass 1: Process items 0..N-1 (all) Pass 2: Process items 0..N-2 … Pass N-1: Process items 0..1 Each Pass: Move largest value to the end. sequentially compare adjacent pairs and exchange when out of order. Bubble Sort

  10. Merge Sort • Divide the data into two subsets of equal size. • Sort each subset • Invoke Merge Sort recursively • Merge the two subsets into a single set. • Note that comparisons and exchanges do not occur until recursion has fully descended.

  11. Binary Tree Traversal • Pre-Order: • Process the root • Pre-Order traverse left subtree • Pre-Order traverse right subtree • In-Order: • In-Order traverse left subtree • Process the root • In-Order traverse right subtree • Post-Order: • Post-Order traverse left subtree • Post-Order traverse right subtree • Process the root

More Related