DATA STRUCTURES + SORTING + STRING

Size: px
Start display at page:

Download "DATA STRUCTURES + SORTING + STRING"

Transcription

1 DATA STRUCTURES + SORTING + STRING COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book.

2 Comments Urgent => Contest Saturday VS ICPC. No details => Go over the topics on weekend. No overstress No overconfident.

3 Data Structure A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

4 Data Structure Basic data structures (built-in libraries). Linear DS. Non-Linear DS. Data structures (Own libraries). Graphs. Union-Find Structures. Segment Tree.

5 Data Structures Basic data structures (built-in libraries). Linear DS (ordering the elements sequentially). Static Array (Array in C/C++ and in Java). Resizeable array (C++ STL<vector> and Java ArrayList). Linked List: (C++ STL<list> and Java LinkedList). Stack (C++ STL<stack> and Java Stack). Queue (C++ STL <queue> and Java Queue).

6 Data Structures Basic data structures (built-in libraries). Non-Linear DS. Balanced Binary Search Tree (C++ STL <map>/<set> and in Java TreeMap/TreeSet). AVL and Red-Black Trees = Balanced BST <map> stores (key -> data) VS <set> only stores the key Heap(C++ STL<queue>:priority_queue and Java PriorityQueue). BST complete. Heap property VS BST protperty. Hash Table (Java HashMap/HashSet/HashTable). Non synchronized vs synchronized. Null vs non-nulls Predictable iteration vs non predictable.

7 Question for you. Basic data structures (built-in libraries). Non Linear DS (non-sequential ordering). Balanced Binary Search Tree (C++ STL <map>/<set> and Java TreeMap/TreeSet) AVL Tree and Red-Black = Balanced BST. <map> stores (key -> data) VS <set> only stores the key Heap (C++ STL <queue> and Java PriorityQueue) Heap property VS BST property. Complete BST. Hash table

8 Question for you. Basic data structures (built-in libraries). Non Linear DS (non-sequential ordering). Balanced Binary Search Tree (C++ STL <map>/<set> and Java TreeMap/TreeSet) AVL Tree and Red-Black = Balanced BST. <map> stores (key -> data) VS <set> only stores the key Heap (C++ STL <queue> and Java PriorityQueue) Heap property VS BST property. Complete BST. Hash table BST HEAP

9 Deciding the Order of the Tasks Returns the newest task (stack) Returns the oldest task (queue) Returns the most urgent task (priority queue) Returns the easiest task (priority queue)

10 STACK Last in, first out (Last In First Out) Stacks model piles of objects (such as dinner plates) Supports three constant-time operations Push(x): inserts x into the stack Pop(): removes the newest item Top(): returns the newest item Very easy to implement using an array

11 STACK Have a large enough array s[] and a counter k, which starts at zero Push(x) : set s[k] = x and increment k by 1 Pop() : decrement k by 1 Top() : returns s[k - 1] (error if k is zero) C++ and Java have implementations of stack stack (C++), Stack (Java)

12 STACK Useful for: Processing nested formulas Depth-first graph traversal Data storage in recursive algorithms

13 QUEUE First in, first out (FIFO) Supports three constant-time operations Enqueue(x) : inserts x into the queue Dequeue() : removes the oldest item Front() : returns the oldest item Implementation is similar to that of stack

14 QUEUE Assume that you know the total number of elements that enter the queue... which allows you to use an array for implementation If not, you can use linked lists or double linked lists Maintain two indices head and tail Dequeue() increments head Enqueue() increments tail Use the value of tail - head to check emptiness You can use queue (C++) and Queue (Java)

15 QUEUE Useful for implementing buffers simulating waiting lists shuffling cards

16 PRIORITY QUEUE Each element in a PQ has a priority value Three operations: Insert(x, p) : inserts x into the PQ, whose priority is p RemoveTop() : removes the element with the highest priority Top() : returns the element with the highest priority All operations can be done quickly if implemented using a heap (if not use a sorted array) priority_queue (C++), PriorityQueue (Java) Useful for Maintaining schedules / calendars Simulating events Sweepline geometric algorithms

17 HEAP Complete binary tree with the heap property: The value of a node values of its children What is the difference between full vs complete? The root node has the maximum value Constant-time top() operation Inserting/removing a node can be done in O(log n) time without breaking the heap property May need rearrangement of some nodes

18 HEAP Start from the root, number the nodes 1, 2,... from left to right Given a node k easy to compute the indices of its parent and children Parent node: floor(k/2) Children: 2k, 2k + 1

19 Heap Inserting a Node 1. Make a new node in the last level, as far left as possible If the last level is full, make a new one 2. If the new node breaks the heap property, swap with its parent node The new node moves up the tree, which may introduce another conflict Repeat 2 until all conflicts are resolved Running time = tree height = O(log n)

20 Heap Deleting a Node 1. Remove the root, and bring the last node (rightmost node in the last level) to the root 2. If the root breaks the heap property, look at its children and swap it with the larger one Swapping can introduce another conflict 3 Repeat 2 until all conflicts are resolved Running time = O(log n)

21 BINARY SEARCH TREE (BST) The idea behind is that each node has, at most, two children A binary tree with the following property: for each node v, value of v values in v s left subtree value of v < values in v s right subtree

22 BST Supports three operations Insert(x) : inserts a node with value x Delete(x) : deletes a node with value x, if there is any Find(x) : returns the node with value x, if there is any Many extensions are possible Count(x) : counts the number of nodes with value less than or equal to x GetNext(x) : returns the smallest node with value x

23 BST Simple implementation cannot guarantee efficiency In worst case, tree height becomes n (which makes BST useless) Guaranteeing O(log n) running time per operation requires balancing of the tree (hard to implement). For example AVL and Red-Black trees (We will skip the details of these balanced trees, but you should be review it.). What does balanced mean?? Use the standard library implementations set, map (C++) TreeSet, TreeMap (Java)

24 BST Simple implementation cannot guarantee efficiency In worst case, tree height becomes n (which makes BST useless) Guaranteeing O(log n) running time per operation requires balancing of the tree (hard to implement). For example AVL and Red-Black trees (We will skip the details of these balanced trees, but you should be review it.). What does balanced mean??=> The heights of the two child subtrees of anny node differ by at most one. Use the standard library implementations set, map (C++) TreeSet, TreeMap (Java)

25 Question for you Why a binary tree is preferable to an array of values that has been sorted? O(?) Finding a given key?

26 Question for you Why a binary tree is preferable to an array of values that has been sorted? O(log n) to find a given key => traversing BST and binary search. Problem is the adding of a new item.

27 Hash Tables A key is used as an index to locate the associated value. Content-based retrieval, unlike position-based retrieval. Hashing is the process of generating a key value. An ideal algorithm must distribute evenly the hash values => the buckets will tend to fill up evenly = fast search. A hash bucket containing more than one value is known as a collision. Open addressing => A simple rule to decide where to put a new item when the desired space is already occupied. Chaining => We associate a linked list with each table location. Hash tables are excellent dictionary data structures.

28 Hash Function A function that takes a string and outputs a number A good hash function has few collisions i.e., If x!= y, H(x)!= H(y) with high probability An easy and powerful hash function is a polynomial mod some prime p. Consider each letter as a number (ASCII value is fine) H(x1... xk) = x 1 a k 1 + x 2 a k xk 1 a + x k (mod p)

29 Data Structures Data structures (Own Libraries). Graph. Lets talk about graphs later. Union-Find Disjoint Sets Segment tree.

30 Union-Find Structure Used to store disjoint sets What is a disjoint set? Can support two types of operations efficiently Find(x) : returns the representative of the set that x belongs Union(x, y) : merges two sets that contain x and y Both operations can be done in (essentially) constant time Super-short implementation! Useful for problems involving partitioning. Ex: keeping track of connected components. Kruskal s algorithm (minimum spaning tree).

31 Union-Find Structure Used to store disjoint sets What is a disjoint set? => sets whose intersection is the empty set. Can support two types of operations efficiently Find(x) : returns the representative of the set that x belongs Union(x, y) : merges two sets that contain x and y Both operations can be done in (essentially) constant time Super-short implementation! Useful for problems involving partitioning. Ex: keeping track of connected components. Kruskal s algorithm (minimum spaning tree).

32 Union-Find Structure Main idea: represent each set by a rooted tree Every node maintains a link to its parent A root node is the representative of the corresponding set Example: two sets {x, y, z} and {a, b, c, d}

33 Union-Find Structure Find(x): follow the links from x until a node points itself This can take O(n) time but we will make it faster Union(x, y): run Find(x) and Find(y) to find corresponding root nodes and direct one to the other. If we assume that the links are stored in L[], then

34 Union-Find Structure In a bad case, the trees can become too deep... which slows down future operations Path compression makes the trees shallower every time Find() is called. We don t care how a tree looks like as long as the root stays the same After Find(x) returns the root, backtrack to x and reroute all the links to the root

35 Question for you How can you implement the operation issameset(i,j)?

36 Question for you How can you implement the operation issameset(i,j)? simply calls findset(i) and findset(j) to check if both refer to the same representative.

37 Segment Tree DS to efficiently answer dynamic range queries. Range Minimum Query (RMQ): finding the index of the minimum element in an array given a range: [i..j]. Ex. RMQ(1, 3) = 2, RMQ(3, 4) = 4, RMQ(0, 0) = 0, RMQ(0, 1) = 1, and RMQ(0, 6) = 5. Iterate takes O(n), let make it faster using a binary tree similar to heap, but usually not a complete binary tree (aka segment tree).

38 Segment Tree Binary tree. Each node is associated with some interval of the array. Each non-leaf node has two children whose associated intervals are disjoint. Each child s interval has approximately half the size of the parent s interval.

39 Segment Tree Root => [0, N 1] and for each segment [l,r] we split them into [l, (l + r) / 2] and [(l + r) / 2 + 1, r] until l = r.

40 Question for you What is the complexity of built_segment_tree O(?)? With segment tree ready, what is the complexity of answering an RMQ? Can you give the worst case? RMQ(?,?)

41 Question for you What is the complexity of built_segment_tree O(n) There are total 2n-1 nodes. With segment tree ready, what is the complexity of answering an RMQ => O(log n) (2 root-to-leaf paths) Ex RMQ(4,6) = blue line. Ex RMQ(1,3) = red line. Ex RMQ(3,4) = worst case => one path from [0,6] to [3,3] and another from [0,6] to [4,4].

42 Segment Tree If the array A is static, then use a Dynamic Programming solution that requires O(nlogn) pre-processing and O(1) per RMQ. Segment tree becomes useful if array A is frequently updated. Ex. Updating A[5] takes O(logn) vs O(nlogn) required by DP.

43 Fenwick Tree Full binary tree with at least n leaf nodes We will use n = 8 for our example kth leaf node stores the value of item k Each internal node stores the sum of values of its children e.g., Red node stores item[5] + item[6]

44 Summing Consecutive Values Main idea: choose the minimal set of nodes whose sum gives the desired value at most 1 node is chosen at each level so that the total number of nodes we look at is log 2 n and this can be done in O(log n) time

45 Summing Consecutive Values Sum(7) = sum of the values of gold-colored nodes.

46 Summing Consecutive Values Sum(8) = sum of the values of gold-colored nodes.

47 Summing Consecutive Values Sum(6) = sum of the values of gold-colored nodes.

48 Summing Consecutive Values Sum(3) = sum of the values of gold-colored nodes.

49 Summing Consecutive Values Say we want to compute Sum(k) Maintain a pointer P which initially points at leaf k Climb the tree using the following procedure: If P is pointing to a left child of some node: Add the value of P Set P to the parent node of P s left neighbor If P has no left neighbor, terminate Otherwise: Set P to the parent node of P Use an array to implement

50 Updating a Value Say we want to do Set(k, x) (set the value of leaf k as x) 1. Start at leaf k, change its value to x 2. Go to its parent, and recompute its value 3. Repeat 2 until the root

51 SORTING Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. In-place algorithms??? Stability. What happens to elements that are comparatively the same?

52 SORTING Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. In-place algorithms => without creating copies of the data Stability. What happens to elements that are comparatively the same? Those elements whose comparison key is the same will remain in the same relative order after sorting as they were before sorting.

53 Bubble Sort To pass through the data and swap two adjacent elements whenever the first is greater than the last. Thus, the smallest elements will bubble to the surface. O(n 2 ). Simple to understand and code from memory + Stable + In-place.

54 Insertion Sort It seeks to sort a list one element at a time. With each iteration, it takes the next element waiting to be sorted, and adds it, in proper location, to those elements that have already been sorted. O(n 2 ). it works very efficiently for lists that are nearly sorted initially

55 Merge Sort A merge sort works recursively (divide and conquer). Divide the unsorted list into n sublists, each containing 1 element. Then, merge sublists to produce new sorted sublists. O(n log n). Faily efficient + can be used to solve other problems.

56 Heap Sort All data from a list is inserted into a heap, and then the root element is repeatedly removed and stored back into the list. O(nlogn) Not stable

57 Quick Sort Divide the data into two groups of high values and low values. Then, recursively process the two halves. Finally, reassemble the now sorted list. O(n 2 ) dependent upon how successfully an accurate midpoint value is selected

58 Radix Sort Sort data without having to directly compare elements to each other. It groups keys by the individual digits which share the same significant position and value. O(n * k), where k is the size of the key. Some types of data may use very long keys, or may not easily lend itself to a representation that can be processed

59 Sorting Libraries Java API, and C++ STL all provide some built-in sorting capabilities. Check the interface called Comparable => you add a method int CompareTo (object other), which returns a negative value if less than, 0 if equal to, or a positive value if greater than the parameter. Also check the interface called Comparator. which defines a single method int Compare (object obj1, object obj2), which returns a value indicating the results of comparing the two parameters.

60 STRINGS

61 String Matching Problem Given a text T and a pattern P, find all occurrences of P within T Notations: n and m : lengths of P and T : set of alphabets (of constant size) Pi : i th letter of P (1-indexed) a, b, c : single letters in x, y, z : strings

62 String Matching Problem T = AGCATGCTGCAGTCATGCTTAGGCTA P = GCT P appears three times in T A naive method takes O(mn) time Initiate string comparison at every starting point Each comparison takes O(m) time We can do much better!

63 String Matching Problem - Hash Main idea: preprocess T to speedup queries Hash every substring of length k k is a small constant For each query P, hash the first k letters of P to retrieve all the occurrences of it within T Don t forget to check collisions!

64 String Matching Problem - Hash Pros: Easy to implement Significant speedup in practice Cons: Doesn t help the asymptotic efficiency Can still take O(nm) time if hashing is terrible or data is difficult Can you give me an example of the worst case? A lot of memory consumption

65 String Matching Problem - Hash Pros: Easy to implement Significant speedup in practice Cons: Doesn t help the asymptotic efficiency Can still take O(nm) time if hashing is terrible or data is difficult Can you give me an example of the worst case? => When all the characters of pattern and text are same. T=AAAAAAA P=AAA. A lot of memory consumption

66 SMP - Knuth-Morris-Pratt (KMP) A linear time (!) algorithm that solves the string matching problem by preprocessing P in O(m) time Main idea is to skip some comparisons by using the previous comparison result. Uses an auxiliary array π that is defined as the following: π[i] is the largest integer smaller than i such that P 1... P π [i] is a suffix of P 1... P i e.g., π[6] = 4 since abab is a suffix of ababab e.g., π[9] = 0 since no prefix of length 8 ends with c

67 Question for you Why is π useful?

68 SMP - Knuth-Morris-Pratt (KMP) T = ABC ABCDAB ABCDABCDABDE P = ABCDABD π = (0,0,0,0,1,2,0) Start matching at the first position of T: Mismatch at the 4th letter of P!

69 SMP - Knuth-Morris-Pratt (KMP) We matched k = 3 letters so far, and π[k] = 0 Thus, there is no point in starting the comparison at T2, T3 Shift P by k π[k] = 3 letters Mismatch at the 4th letter of P!

70 SMP - Knuth-Morris-Pratt (KMP) We matched k = 0 letters so far Shift P by k π[k] = 1 letter (we define π[0] = 1) Mismatch at T 11!

71 SMP - Knuth-Morris-Pratt (KMP) π[6] = 2 means P 1 P 2 is a suffix of P 1... P 6 Shift P by 6 π[6] = 4 letters Again, no point in shifting P by 1, 2, or 3 letters

72 SMP - Knuth-Morris-Pratt (KMP) Mismatch at T 11 again! Currently 2 letters are matched Shift P by 2 π[2] = 2 letters

73 SMP - Knuth-Morris-Pratt (KMP) Mismatch at T 11 again! Currently no letters are matched Shift P by 0 π[0] = 1 letter

74 SMP - Knuth-Morris-Pratt (KMP) Mismatch at T18 Currently 6 letters are matched Shift P by 6 π[6] = 4 letters

75 SMP - Knuth-Morris-Pratt (KMP) Finally, there it is! Currently all 7 letters are matched After recording this match (at T16... T22, we shift P again in order to find other matches Shift by 7 π[7] = 7 letters

76 SMP - Knuth-Morris-Pratt (KMP) Computing π. Obs1=> if P 1... P π[i] is a suffix of P 1... P i, then P 1... P π[i]-1 is a suffix of P 1... P i 1 Obs2 => all the prefixes of P that are a suffix of P 1... P i can be obtained by recursively applying to I e.g., P 1... P π[i], P 1..., P π[π[i]], P1...,, P π[π[π[i]]] are all suffixes of P 1... P i

77 SMP - Knuth-Morris-Pratt (KMP) Computing π. Obs3 (not obvious) => First, let s write π (k) [i] as π[.] applied k times to I e.g., π (2) [i] = π[π[i]] π[i] is equal to π (k) [i 1] + 1, where k is the smallest integer that satisfies P π(k)[i 1]+1 = P i If there is no such k, [i] = 0 Intuition: we look at all the prefixes of P that are suffixes of P 1... P i 1, and find the longest one whose next letter matches P i

78 SMP - Knuth-Morris-Pratt (KMP) Implementation π.

79 SMP - Knuth-Morris-Pratt (KMP) Implementation KMP.

80 SMP Suffix trie Suffix trie of a string T is a rooted tree that stores all the suffixes (thus all the substrings) Each node corresponds to some substring of T Each edge is associated with an alphabet For each node that corresponds to ax, there is a special pointer called suffix link that leads to the node corresponding to x Surprisingly easy to implement!

81 SMP Suffix trie

82 SMP Suffix trie Given the suffix tree for T 1... T n Then we append T n+1 = a to T, creating necessary nodes Start at node u corresponding to T 1... T n Create an a -transition to a new node v Take the suffix link at u to go to u, corresponding to T 2... T n Create an a -transition to a new node v Create a suffix link from v to v

83 SMP Suffix trie Repeat the previous process: Take the suffix link at the current node Make a new a-transition there Create the suffix link from the previous node Stop if the node already has an a-transition Because from this point, all nodes that are reachable via suffix links already have an a -transition

84 SMP Suffix trie Given the suffix trie for aba, we want to add a new letter c

85 SMP Suffix trie

86 SMP Suffix trie

87 SMP Suffix trie

88 SMP Suffix trie

89 SMP Suffix trie

90 SMP Suffix trie To find P, start at the root and keep following edges labeled with P 1, P 2, etc. Got stuck? Then P doesn t exist in T

91 SMP-Suffix Array

92 SMP Suffix Array Memory usage is O(n) Has the same computational power as suffix trie Can be constructed in O(n) time (!) But it s hard to implement

93 Notes Always be aware of the null-terminators Simple hash works so well in many problems If a problem involves rotations of some string, consider concatenating it with itself and see if it helps It is a smart idea to have the implementation of suffix arrays and KMP in your notebook.

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions.

Data Structure. A way to store and organize data in order to support efficient insertions, queries, searches, updates, and deletions. DATA STRUCTURES COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book. Data

More information

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms???

SORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms??? SORTING + STRING COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book.

More information

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42

String Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42 String Matching Pedro Ribeiro DCC/FCUP 2016/2017 Pedro Ribeiro (DCC/FCUP) String Matching 2016/2017 1 / 42 On this lecture The String Matching Problem Naive Algorithm Deterministic Finite Automata Knuth-Morris-Pratt

More information

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell Hash Tables CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 22, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005

More information

Module 2: Classical Algorithm Design Techniques

Module 2: Classical Algorithm Design Techniques Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

COMP 251 Winter 2017 Online quizzes with answers

COMP 251 Winter 2017 Online quizzes with answers COMP 251 Winter 2017 Online quizzes with answers Open Addressing (2) Which of the following assertions are true about open address tables? A. You cannot store more records than the total number of slots

More information

COMP Data Structures

COMP Data Structures COMP 2140 - Data Structures Shahin Kamali Topic 5 - Sorting University of Manitoba Based on notes by S. Durocher. COMP 2140 - Data Structures 1 / 55 Overview Review: Insertion Sort Merge Sort Quicksort

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION

Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION DESIGN AND ANALYSIS OF ALGORITHMS Unit 6 Chapter 15 EXAMPLES OF COMPLEXITY CALCULATION http://milanvachhani.blogspot.in EXAMPLES FROM THE SORTING WORLD Sorting provides a good set of examples for analyzing

More information

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)

More information

Sorting and Selection

Sorting and Selection Sorting and Selection Introduction Divide and Conquer Merge-Sort Quick-Sort Radix-Sort Bucket-Sort 10-1 Introduction Assuming we have a sequence S storing a list of keyelement entries. The key of the element

More information

Table of Contents. Chapter 1: Introduction to Data Structures... 1

Table of Contents. Chapter 1: Introduction to Data Structures... 1 Table of Contents Chapter 1: Introduction to Data Structures... 1 1.1 Data Types in C++... 2 Integer Types... 2 Character Types... 3 Floating-point Types... 3 Variables Names... 4 1.2 Arrays... 4 Extraction

More information

CS-301 Data Structure. Tariq Hanif

CS-301 Data Structure. Tariq Hanif 1. The tree data structure is a Linear data structure Non-linear data structure Graphical data structure Data structure like queue FINALTERM EXAMINATION Spring 2012 CS301- Data Structure 25-07-2012 2.

More information

UNIT III BALANCED SEARCH TREES AND INDEXING

UNIT III BALANCED SEARCH TREES AND INDEXING UNIT III BALANCED SEARCH TREES AND INDEXING OBJECTIVE The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions and finds in constant

More information

Course Review for Finals. Cpt S 223 Fall 2008

