Presentation is loading. Please wait.

Presentation is loading. Please wait.

ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,

Similar presentations


Presentation on theme: "ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,"— Presentation transcript:

1 ACM/JETT Workshop - August 4-5, 2005 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

2 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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 log 2 N. The average number of probes is (log 2 N)÷2.

9 ACM/JETT Workshop - August 4-5, 2005 Bubble Sort 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.

10 ACM/JETT Workshop - August 4-5, 2005 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 ACM/JETT Workshop - August 4-5, 2005 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


Download ppt "ACM/JETT Workshop - August 4-5, 2005 Using Visualization Tools To Teach Data Structures and Algorithms Java applets by Dr. R. Mukundan, University of Canterbury,"

Similar presentations


Ads by Google