Algorithms and Data Structures Exercise I Banafsheh Azari http://www.uni-weimar.de/de/medien/professuren/grafischedatenverarbeitung/ Bauhaus-University Weimar - CogVis/MMC May 3, 2017 c 2017, Algorithms and Data Structures Exercise I Exercise I 1/23
Exercise Wednesday,11:00, SR014, B11 Even weeks First Exercise : 03.05.2017 c 2017, Algorithms and Data Structures Exercise I Exercise I 2/23
Exercise 5 Assignments max 6 point for each assigment 30% exercise and 70% final exam c 2017, Algorithms and Data Structures Exercise I Exercise I 3/23
Exercise Conditions C/C++ or Java Compilable source code (gcc or javac) No IDEs Readable source code Self-contained submission c 2017, Algorithms and Data Structures Exercise I Exercise I 4/23
Exercise Comments Sufficient comments (rule of thumb: another Developers can get program logic alone by reading the comments) In each! Data: Name, matriculation number, SS2017 c 2017, Algorithms and Data Structures Exercise I Exercise I 5/23
Exercise Tasks: www.uni-weimar.de/de/medien/professuren/grafischedatenverarbeitung/ Submission: per E-Mail as NameLastname E... c 2017, Algorithms and Data Structures Exercise I Exercise I 6/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Data Structures Array Linked Lists Stacks LIFO Push pop Queues FIFO enqueue dequeue Trees Graphs c 2017, Algorithms and Data Structures Exercise I Exercise I 7/23
Polynomial g x =mx +nx +ox+p coef expo next Start m 4 n 2 o 1 p 0 c 2017, Algorithms and Data Structures Exercise I Exercise I 8/23
Polynomial Addition f x =ax +bx +cx Start g x =mx +nx +ox+p a 5 b 3 c 1 Start m 4 n 2 o 1 p 0 h x =f x +g x =ax +mx +bx +nx + c+o x+p c 2017, Algorithms and Data Structures Exercise I Exercise I 9/23
Infix and Postfix Expression Infix expression (A * (B + (C / D) ) ) Postfix expression (A (B (C D /) +) *) Prefix expression (* A (+ B (/ C D) ) ) c 2017, Algorithms and Data Structures Exercise I Exercise I 10/23
Converting Example stack original expression 5/7+2*4*3 postfix expression 5 / + * + * + + push / 5 7 pop / push + 5 7 / 5 7 / 2 push * 5 7 / 2 4 pop * push * 5 7 / 2 4 * pop * 5 7 / 2 4 * 3 * pop + 5 7 / 2 4 * 3 * + c 2017, Algorithms and Data Structures Exercise I Exercise I 11/23
Calculation Example stack original expression 2 4 * 9 5 + - 2 4 2 push 2 push 4 pop 4 pop 2 push 2*4 8 5 9 8 14 8-6 push 9 push 5 pop 5 pop 9 push 9+5 pop 14 pop 8 push 8-14 c 2017, Algorithms and Data Structures Exercise I Exercise I 12/23
Trees Terminology A S M E P L Q T c 2017, Algorithms and Data Structures Exercise I Exercise I 13/23
Trees A S M E P L Terminology Node External node: leaf Internal node Edge Path Root Q T c 2017, Algorithms and Data Structures Exercise I Exercise I 14/23
Trees A N=number of nodes M=number of edges M=N-1 S M E P L Q T c 2017, Algorithms and Data Structures Exercise I Exercise I 15/23
Trees Implementing A B C D E F c 2017, Algorithms and Data Structures Exercise I Exercise I 16/23
Trees traversing methods A S M E P L Q T c 2017, Algorithms and Data Structures Exercise I Exercise I 17/23
Tree traversing methods S A M Preorder Inorder Postorder Level-Order E P N L X K Q T c 2017, Algorithms and Data Structures Exercise I Exercise I 18/23
Trees * A + B / C D c 2017, Algorithms and Data Structures Exercise I Exercise I 19/23
Huffman coding ABACCDA 010100010000000111010 21 bit Character D C B A Code 111 000 100 010 00010010101100 14 bit Character D C B A Code 11 10 01 00 0110010101110 13 bit Character D C B A Code 111 10 110 0 c 2017, Algorithms and Data Structures Exercise I Exercise I 20/23
Palindrome & Anagram madam m m a a d d a a m m c 2017, Algorithms and Data Structures Exercise I Exercise I 21/23
Assignment I Write a program that reads an infix expression as input, convert it to postfix expression and calculate the integer result. Return the postfix order and the integer result as output. Assume the infix expression is a string of tokens delimited by spaces. The operator tokens are *, /, +, and -. The operands are assumed to be single-digit integer values. Example: Enter an infix expression: 1 + 2-3 Postfix expression is: 1 2 + 3 - Evaluation of expression is: 0 Use array or linked list to implement the Stack and Queue. Deadline: 17. May 2017 23:59 Mailto: banafsheh.azari@uni-weimar.de Good luck! c 2017, Algorithms and Data Structures Exercise I Exercise I 22/23