Course Review for Finals. Cpt S 223 Fall 2008 Course Review for Finals Cpt S 223 Fall 2008 1 Course Overview Introduction to advanced data structures Algorithmic asymptotic analysis Programming data structures Program design based on performance i.e.,

More information

Cpt S 223 Fall Cpt S 223. School of EECS, WSU

Cpt S 223 Fall Cpt S 223. School of EECS, WSU Course Review Cpt S 223 Fall 2012 1 Final Exam When: Monday (December 10) 8 10 AM Where: in class (Sloan 150) Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes

More information

Course Review. Cpt S 223 Fall 2010

Course Review. Cpt S 223 Fall 2010 Course Review Cpt S 223 Fall 2010 1 Final Exam When: Thursday (12/16) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

INSTITUTE OF AERONAUTICAL ENGINEERING

INSTITUTE OF AERONAUTICAL ENGINEERING INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad - 500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name Course Code Class Branch DATA STRUCTURES ACS002 B. Tech

More information

Final Examination CSE 100 UCSD (Practice)

Final Examination CSE 100 UCSD (Practice) Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam

More information

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND CSE 373 MAY 0 TH SPANNING TREES AND UNION FIND COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend COURSE LOGISTICS HW4 due tonight, if you want feedback by the weekend HW5 out tomorrow

More information

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix

Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Spring 2010 Review Topics Big O Notation Heaps Sorting Selection, Bubble, Insertion, Merge, Heap, Quick Bucket, Radix Hashtables Tree Balancing: AVL trees and DSW algorithm Graphs: Basic terminology and

More information

Advanced Set Representation Methods

Advanced Set Representation Methods Advanced Set Representation Methods AVL trees. 2-3(-4) Trees. Union-Find Set ADT DSA - lecture 4 - T.U.Cluj-Napoca - M. Joldos 1 Advanced Set Representation. AVL Trees Problem with BSTs: worst case operation

More information

Lecture Summary CSC 263H. August 5, 2016

Lecture Summary CSC 263H. August 5, 2016 Lecture Summary CSC 263H August 5, 2016 This document is a very brief overview of what we did in each lecture, it is by no means a replacement for attending lecture or doing the readings. 1. Week 1 2.

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 10: Search and Heaps MOUNA KACEM mouna@cs.wisc.edu Spring 2018 Search and Heaps 2 Linear Search Binary Search Introduction to trees Priority Queues Heaps Linear Search

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

End-Term Examination Second Semester [MCA] MAY-JUNE 2006

End-Term Examination Second Semester [MCA] MAY-JUNE 2006 (Please write your Roll No. immediately) Roll No. Paper Code: MCA-102 End-Term Examination Second Semester [MCA] MAY-JUNE 2006 Subject: Data Structure Time: 3 Hours Maximum Marks: 60 Note: Question 1.

More information

Chapter 7. Space and Time Tradeoffs. Copyright 2007 Pearson Addison-Wesley. All rights reserved.

Chapter 7. Space and Time Tradeoffs. Copyright 2007 Pearson Addison-Wesley. All rights reserved. Chapter 7 Space and Time Tradeoffs Copyright 2007 Pearson Addison-Wesley. All rights reserved. Space-for-time tradeoffs Two varieties of space-for-time algorithms: input enhancement preprocess the input

More information

O(n): printing a list of n items to the screen, looking at each item once.

O(n): printing a list of n items to the screen, looking at each item once. UNIT IV Sorting: O notation efficiency of sorting bubble sort quick sort selection sort heap sort insertion sort shell sort merge sort radix sort. O NOTATION BIG OH (O) NOTATION Big oh : the function f(n)=o(g(n))

More information

Programming II (CS300)

Programming II (CS300) 1 Programming II (CS300) Chapter 12: Heaps and Priority Queues MOUNA KACEM mouna@cs.wisc.edu Fall 2018 Heaps and Priority Queues 2 Priority Queues Heaps Priority Queue 3 QueueADT Objects are added and

More information

CS61BL. Lecture 5: Graphs Sorting

CS61BL. Lecture 5: Graphs Sorting CS61BL Lecture 5: Graphs Sorting Graphs Graphs Edge Vertex Graphs (Undirected) Graphs (Directed) Graphs (Multigraph) Graphs (Acyclic) Graphs (Cyclic) Graphs (Connected) Graphs (Disconnected) Graphs (Unweighted)

More information

Balanced Binary Search Trees. Victor Gao

Balanced Binary Search Trees. Victor Gao Balanced Binary Search Trees Victor Gao OUTLINE Binary Heap Revisited BST Revisited Balanced Binary Search Trees Rotation Treap Splay Tree BINARY HEAP: REVIEW A binary heap is a complete binary tree such

More information

Lecture 7. Transform-and-Conquer

Lecture 7. Transform-and-Conquer Lecture 7 Transform-and-Conquer 6-1 Transform and Conquer This group of techniques solves a problem by a transformation to a simpler/more convenient instance of the same problem (instance simplification)

More information

Algorithms and Data Structures Lesson 3

Algorithms and Data Structures Lesson 3 Algorithms and Data Structures Lesson 3 Michael Schwarzkopf https://www.uni weimar.de/de/medien/professuren/medieninformatik/grafische datenverarbeitung Bauhaus University Weimar May 30, 2018 Overview...of

More information

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019

CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees. Ruth Anderson Winter 2019 CSE 332: Data Structures & Parallelism Lecture 7: Dictionaries; Binary Search Trees Ruth Anderson Winter 2019 Today Dictionaries Trees 1/23/2019 2 Where we are Studying the absolutely essential ADTs of

More information

Priority Queues Heaps Heapsort

