computer science 3
play

Computer Science 3 FINAL EXAM REVIEW DATE & TIME: Thursday, - PDF document

Computer Science 3 FINAL EXAM REVIEW DATE & TIME: Thursday, 05/12/16,10:15-12:15 SCOPE: Overview of Topics: FORMAT: TREES (chapter 9) + 5-10 questions (may have 2 or 3 parts each) + Types of questions: TREE PROJECTS (chapter 10)


  1. Computer Science 3 FINAL EXAM REVIEW DATE & TIME: Thursday, 05/12/16,10:15-12:15 SCOPE: Overview of Topics: FORMAT: • TREES (chapter 9) + 5-10 questions (may have 2 or 3 parts each) • + Types of questions: TREE PROJECTS (chapter 10) • Give example (using diagram) of … • SEARCHING (chapter 11) • Given a code for … Fill-in the missing parts in the code • SORTING (chapter 12) • Write code for … • GRAPHS (chapter 14) • Multiple-choice questions Do all Self-Test Exercises in these chapters. Sample questions/subtopics Q1 What are binary trees, depth of a tree, depth of a node? Give examples (draw diagrams). What are complete binary trees, full binary trees ? Give examples (draw diagrams). Give examples of array representation of complete binary trees. (draw diagrams & code) Give examples of node representation of complete binary trees. (diagrams & code) Code of a class for binary tree nodes: constructor, getting & setting data/links, test a node is a leaf, get/remove leftmost & rightmost, copy a tree, define tree size, depth of a node, depth of a tree, scan/print all nodes,… (also see BinaryTreeNode.java) Tree traversals: Give example, find, write code for Pre-Order, In-Order, and Post-order traversals. Q2 Binary Search Tree(BST): give an example of BST, (diagrams & code for) generating a BST, search for a node, add a node, remove a node in BST. HEAP: give an example of heap, (diagrams & code for) generating a heap, search for a node, add a node, remove a node in heap. B-tree: give an example of B-tree, (diagrams & code for) generating a B-tree, search for a node, add a node, remove a node in B-tree. Q3 Binary Search: give example and write code. Open-address Hashing(OH): give an example of OH a collision, (diagrams & code for) generating a OH table, find/search for an element, add/put an element, remove an element in OH. Double Hashing: purpose, give an example of Double Hashing. (diagrams & code for) generating a double Hashing table. Chained Hashing: purpose, give an example of Chained Hashing. (diagrams & code for) generating a double Hashing table. Q4 SelectionSort: example (diagram) and code InsertionSort: example (diagram) and code MergeSort: example (diagram) and pseudo code (but should be able to fill-in code) QuickSort: example (diagram) and pseudo code (but should be able to fill-in code) HeapSort: example (diagram) and pseudo code (but should be able to fill-in code) Q5 Represent a graph with a 2-dimensional array (for Adjacency Matrix): example (diagram) and code. Represent a graph with Edge (Linked) Lists : example (diagram) and code. Represent a graph with Edge Sets : example (diagram) and code. Depth-First-Search: example (diagram) and pseudo code (but should be able to fill-in code) Breadth-First-Search: example (diagram) and pseudo code (but should be able to fill-in code) Dijskra’s Algorithm: example (diagram) and pseudo code (but should be able to fill-in code) Shortest Path(between 2 nodes): example (diagram) and pseudo code (but should be able to fill-in code) A* (Analysis) O notation/estimation of search and sort algorithms (Best case, Worst case, Average)

  2. Sample Final Exam: 1) Fill-in the code for function treeCopy to copy a binary tree. public class BinaryTreeNode{ public int data; public BinaryTreeNode left, right; public BinaryTreeNode(int initialData, BinaryTreeNode initialLeft, BinaryTreeNode initialRight) { data = initialData; left = initialLeft; right = initialRight; } public static BinaryTreeNode treeCopy(BinaryTreeNode source) { BinaryTreeNode leftCopy, rightCopy; if (source == null) return null; else { leftCopy = treeCopy(source.left); //FILL-IN HERE ... return // FILL_IN HERE ... } } } 2) Draw a diagram to give an example of a Heap of 9 nodes(show node values) and its array representation. 3) Draw a diagram to give an example of a Hash function for a Hash table of size 5, a list of 5 data, and its Chained Hashing table. 4) Write code for function SelectSort(int[] A, int N) which sorts array A using SelectionSort method and returns the sorted array. 5) Given a Graph(p. 722), show order of visited nodes using Breadth-First-Search

  3. • EXAMPLE of QUESTIONS: 1) Given a heap: ADD a node with value 111, draw a new heap: REMOVE the root , draw a new heap: IF we use ARRAY IMPLEMENTATION for heaps(complete binary trees): For the given above heap: index 0 1 2 3 4 5 6 7 8 9 10 11 12 value 100 90 91 17 26 45 1 2 7 3 19 25 36 EXAMPLE of (advanced) QUESTIONS: 2) GIVEN a heap with array implementation: index 0 1 2 3 4 5 6 7 8 9 10 11 12

  4. value 100 90 91 17 26 45 1 2 7 3 19 25 36 ADD a node with value 95, find the NEW array contents: (THEN, we’ll need to draw) (ADD using the graph, we’ll have a NEW GRAPH) index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 value 100 90 95 17 26 45 91 2 7 3 19 25 36 1 3)GIVEN a heap with array implementation: index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 value 100 90 95 17 26 45 91 2 7 3 19 25 36 1 REMOVE the ROOT, find the NEW array contents: (THEN, we’ll need to draw) REVOME using the graph, we’ll have a NEW GRAPH)

  5. index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 value 95 90 91 17 26 45 1 2 7 3 19 25 36 4) Given a set of data {2,7,26,25,19,17} build/draw the HEAP/graph using array implementation: Initially: index 0 1 2 3 4 5 value 2 7 26 125 19 17 THEN, we’ll have to do DOWNWARD HEAPIFICATION: AFTER that we’ll have our HEAP: index 0 1 2 3 4 5 value 26 25 17 7 19 2 5) WHICH of the following trees are HEAP or BST ? a)

  6. b) c) d) e)

  7. List Complete Binary Trees: a,b,d List NON-Complete BT: c,e List HEAP: b,d List BST:c 6) BINARY SEARCH TREE: ADD a node: (55) BEFORE: AFTER: REMOVE a node:

  8. Add 71 back: EXAMPLES of QUESTIONS: 7)Given a BST (below). This is was created by adding a node at a time from a list. Define that list {X,X,X,X,X}. a) ANSWER: the list = {49,9,93,13,52} b)

  9. ANSWER: the list = {13,9,49,52,93} ANOTHER answer: = 13,49,52,9,93 ANOTHER answer: = 13,49,9,52,93 ANOTHER answer: = 13,49,52,93,9 Hashing Method: 8) EXAMPLE: Assume that we need to store the 10 dates of the month (from 1 to 31), for example {4,12,10,5,24,15,30,22,20,14}. Build a Hash table for these data in the following cases: a) Use MIN memory b) With MIN # of collisions (fast) c) Using Double Hash d) Using Linked List (open hashing(=close addressing)), chaining hashing ) a)Use MIN memory Hash function is MOD-10(x) => hash values [0-9] [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 10 30 12 22 4 5 24 15 20 14 24 => collision => WHICH methods (of probing) to use ?  Linear  Double hashing  Linked

  10. 24,15 gives 2 collisions 15,30, gives 1 20 give 8 14 give 5 TOTAL = 19 collisions b) With MIN # of collisions (fast) {4,12,10,5,24,15,30,22,20,14}. DATA range is [1,31] => how many different inputs/data ? 31 => Hash function is MOD-31(x) => hash values [0-30] => Hash TABLE ? size =31 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] 4 5 [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] 10 12 14 15 [20] [21] [22] [23] [24] [25] [26] [27] [28] [29] 20 22 24 [30] 30 TOTAL # of collisions ? = 0 WHAT IF we have to ADD 31 => where it will be ? MOD 31 (31)=0

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend