*** 323 Final Mega Practice Exam :) *** I. Linked lists implementation of Stacks, Queue and List a. What is the major advantage of using linked list implementation for stacks and queues verses using 1D arrays? b. What is the major advantage of using a dummy node in the front of a linked list? II. HashTable (Hash function, table size, 1-D array of LL Queues) a. What is the hash tables for? b. What is the data structure used in hash tables? c. Why do we need to know the bucket size of hash tables? d. What is the hash function for? e. What kind of hash function we would considered a good hash function? f. Why it is very important to have a good hush function for hash tables? III. Bucket Sort – an application of hash table a. What is the hash function used in Bucket-sort? b. Suppose the input size is N, and the largest integer is M, what is the bucket size we needed in bucket-sort? c. Suppose the input size is N and the largest integer in the input data is K, what is the time complexity of the Bucket-sort to sort the input? Show your computation. d. In general, if the input size is N and the largest integer M, in the data set is smaller than N, what would be the time complexity using Bucket-sort? Explain your answer for credits e. What kind of data file would be the worst case to use Bucket-sort for sorting? f. Can we use bucket-sort to sort string? Explain your answer for credit. IV. Radix Sort – an application of hash table a. What is the hash function used in Radix-sort? b. Why do we use only 10 buckets in Radix-sort to sort integers? c. How many buckets do we need when sorting strings? d. How many hash tables do we need in Radix-sort for sorting strings. e. What is the time complexity of Radix-sort for sorting a list of N positive integers. Explain your answer. f. Use the radix-sort to sort the following integers, you must show the results of all iterations (use one table for each iteration) Data: 413, 292, 5, 44, 9, 58, 166, 83, 61 0 | | -> 0 | | -> 0 | | -> 1 | | -> 1 | | -> 1 | | -> 2 | | -> 2 | | -> 2 | | -> 3 | | -> 3 | | -> 3 | | -> 4 | | -> 4 | | -> 4 | | -> 5 | | -> 5 | | -> 5 | | -> 6 | | -> 6 | | -> 6 | | -> 7 | | -> 7 | | -> 7 | | -> 8 | | -> 8 | | -> 8 | | -> 9 | | -> 9 | | -> 9 | | -> Sorted data: Data: 31, 225, 4, 52, 7, 98, 166, 83, 49 0 | | -> 0 | | -> 0 | | -> 1 | | -> 1 | | -> 1 | | -> 2 | | -> 2 | | -> 2 | | -> 3 | | -> 3 | | -> 3 | | -> 4 | | -> 4 | | -> 4 | | -> 5 | | -> 5 | | -> 5 | | -> 6 | | -> 6 | | -> 6 | | -> 7 | | -> 7 | | -> 7 | | -> 8 | | -> 8 | | -> 8 | | -> 9 | | -> 9 | | -> 9 | | -> Sorted data: g. Write in English or in algorithm steps to describe how we may use an existing radix-sort to sort an input file that contains mixture of positive and negative integers. V. B-Trees and 2-3 Trees a. List at least 4 properties of 2-3 trees b. In 2-3 tree insertion, describe how to locate the Spot where to insert a data under Spot? c. Describe in English or in algorithm steps, how to insert a newNode under Spot when Spot has two kids. d. Describe in English or in algorithm steps, how to insert a newNode under Spot when Spot has three kids. e. Describe in English or in algorithm steps, how to delete one of Spot's kids when spot has only two kids, but one of its next sibling(s) has three kids. f. Describe in English or in algorithm steps, how to delete one of Spot's kids when spot has only two kids, but none of its next sibling(s) has three kids. g. Describe the situation, when inserting a node into a 2-3 tree, the 2-3 tree will grow a level in height. h. Describe the situation, when deleting a node from a 2-3 tree, the 2-3 tree will decrease a level in height. i. [source: exam 1] Insert 10 into the 2-3 tree below. You must do: (a) fill the leaf-nodes; b) show which node “SPOT” is pointed to; c) make necessary modification of spot's kids and d) update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable 21 | 52 12 | -1 30 | 45 68 | 78 _8_ ___ _=_ ___ ___ ___ ___ ___ ___ j. [source: exam 1] Insert 50 into the 2-3 tree below. You must do: (a) fill the leaf-nodes; b) show which node “SPOT” is pointed to; c) make necessary modification of spot's kids and d) update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable. <2-3 tree in the next page> 25 | 55 15 | -1 30 | 48 58 | 70 _8_ ___ _=_ ___ ___ ___ ___ ___ ___ k. [source: final] Insert 65 into the 2-3 tree below. You must do: (a) fill the leaf-nodes; b) show which node “SPOT” is pointed to; c) make necessary modification of spot's kids and d) update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable. 25 | 55 15 | -1 30 | 48 58 | 70 _8_ ___ _=_ ___ ___ ___ ___ ___ ___ l. [source: exam 1] Delete 57 from the 2-3 tree below. You must do: (a) fill in leaf-nodes b) show the search path and show which node “SPOT” is pointed to; (c) mark the deletion; d) make necessary modification of spot's kids and update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable. 27 | 57 12 | -1 32 | -1 70 | -1 _8_ ___ _=_ ___ ___ _=_ ___ ___ _=_ m. [source: exam 1] Delete 18 from the 2-3 tree below. You must do: (a) fill in leaf-nodes b) show the search path and show which node “SPOT” is pointed to; (c) mark the deletion; d) make necessary modification of spot's kids and update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable. 29 | 60 18 | -1 38 | -1 70 | -1 _8_ ___ _=_ ___ ___ _=_ ___ ___ _=_ n. [source: final] Delete 30 from the 2-3 tree below. You must do: (a) fill in leaf-nodes b) show the search path and show which node “SPOT” is pointed to; (c) mark the deletion; d) make necessary modification of spot's kids and update all necessary keys of the tree; e) draw the final tree only if your modification is very messy, not readable. 25 | -1 15 | -1 30 | -1 __=__ _8_ ___ _=_ ___ ___ _=_ VI. Quad Tree (image representation and compression) a. Draw the Quad tree representation of the binary image below. 0 is white and 1 is black and 5 is grey. Use the rectangle on the right to draw your tree. 0000111111110000 0000111111110000 0000111111110000 0000111111110000 1111000000001111 1111000000001111 1111000000001111 1111000000001111 1111111100000000 1111111100000000 1111111100000000 1111111100000000 0000111111110000 0000111111110000 0000111111110000 0000111111110000 b. Construct a binary image for the quad tree below. Use the box on the right for image. :grey :black (1) :white (0) c. Given the upperR, upperC, and the size, <0, 28, 28>, of a grey-color node in a Quad tree below, write the upperR, upperC, and size for each of its four children. <0, 28, 28> < , , > < , , > < , , > < , , > < , , > < , , > < , , > < , , > VII. Huffman Coding for data a. What us Huffman coding for? b. What is the purpose of computing entropy of a Huffman-coding scheme? c. Given an unsorted input pairs of characters and probability below, illustrate the Huffman coding algorithm steps: input: 46(e) 7(f) 10(b) 6(c) 7(d) 24(a) i. Construction of an ordered linked list. ii. Construction of the Huffman binary tree from the ordered linked list. iii. Illustrate the result of Huffman binary tree. iv. Fill the Huffman entropy table below: Prob code # bits entropy a 24 b 10 c 6 Total Entropy = ________ d 7 e 46 f 7 VIII. Directed Graphs and Undirected Graphs a. Write the formal definition of the following: i. Graphs ii. Path iii. Simple cycle iv. Connected graph v. Free tree vi. Spanning trees of a graph G vii. Minimum spanning tree of a graph G b. If a matrix is used to represent a directed graph of N nodes and K edges, how many bytes of memory would be used? c. If a hash table (array of linked lists with dummy nodes) to represent a directed graph of N nodes and K edges, how many bytes of memory would be used? d. Given a directed graph of N nodes and K edges, if your main concern is about the usage of memory space, how do you to determine which data structures to use, matrix or hash table? Explain your answer e. What is the major advantage of using matrix for a graph vs using hash table? IX. Dijkstra’s Algorithm a. Given the list of edges of a directed graph below and the source is _C_, using only arrays to illustrate Dijkstra’s algorithm to find the shortest paths from _C_ to all nodes in the graph. (a) iteration (Iterat) 0: fill-in the matrix from the graph, fill-in Min and three 1D arrays; (b) for each iteration (1 to 4), update Min, update three 1D arrays, (c) when finish, list all paths from _C_ to all other nodes in the graph with costs. List of edges: <A B 5>, <A D 10>, <B C 15>, <B D 20>, <C A 25>, <C D 10>, <C E 5>, <D A 5>, <D C 15>, <E A 15> , <E D 8> ** use 99 for infinity A B C D E Iterat Min A B C D E A B C D E A B C D E A 0 C ToDo Best Father B C Iterat Min A B C D E A B C D E A B C D E D 1 ToDo Best Father E Iterat Min A B C D E A B C D E A B C D E 2 ToDo Best Father Iterat Min A B C D E A B C D E A B C D E 3 ToDo Best Father Iterat Min A B C D E A B C D E A B C D E 4 ToDo Best Father Path from C to A (with cost): Path from C to B (with cost): Path from C to C (with cost): Path from C to D (with cost): Path from C to E (with cost): b. What is the time complexity of the Dijkstra’s algorithm? c. Write, in algorithm steps the Dijkstra's algorithm. d. Proof: During each iteration of the Dijkstra's algorithm, when a min node, say, M, is determined, the Dijkstra's algorithm claims that it has found the shortest path from the source node, S, to the min node, M: Pi= <S, ni1, ni2, …, M>, Prove this claim that there is no other path, say Pk = <S, nk1, nk2, , …, M>, in the graph from S to M is shorter than the path Pi. Proof by contradiction. Assume there is a shorter path from S to M. That means there was a path that contained edges with a lower cost to get to M than the path of edges we currently chose using the algorithm. However, since Dijkstra's always chooses the path with the edges with the lowest cost, this is not possible. Therefore, we have a contradiction and our original premise must have been false. Therefore, there is no other path in the graph from S to M that is shorter than Pi. X. Minimum Spanning Trees Algorithms a. Write the two properties of Free trees b. Prove the first property of Free trees. c. Prove the second property of Free trees. d. Write in algorithm steps for the Prim's algorithm for finding MST of a given undirected graph G. e. Write in algorithm steps for the Kruskal's algorithm for finding MST of a given undirected graph G f. Given an undirected and connected graph below (in edge notation), use Kruskal’s algorithm to construct a minimum-spanning-tree (MST) of G; using edge notation, as shown in the lectures, to illustrate the construction process. G = <N, E>, where N = {A, B, C, D, E}; and E = {<A B 4>, <A D 5>, <A E 5>, <B E 2>, <B C 2>, <C E 2>, <C D 6> <D E 5>} g. Given an undirected and connected graph below (in edge notation), use Prim’s algorithm to construct a minimum-spanning-tree (MST) of G. Let E be the initial node in MST. To illustrate the construction process, you may use the edge notation as in Kruscal's or draw the diagrams as shown in lecture notes. G = <N, E>, where N= {A, B, C, D, E}; and E={<A B 7>, <A D 4>, <A E 8>, <B E 2>, <B C 2>, <C E 2>, <C D 6> <D E 5>} XI. Partial Ordering a. Define partial ordering relations Has 3 properties. Irre exive, anti symmetric, transitive b. Is the relation “is-standing-next-to” a partial ordering relation? If it is, then show it passes all the criteria, if it is not, then show what criteria it violates. c. Is the relation “is-shorter than” a partial ordering relation? If it is, then show it passes all the criteria, if it is not, then show what criteria it violates. d. Is the relation “is greater or equal to” a partial ordering relation? If it is, then show it passes all the criteria, if it is not, then show what criteria it violates. e. Is the relation “is-taller than” a partial ordering relation? If it is, then show it passes all the criteria, if it is not, then show what criteria it violates. f. Is the relation "is-on-top-of " a partial ordering? If it is, then show it passes all the criteria, if it is not, then show what criteria it violates. XI. Dependency Graphs and Scheduling a. Given the dependency graph below, construct a job schedule table, using un-limited processors and variable job times. Use one graph and one schedule table. However, you need to do: a. increment time Ti; b. for each T0, T1, T2, …, write what jobs are placed in OPEN after all the unmarked Orphan nodes are located; c. cross out jobs after jobs are removed from OPEN and placed onto the schedule table. 9[2] 8 [1] T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 3 [2] 6 [3] 1 [3] 4 [2] 7 [1] 5 [3] 2 [3] Time: T0 Write the job ID in OPEN according to Time (Jobs in Open are in ascending order by jobs' ID): Time T0 : OPEN: Time T1 : OPEN: Time T2 : OPEN: Time T3 : OPEN: Time T4 : OPEN: Time T5 : OPEN: Time T6 : OPEN: b. Given the dependency graph below, construct a job schedule table, using 2 processors. You may assume all jobs take 1-time unit. Use one graph and one schedule table. However, you need i. to increment time, Ti; ii. for each T0, T1, T2, …, write what jobs are in OPEN after all the unmarked Orphan nodes are located; iii. cross out jobs after jobs are removed from OPEN and placed onto the schedule table. T0 T1 T2 T3 T4 T5 T6 T7 T8 T9 T10 9 8 P1 P2 3 6 1 Time: T0 Write the job ID in OPEN according to Time (Jobs in Open are in ascending order by jobs' ID): 4 7 5 Time T0 : OPEN: 2 Time T1 : OPEN: Time T2 : OPEN: Time T3 : OPEN: Time T4 : OPEN: Time T5 : OPEN: XII. Solving Hard Problems and Search Techniques a. Write the problem statement for the k-cliques problem and what makes it a NP-problem. b. Write the problem statement for the knapsack problem and what makes it a NP-problem. c. Write the problem statement for the graph-coloring problem and what makes it a NP-problem. d. Write the problem statement for the travelling-salesman's problem and what makes it a NP-problem. e. One of the applications of the graph-coloring problem is the traffic-light control system, where nodes are traffic turns and edges are those turns cannot perform simultaneously. Given the T-junction of the street intersection below (all streets are bi-directional), draw the graph for the traffic control system to be solve by the graph- coloring algorithm. If drawing is hard, you can just write the list of undirected edges of the graph. <There will be a question like this on the exam… Make sure to study more traffic-light graph coloring problems> A | | B--- ---C XIII. Advanced Search Strategies a. What are the two poloynomial time complexity greedy methods that find sub-optimal solutions for the graph- coloring problem. i. Write the algorithm steps for the first one ii. Write the algorithm steps for the second one b. Define Depth-First Search. How many nodes do we visit, before finding the first goal? Is this a good search technique? Can you see any potential problem with this search technique? Does this search technique quarantee finding a goal node, if it exists? <Refer to Lecture 11.1, page 8> c. Define Breadth-First Search. How many nodes do we visit, before finding the first goal? Is this a good search technique? Can you see any potential problem with this search technique? Does this search technique quarantee finding a goal node, if it exists? <Refer to Lecture 11.1, page 9> d. Define Hill-Climbing/Greedy method – without backtrack. Is this a good search control strategy? Can you see any potential problem with this search technique? Does this search technique quarantee finding a minimum route? How can we improve this method? <Refer to Lecture 11.1, page 11> e. Define Hill-Climbing/Greedy method – with backtracking. Is this a good search control strategy? Can you see any potential problem with this search technique? Does this search technique quarantee finding a minimum route? How can we improve this method? <Refer to Lecture 11.1, page 12> f. Without backtrack, what is the best case given a search tree? What is the worst case? Why? g. With backtracking, what is the best case given a search tree? What is the worst case? Why? h. Basic Search: Given the search tree below, write the sequence of nodes visited using the search methods below (Search should stop when the search is a fail or a node with * is reached) A C D E Y X Z U N W* K I J* i. The list of nodes visited using Breadth-first search: ii. The list of nodes visited using Depth-first without back-track: iii. The list of nodes visited using Depth-first with back-track: iv. In general, if a goal node (*) exists in a given search tree, which search methods in the above may not find a goal node? XIV. A* Search Technique a. What are the two (h* functions) used in 8-puzzle problem for A* search algorithm. h1*(n) = ?, h2*(n) = ? b. Given the node n, and the goal node G, fill the arrays for the configurations of node n and node G n G 0 1 2 3 4 5 6 7 8 n= 1 2 3 2 8 7 4 0 6 1 6 4 0 1 2 3 4 5 6 7 8 5 8 7 3 0 5 G= c. Use 1D arrays for the tile misplaced for h1*(n) and distances for h2*(n) then compute the values. 0 1 2 3 4 5 6 7 8 h1* h1*(n)= _____ 0 1 2 3 4 5 6 7 8 h2*(n)= _____ h2* d. As taught in lecture, we can use a 2D matrix for a quick look-up for the distance from a position in node n to a position in the goal node G. Fill the 2D distance look-up matrix for h2*(n), where matrix (i, j) is the distance of a tile in position i to the position j in 8-puzzel. 0 1 2 3 4 5 6 7 8 0 1 2 3 4 5 6 7 8 XV. Min-Max & Alpha-Beta a. Define Min-Max tree, what is Max node? What is Min node? b. What is the Alpha cut off Rule? c. What is the Beta cutoff rule? d. Given the Win-Lost-draw tree below. Use the strategy you learnt in class, to determine which branch the max node (the root) should make his/he next move. Show all your work as illustrated in the lecture: write W, D, or L inside those leafnode that are evaluate; write the back-up values under the nodes and write the final back-up value inside the nodes and cross out those branches that do not need to explore. D W D W L W W W D L W W W L L D W W L e. Given the min-max game tree below. Use the strategy you learnt in class to determine which branch the max node (the root) should make his/her next move. Show all your work as illustrated during the lecture: mark those leaf- node that are evaluated; write the back-up values under the nodes and write the final back-up value inside the nodes and cross out those branches that do not need to explore (i.e., alpha-cut-off and beta-cut-off). 14 15 4 2 12 13 7 6 4 3 10 15 6 5 6 5 10 12 15 XVI. Algorithm Analysis and Time Complexities a. Determine the time complexity of T(n) for the procedure below. Compute f(n), c, and n0 for practice. void ProcA(int N) { int result = 1; for (int i = 1; i <= N; i++) { result += i * i * i for (int j = N; j >= 1; j++) { result *= i + j * k; } } return result; } b. Given T(n) = 8n2 + 5n + 10, determine f(n), c and n0. You must show your work c. Given T(n) = 8log2(n) + 8, determine f(n), c and n0. You must show your work! d. Determine T(n) for the recursive procedure below. Compute f(n), c, and n0 for practice. int ProcB(Tnode T) { if (T == null) if N <= 1 return 0; T(N) = else else { T.leftCount = 1 + procB(T.left); T.rightCount = 1 + procB(T.right); return max(T.LeftCount, T.rightCount); } } e. Determine T(n) for the recursive procedure below. Compute f(n), c, and n0 for practice. bool ProcC(Tnode T, int data) { if N <= 1 if (T == null) { T(N) = return false; else } else if (T.data == data) { return true; } else if (T.data < data) { return ProcC(T.left, data); } else { return ProcC(T.right, data); } }
Enter the password to open this PDF file:
-
-
-
-
-
-
-
-
-
-
-
-