Priority Queues Heaps Heapsort Priority Queues Heaps Heapsort After this lesson, you should be able to apply the binary heap insertion and deletion algorithms by hand implement the binary heap insertion and deletion algorithms explain

More information

CSci 231 Final Review

CSci 231 Final Review CSci 231 Final Review Here is a list of topics for the final. Generally you are responsible for anything discussed in class (except topics that appear italicized), and anything appearing on the homeworks.

More information

COMP 103 Introduction to Data Structures and Algorithms

COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I VUW V I C T O R I A UNIVERSITY OF WELLINGTON Student ID:..................... EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data

More information

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015

BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015 BINARY HEAP cs2420 Introduction to Algorithms and Data Structures Spring 2015 1 administrivia 2 -assignment 10 is due on Thursday -midterm grades out tomorrow 3 last time 4 -a hash table is a general storage

More information

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305 Q.1 If h is any hashing function and is used to hash n keys in to a table of size m, where n

More information

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F].

Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F]. Question Assume you are given a Simple Linked List (i.e. not a doubly linked list) containing an even number of elements. For example L = [A B C D E F]. a) Draw the linked node structure of L, including

More information

Introduction to Competitive Programming. Instructor: William W.Y. Hsu

Introduction to Competitive Programming. Instructor: William W.Y. Hsu Introduction to Competitive Programming Instructor: William W.Y. Hsu CONTENTS Linear data structures and built-in libraries Array sorting and searching Non-linear data structures with built-in libraries

More information

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms

EXAMINATIONS 2005 END-YEAR. COMP 103 Introduction to Data Structures and Algorithms T E W H A R E W Ā N A N G A O T E Ū P O K O O T E I K A A M Ā U I ÎÍÏ V I C T O R I A UNIVERSITY OF WELLINGTON EXAMINATIONS 2005 END-YEAR COMP 103 Introduction to Data Structures and Algorithms Time Allowed:

More information

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1

Hash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Hash Open Indexing Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Consider a StringDictionary using separate chaining with an internal capacity of 10. Assume our buckets are implemented

More information

CSC 421: Algorithm Design Analysis. Spring 2017

CSC 421: Algorithm Design Analysis. Spring 2017 CSC 421: Algorithm Design Analysis Spring 2017 Transform & conquer transform-and-conquer approach presorting, balanced search trees, heaps, Horner's Rule problem reduction space/time tradeoffs heap sort,

More information

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014

CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up. Nicki Dell Spring 2014 CSE373: Data Structures & Algorithms Lecture 28: Final review and class wrap-up Nicki Dell Spring 2014 Final Exam As also indicated on the web page: Next Tuesday, 2:30-4:20 in this room Cumulative but

More information

Binary heaps (chapters ) Leftist heaps

Binary heaps (chapters ) Leftist heaps Binary heaps (chapters 20.3 20.5) Leftist heaps Binary heaps are arrays! A binary heap is really implemented using an array! 8 18 29 20 28 39 66 Possible because of completeness property 37 26 76 32 74

More information

Knuth-Morris-Pratt. Kranthi Kumar Mandumula Indiana State University Terre Haute IN, USA. December 16, 2011

Knuth-Morris-Pratt. Kranthi Kumar Mandumula Indiana State University Terre Haute IN, USA. December 16, 2011 Kranthi Kumar Mandumula Indiana State University Terre Haute IN, USA December 16, 2011 Abstract KMP is a string searching algorithm. The problem is to find the occurrence of P in S, where S is the given

More information

Department of Computer Science and Technology

Department of Computer Science and Technology UNIT : Stack & Queue Short Questions 1 1 1 1 1 1 1 1 20) 2 What is the difference between Data and Information? Define Data, Information, and Data Structure. List the primitive data structure. List the

More information

CS102 Binary Search Trees

CS102 Binary Search Trees CS102 Binary Search Trees Prof Tejada 1 To speed up insertion, removal and search, modify the idea of a Binary Tree to create a Binary Search Tree (BST) Binary Search Trees Binary Search Trees have one

More information

Solutions to Exam Data structures (X and NV)

Solutions to Exam Data structures (X and NV) Solutions to Exam Data structures X and NV 2005102. 1. a Insert the keys 9, 6, 2,, 97, 1 into a binary search tree BST. Draw the final tree. See Figure 1. b Add NIL nodes to the tree of 1a and color it

More information

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40%

CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% CS210 (161) with Dr. Basit Qureshi Final Exam Weight 40% Name ID Directions: There are 9 questions in this exam. To earn a possible full score, you must solve all questions. Time allowed: 180 minutes Closed

More information

Outline. Graphs. Divide and Conquer.

Outline. Graphs. Divide and Conquer. GRAPHS COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges books. Outline Graphs.

More information

- Alan Perlis. Topic 24 Heaps

- Alan Perlis. Topic 24 Heaps Topic 24 Heaps "You think you know when you can learn, are more sure when you can write even more when you can teach, but certain when you can program." - Alan Perlis Recall priority queue Priority Queue

More information

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1.

Thus, it is reasonable to compare binary search trees and binary heaps as is shown in Table 1. 7.2 Binary Min-Heaps A heap is a tree-based structure, but it doesn t use the binary-search differentiation between the left and right sub-trees to create a linear ordering. Instead, a binary heap only

More information

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2

CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 CMSC 341 Lecture 16/17 Hashing, Parts 1 & 2 Prof. John Park Based on slides from previous iterations of this course Today s Topics Overview Uses and motivations of hash tables Major concerns with hash

More information

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time

An AVL tree with N nodes is an excellent data. The Big-Oh analysis shows that most operations finish within O(log N) time B + -TREES MOTIVATION An AVL tree with N nodes is an excellent data structure for searching, indexing, etc. The Big-Oh analysis shows that most operations finish within O(log N) time The theoretical conclusion

More information

