ALGORITHMS & DATA STRUCTURES M. Antczak, S. Wąsik.
-
Upload
alejandro-wintle -
Category
Documents
-
view
213 -
download
0
Transcript of ALGORITHMS & DATA STRUCTURES M. Antczak, S. Wąsik.
ALGORITHMS & DATA STRUCTURES
M. Antczak, S. Wąsik
Static tables:
Character tables (string):
Static tables (2):
Pointers:
Steve Oualline , „Practical C Programming, 3rd Edition”, O’REILLY
*first_ptr = *second_ptr =
? ? 1 1
Pointers as Function arguments:
&
*
Const pointers:
Pointers as Arrays:
Steve Oualline , „Practical C Programming, 3rd Edition”, O’REILLY
*array_ptr == array[0]*(array_ptr + 1) == array[1]*(array_ptr + 2) == array[2]…
*(array_ptr) + 1 == array[1]
NO!
*(array_ptr) + 1 == array[0] + 1
OK!
Dynamic memory allocation:
Dynamic vector & matrix implementation:
New element addition:1) at beginning
One direction list:
3) at the end
2) in the middle
Selected element deletion:1) from the beginning
2) from the middle 3) from the end
Two direction list:
Stack (Last In – First Out) Queue (First In – First Out)
New element addition Head element deletion
New element addition
First element deletion
Let’s build the Binary Search Tree (BST) based on numbers sequence defined below:12, 18, 5, 19, 2, 15, 9, 17
<=
12
>
12 L 18<=12R 18>12
18
L 5<=12R 5>12
5
L 19<=12R 19>12L 19<=18R 19>18
19
L 2<=12R 2>12L 2<=5R 2>5
2
L 15<=12R 15>12L 15<=18R 15>18
15
L 9<=12R 9>12L 9<=5R 9>5
9
L 17<=12R 17>12L 17<=18R 17>18L 17<=15R 17>15
17
BST Searching:
Pre-order (wzdłużne): Root, Left Subtree, Right Subtree (R,LS,RS). In-order (poprzeczne): Left Subtree, Root, Right Subtree (LS,R,RS). Post-order (wsteczne): Left Subtree, Right Subtree, Root (LS,RS,R).
Pre-order : 12, 5, 2, 9, 18, 15, 17, 19. In-order: 2, 5, 9, 12, 15, 17, 18, 19. Post-order : 2, 9, 5, 17, 15, 19, 18, 12.
BST removing (e.g. 18):1) Maximal node from left subtree
MAX=17 2) Minimal node from right subtree
MIN=19
12
5
192 9
17
12
5
2 9
17
15
19
15
Basic list implementation: