The.Algorithm.Design.Manual.Springer-Verlag.1998
The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998
Lecture 7 - elementary data structures ● Next(S,x), Previous(S,x) - Given an element x whose key is from a totally ordered set S, returns the next largest (smallest) element in S, or NIL if x is the maximum (minimum) element. Listen To Part 7-9 Pointer Based Implementation We can maintain a dictionary in either a singly or doubly linked list. We gain extra flexibility on predecessor queries at a cost of doubling the number of pointers by using doublylinked lists. Since the extra big-Oh costs of doubly-linkly lists is zero, we will usually assume they are, although it might not be necessary. Singly linked to doubly-linked list is as a Conga line is to a Can-Can line. Array Based Sets Unsorted Arrays ● Search(S,k) - sequential search, O(n) ● Insert(S,x) - place in first empty spot, O(1) ● Delete(S,x) - copy nth item to the xth spot, O(1) ● Min(S,x), Max(S,x) - sequential search, O(n) ● Successor(S,x), Predecessor(S,x) - sequential search, O(n) Listen To Part 7-10 Sorted Arrays ● Search(S,k) - binary search, ● Insert(S,x) - search, then move to make space, O(n) ● Delete(S,x) - move to fill up the hole, O(n) ● Min(S,x), Max(S,x) - first or last element, O(1) ● Successor(S,x), Predecessor(S,x) - Add or subtract 1 from pointer, O(1) What are the costs for a heap? file:///E|/LEC/LECTUR17/NODE7.HTM (6 of 13) [19/1/2003 1:34:42]
Lecture 7 - elementary data structures Listen To Part 7-11 LIST-SEARCH(L, k) x = head[L] Unsorted List Implementation while x NIL and key[x] k return x do x = next[x] Note: the while loop might require two lines in some programming languages. LIST-INSERT(L, x) next[x] = head[L] if head[L] NIL head[L] = x file:///E|/LEC/LECTUR17/NODE7.HTM (7 of 13) [19/1/2003 1:34:42] then prev[head[L]] = x
- Page 857 and 858: Lecture 2 - asymptotic notation alg
- Page 859 and 860: Lecture 2 - asymptotic notation Sup
- Page 861 and 862: Lecture 2 - asymptotic notation Nex
- Page 863 and 864: Lecture 3 - recurrence relations Is
- Page 865 and 866: Lecture 3 - recurrence relations
- Page 867 and 868: Lecture 3 - recurrence relations Li
- Page 869 and 870: Lecture 3 - recurrence relations Su
- Page 871 and 872: Lecture 3 - recurrence relations A
- Page 873 and 874: Lecture 4 - heapsort Note iteration
- Page 875 and 876: Lecture 4 - heapsort The convex hul
- Page 877 and 878: Lecture 4 - heapsort 1. All leaves
- Page 879 and 880: Lecture 4 - heapsort left = 2i righ
- Page 881 and 882: Lecture 4 - heapsort Since this sum
- Page 883 and 884: Lecture 4 - heapsort Selection sort
- Page 885 and 886: Lecture 4 - heapsort Greedy Algorit
- Page 887 and 888: Lecture 5 - quicksort Partitioning
- Page 889 and 890: Lecture 5 - quicksort Listen To Par
- Page 891 and 892: Lecture 5 - quicksort Listen To Par
- Page 893 and 894: Lecture 5 - quicksort The worst cas
- Page 895 and 896: Lecture 5 - quicksort Mon Jun 2 09:
- Page 897 and 898: Lecture 6 - linear sorting Since 2i
- Page 899 and 900: Lecture 6 - linear sorting With uni
- Page 901 and 902: Lecture 6 - linear sorting Listen T
- Page 903 and 904: Lecture 7 - elementary data structu
- Page 905 and 906: Lecture 7 - elementary data structu
- Page 907: Lecture 7 - elementary data structu
- Page 911 and 912: Lecture 7 - elementary data structu
- Page 913 and 914: Lecture 7 - elementary data structu
- Page 915 and 916: Lecture 7 - elementary data structu
- Page 917 and 918: Lecture 8 - binary trees - Joyce Ki
- Page 919 and 920: Lecture 8 - binary trees TREE-MINIM
- Page 921 and 922: Lecture 8 - binary trees Inorder-Tr
- Page 923 and 924: Lecture 8 - binary trees Listen To
- Page 925 and 926: Lecture 8 - binary trees insert(b)
- Page 927 and 928: Lecture 8 - binary trees Not (1) -
- Page 929 and 930: Lecture 9 - catch up Next: Lecture
- Page 931 and 932: Lecture 10 - tree restructuring 1.
- Page 933 and 934: Lecture 10 - tree restructuring Lis
- Page 935 and 936: Lecture 10 - tree restructuring Not
- Page 937 and 938: Lecture 10 - tree restructuring Cas
- Page 939 and 940: Lecture 11 - backtracking Next: Lec
- Page 941 and 942: Lecture 11 - backtracking Only 63 s
- Page 943 and 944: Lecture 11 - backtracking Recursion
- Page 945 and 946: Lecture 11 - backtracking Specifica
- Page 947 and 948: Lecture 12 - introduction to dynami
- Page 949 and 950: Lecture 12 - introduction to dynami
- Page 951 and 952: Lecture 12 - introduction to dynami
- Page 953 and 954: Lecture 12 - introduction to dynami
- Page 955 and 956: Lecture 12 - introduction to dynami
- Page 957 and 958: Lecture 13 - dynamic programming ap
Lecture 7 - elementary data structures<br />
● Next(S,x), Previous(S,x) - Given an element x whose key is from a totally ordered set S, returns the next<br />
largest (smallest) element in S, or NIL if x is the maximum (minimum) element.<br />
Listen To Part 7-9<br />
Pointer Based Implementation<br />
We can maintain a dictionary in either a singly or doubly linked list.<br />
We gain extra flexibility on predecessor queries at a cost of doubling the number of pointers by using doublylinked<br />
lists.<br />
Since the extra big-Oh costs of doubly-linkly lists is zero, we will usually assume they are, although it might not be<br />
necessary.<br />
Singly linked to doubly-linked list is as a Conga line is to a Can-Can line.<br />
Array Based Sets<br />
Unsorted Arrays<br />
● Search(S,k) - sequential search, O(n)<br />
● Insert(S,x) - place in first empty spot, O(1)<br />
● Delete(S,x) - copy nth item to the xth spot, O(1)<br />
● Min(S,x), Max(S,x) - sequential search, O(n)<br />
● Successor(S,x), Predecessor(S,x) - sequential search, O(n)<br />
Listen To Part 7-10<br />
Sorted Arrays<br />
● Search(S,k) - binary search,<br />
● Insert(S,x) - search, then move to make space, O(n)<br />
● Delete(S,x) - move to fill up the hole, O(n)<br />
● Min(S,x), Max(S,x) - first or last element, O(1)<br />
● Successor(S,x), Predecessor(S,x) - Add or subtract 1 from pointer, O(1)<br />
What are the costs for a heap?<br />
file:///E|/LEC/LECTUR17/NODE7.HTM (6 of 13) [19/1/2003 1:34:42]