Data structures. Organize your data to support various queries using little time and/or space

Data structures. Organize your data to support various queries using little time and/or space Data structures Organize your data to support various queries using little time and/or space Given n elements A[1..n] Support SEARCH(A,x) := is x in A? Trivial solution: scan A. Takes time Θ(n) Best possible

More information

CSE373: Data Structures & Algorithms Lecture 4: Dictionaries; Binary Search Trees. Kevin Quinn Fall 2015

CSE373: Data Structures & Algorithms Lecture 4: Dictionaries; Binary Search Trees. Kevin Quinn Fall 2015 CSE373: Data Structures & Algorithms Lecture 4: Dictionaries; Binary Search Trees Kevin Quinn Fall 2015 Where we are Studying the absolutely essential ADTs of computer science and classic data structures

More information

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) _ UWNetID: Lecture Section: A CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will give

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)

COSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer) COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back

More information

Disclaimer. CS130A Winter 2008 Final Review. Information on the final exam. Suggestions

Disclaimer. CS130A Winter 2008 Final Review. Information on the final exam. Suggestions Disclaimer CS0 Winter 008 Final Review Shuo Wu Provided as is. Humanitarian purpose. Only served as a guideline/self-test for final preparation. Only a sketch/summary of important materials. You need to

More information

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs

Lecture 5. Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs Lecture 5 Treaps Find, insert, delete, split, and join in treaps Randomized search trees Randomized search tree time costs Reading: Randomized Search Trees by Aragon & Seidel, Algorithmica 1996, http://sims.berkeley.edu/~aragon/pubs/rst96.pdf;

More information

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader

CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, Problem Topic Points Possible Points Earned Grader CSE100 Practice Final Exam Section C Fall 2015: Dec 10 th, 2015 Problem Topic Points Possible Points Earned Grader 1 The Basics 40 2 Application and Comparison 20 3 Run Time Analysis 20 4 C++ and Programming

More information

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions.

CS251-SE1. Midterm 2. Tuesday 11/1 8:00pm 9:00pm. There are 16 multiple-choice questions and 6 essay questions. CS251-SE1 Midterm 2 Tuesday 11/1 8:00pm 9:00pm There are 16 multiple-choice questions and 6 essay questions. Answer the multiple choice questions on your bubble sheet. Answer the essay questions in the

More information

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS

EXAMINATIONS 2015 COMP103 INTRODUCTION TO DATA STRUCTURES AND ALGORITHMS T E W H A R E W Ā N A N G A O T E Student ID:....................... Ū P O K O O T E I K A A M Ā U I VUW VICTORIA U N I V E R S I T Y O F W E L L I N G T O N EXAMINATIONS 2015 TRIMESTER 2 COMP103 INTRODUCTION

More information

Dictionaries. Priority Queues

Dictionaries. Priority Queues Red-Black-Trees.1 Dictionaries Sets and Multisets; Opers: (Ins., Del., Mem.) Sequential sorted or unsorted lists. Linked sorted or unsorted lists. Tries and Hash Tables. Binary Search Trees. Priority Queues

More information

CS 8391 DATA STRUCTURES

CS 8391 DATA STRUCTURES DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING QUESTION BANK CS 8391 DATA STRUCTURES UNIT- I PART A 1. Define: data structure. A data structure is a way of storing and organizing data in the memory for

More information

8. Binary Search Tree

8. Binary Search Tree 8 Binary Search Tree Searching Basic Search Sequential Search : Unordered Lists Binary Search : Ordered Lists Tree Search Binary Search Tree Balanced Search Trees (Skipped) Sequential Search int Seq-Search

More information

CS 61B Midterm 2 Guerrilla Section Spring 2018 March 17, 2018

CS 61B Midterm 2 Guerrilla Section Spring 2018 March 17, 2018 CS 61B Midterm 2 Guerrilla Section Spring 2018 March 17, 2018 Instructions Form a small group. Start on the first problem. Check off with a helper or discuss your solution process with another group once

More information

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course

CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course Today s Topics Review Uses and motivations of hash tables Major concerns with hash tables Properties Hash function Hash

More information

Indexing and Searching

Indexing and Searching Indexing and Searching Introduction How to retrieval information? A simple alternative is to search the whole text sequentially Another option is to build data structures over the text (called indices)

More information

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting)

IS 709/809: Computational Methods in IS Research. Algorithm Analysis (Sorting) IS 709/809: Computational Methods in IS Research Algorithm Analysis (Sorting) Nirmalya Roy Department of Information Systems University of Maryland Baltimore County www.umbc.edu Sorting Problem Given an

More information

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012

CMPSCI 187: Programming With Data Structures. Review for Final Exam David Mix Barrington 10 December 2012 CMPSCI 187: Programming With Data Structures Review for Final Exam David Mix Barrington 10 December 2012 Exam Overview Thursday 13 December, 1:30-3:30 p.m., Marcus 131 Format is the same as the Fall 2011

More information

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology

9/29/2016. Chapter 4 Trees. Introduction. Terminology. Terminology. Terminology. Terminology Introduction Chapter 4 Trees for large input, even linear access time may be prohibitive we need data structures that exhibit average running times closer to O(log N) binary search tree 2 Terminology recursive

More information

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II

CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II Review from Lecture 22 CSCI-1200 Data Structures Fall 2018 Lecture 23 Priority Queues II Using STL s for_each, Function Objects, a.k.a., Functors STL s unordered_set (and unordered_map) Hash functions

More information

Exact String Matching. The Knuth-Morris-Pratt Algorithm

Exact String Matching. The Knuth-Morris-Pratt Algorithm Exact String Matching The Knuth-Morris-Pratt Algorithm Outline for Today The Exact Matching Problem A simple algorithm Motivation for better algorithms The Knuth-Morris-Pratt algorithm The Exact Matching

More information

CS521 \ Notes for the Final Exam

CS521 \ Notes for the Final Exam CS521 \ Notes for final exam 1 Ariel Stolerman Asymptotic Notations: CS521 \ Notes for the Final Exam Notation Definition Limit Big-O ( ) Small-o ( ) Big- ( ) Small- ( ) Big- ( ) Notes: ( ) ( ) ( ) ( )

More information

CSC 421: Algorithm Design Analysis. Spring 2013

CSC 421: Algorithm Design Analysis. Spring 2013 CSC 421: Algorithm Design Analysis Spring 2013 Transform & conquer transform-and-conquer approach presorting balanced search trees, heaps Horner's Rule problem reduction 1 Transform & conquer the idea

More information

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms...

Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms... Second Semester - Question Bank Department of Computer Science Advanced Data Structures and Algorithms.... Q1) Let the keys are 28, 47, 20, 36, 43, 23, 25, 54 and table size is 11 then H(28)=28%11=6; H(47)=47%11=3;

More information

CS 445: Data Structures Final Examination: Study Guide

CS 445: Data Structures Final Examination: Study Guide CS 445: Data Structures Final Examination: Study Guide Java prerequisites Classes, objects, and references Access modifiers Arguments and parameters Garbage collection Self-test questions: Appendix C Designing

More information

CS8391-DATA STRUCTURES

CS8391-DATA STRUCTURES ST.JOSEPH COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERI NG CS8391-DATA STRUCTURES QUESTION BANK UNIT I 2MARKS 1.Explain the term data structure. The data structure can be defined

More information

Binary Heaps. COL 106 Shweta Agrawal and Amit Kumar

Binary Heaps. COL 106 Shweta Agrawal and Amit Kumar Binary Heaps COL Shweta Agrawal and Amit Kumar Revisiting FindMin Application: Find the smallest ( or highest priority) item quickly Operating system needs to schedule jobs according to priority instead

More information

W4231: Analysis of Algorithms

W4231: Analysis of Algorithms W4231: Analysis of Algorithms 10/5/1999 (revised 10/6/1999) More hashing Binomial heaps Lectures Next Week No Lecture Tues. October 12 and Thurs. October 14. Extra lecture (2 1 2 hours) on Mon. October

More information

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad -500 043 COMPUTER SCIENCE AND ENGINEERING TUTORIAL QUESTION BANK Course Name : DATA STRUCTURES Course Code : A30502 Class : II B.

More information

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs

Graphs and Network Flows ISE 411. Lecture 7. Dr. Ted Ralphs Graphs and Network Flows ISE 411 Lecture 7 Dr. Ted Ralphs ISE 411 Lecture 7 1 References for Today s Lecture Required reading Chapter 20 References AMO Chapter 13 CLRS Chapter 23 ISE 411 Lecture 7 2 Minimum

More information

Sorting Algorithms. + Analysis of the Sorting Algorithms

Sorting Algorithms. + Analysis of the Sorting Algorithms Sorting Algorithms + Analysis of the Sorting Algorithms Insertion Sort What if first k elements of array are already sorted? 4, 7, 12, 5, 19, 16 We can shift the tail of the sorted elements list down and

More information

Range Queries. Kuba Karpierz, Bruno Vacherot. March 4, 2016

Range Queries. Kuba Karpierz, Bruno Vacherot. March 4, 2016 Range Queries Kuba Karpierz, Bruno Vacherot March 4, 2016 Range query problems are of the following form: Given an array of length n, I will ask q queries. Queries may ask some form of question about a

More information

Algorithms: Design & Practice

Algorithms: Design & Practice Algorithms: Design & Practice Deepak Kumar Bryn Mawr College Spring 2018 Course Essentials Algorithms Design & Practice How to design Learn some good ones How to implement practical considerations How

More information

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge

! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every

More information

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Name: Email address: Quiz Section: CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will

More information

Final Exam. EECS 2011 Prof. J. Elder - 1 -

Final Exam. EECS 2011 Prof. J. Elder - 1 - Final Exam Ø Wed Apr 11 2pm 5pm Aviva Tennis Centre Ø Closed Book Ø Format similar to midterm Ø Will cover whole course, with emphasis on material after midterm (maps and hash tables, binary search, loop

More information

CMSC 341 Lecture 14: Priority Queues, Heaps

CMSC 341 Lecture 14: Priority Queues, Heaps CMSC 341 Lecture 14: Priority Queues, Heaps Prof. John Park Based on slides from previous iterations of this course Today s Topics Priority Queues Abstract Data Type Implementations of Priority Queues:

More information

Section 05: Solutions

Section 05: Solutions Section 05: Solutions 1. Memory and B-Tree (a) Based on your understanding of how computers access and store memory, why might it be faster to access all the elements of an array-based queue than to access

More information

Recitation 9. Prelim Review

Recitation 9. Prelim Review Recitation 9 Prelim Review 1 Heaps 2 Review: Binary heap min heap 1 2 99 4 3 PriorityQueue Maintains max or min of collection (no duplicates) Follows heap order invariant at every level Always balanced!

More information

Question Bank Subject: Advanced Data Structures Class: SE Computer

Question Bank Subject: Advanced Data Structures Class: SE Computer Question Bank Subject: Advanced Data Structures Class: SE Computer Question1: Write a non recursive pseudo code for post order traversal of binary tree Answer: Pseudo Code: 1. Push root into Stack_One.

More information

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University

Cpt S 223 Course Overview. Cpt S 223, Fall 2007 Copyright: Washington State University Cpt S 223 Course Overview 1 Course Goals Learn about new/advanced data structures Be able to make design choices on the suitable data structure for different application/problem needs Analyze (objectively)

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information