# Introduction to Data Structures and Algorithms

Save this PDF as:

Size: px
Start display at page:

## Transcription

1 Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, Erlangen

2 Overview on simple data structures for representing dynamic sets of data records Main operations on these data structures are Insertion and deletion of an element searching for an element finding the minimum or maximum element finding the successor or the predecessor of an element And similar operations These data structures are often implemented using dynamically allocated objects and pointers Data Structures and Algorithms (132)

3 Typical Examples of Elementary Data Structures Array Stack Queue Linked List Tree Data Structures and Algorithms (133)

4 Stack A stack implements the LIFO (last-in, first-out) policy like a stack of plates, where you can either place an extra plate at the top or remove the topmost plate For a stack, the insert operation is called Push and the delete operation is called Pop Data Structures and Algorithms (134)

5 Where are Stacks used? A call stack that is used for the proper execution of a computer program with subroutine or function calls Analysis of context free languages (e.g. properly nested brackets) Properly nested: (()(()())), Wrongly nested: (()((()) Reversed Polish notation of terms Compute 2 + 3*5 2 Push 3 Push 5 * + Data Structures and Algorithms (135)

6 Properties of a Stack Stacks can be defined by axioms based on the stack operations, i.e. a certain data structure is a stack if the respective axioms hold For illustration some examples for such axioms - the typical axioms are (where S is a Stack which can hold elements x of some set X) If not full(s): Pop(S) o (Push(S,x)) = x for all x X If not empty(s): Push(S, Pop(S)) = S Data Structures and Algorithms (136)

7 Typical Implementation of a Stack A typical implementation of a stack of size n is based on an array S[1 n] so it can hold at most n elements top(s) is the index of the most recently inserted element Push Pop The stack consists of elements S[1 top(s)], where S[1] is the element at the bottom of the stack, and S[top(S)] is the element at the top. The unused elements S[top(S)+1 n] are not in the stack Top S Data Structures and Algorithms (137)

8 Stack If top(s) = 0 the stack is empty no element can be popped If top(s) = n the stack is full no further element can be pushed Data Structures and Algorithms (138)

9 Example (Stack Manipulation) S Start with stack given, denote changes of stack state 7 6 Push(S, 17) Pop(S), Pop(S), Pop(S), Push(S, 5) 5 Pop(S), Pop(S) Pop(S) top(s) Data Structures and Algorithms (139)

10 pop (S) 17 pop (S) 3 push(s,17) pop (S) 23 pop (S) 5 push(s,5) pop (S) 3 S: S: S: S: pop (S) Error: underflow Top[S]=3 5 4 Top= Top= Top=0 Data Structures and Algorithms (140)

11 Pseudo Code for Stack Operations Number of elements NumElements (S) return top[s] Data Structures and Algorithms (141)

12 Pseudo Code for Stack Operations Test for emptiness Stack_Empty(S) if top[s]=0 then return true else return false Test for stack full Stack_Full (S) if top[s]=n then return true else return false Data Structures and Algorithms (142)

13 Pseudo Code for Stack Operations Pushing and Popping Push(S,x) if Stack_Full(S) then error "overflow" else top[s] := top[s]+1 S[top[S]] := x Pop(S) if Stack_Empty(S) then error "underflow" else top[s] := top[s]-1 return S[top[S]+1] This pseudo code contains error handling functionality Data Structures and Algorithms (143)

14 Pseudo Code for Stack Operations (Asymptotic) Runtime NumElements: number of operations independent of size n of stack constant O(1) Stack_Empty and Stack_Full: number of operations independent of size n of stack constant O(1) Push and Pop: number of operations independent of size n of stack constant O(1) Data Structures and Algorithms (144)

15 Queue A queue implements the FIFO (first-in, first-out) policy Like a line of people at the post office or in a shop enqueue dequeue For a queue, tail head the insert operation is called Enqueue (=> place at the tail of the queue) and the delete operation is called Dequeue (=> take from the head of the queue) Data Structures and Algorithms (145)

16 Where are Queues used? In multi-tasking systems (communication, synchronization) In communication systems (store-and-forward networks) In servicing systems (queue in front of the servicing unit) Queuing networks (performance evaluation of computer and communication networks) Data Structures and Algorithms (146)

17 Typical Implementation of a Queue A typical implementation of a queue consisting of at most n-1 elements is based on an array Q[1 n] Its attribute head(q) points to the head of the queue. Its attribute tail(q) points to the position where a new element will be inserted into the queue (i.e. one position behind the last element of the queue). The elements in the queue are in positions head(q), head(q)+1,, tail(q)-1, where we wrap around the array boundary in the sense that Q[1] immediately follows Q[n] Data Structures and Algorithms (147)

18 Example (1) Q (n = length (Q) = 10) Insert a new element (4.) head(q) tail(q) Q head(q) tail(q) Data Structures and Algorithms (148)

19 Example (2) Q Insert one more element (5.) head(q) tail(q) Q tail(q) head(q) And again: Insert one more element (6.) Q tail(q) head(q) Data Structures and Algorithms (149)

20 Typical Implementation of a Queue Number of elements in queue If tail > head: NumElements(Q) = tail - head If tail < head: NumElements(Q) = tail head + n If tail = head: NumElements(Q) = 0 Initially: head[q] = tail[q] = 1 Position of elements in queue The x. element of a queue Q (1 x NumElements(Q) is mapped to array position head(q) + (x - 1) if x n head +1 (no wrap around) head(q) + (x - 1) - n if x > n head +1 (wrap around) Data Structures and Algorithms (150)

21 Typical Implementation of a Queue Remark: A queue implemented by a n-element array can hold at most n-1 elements otherwise we could not distinguish between an empty and a full queue A queue Q is empty: ( NumElements(Q) = 0) if head(q) = tail(q) A queue Q is full: ( NumElements(Q) = n-1) if head(q) = (tail(q) + 1) (head(q) > tail(q)) if head(q) = (tail(q) - n + 1) (head(q) < tail(q)) Data Structures and Algorithms (151)

22 Example (Queue Manipulation) Q head(q) tail(q) Start with queue given, denote changes of queue state Enqueue(Q, 2), Enqueue(Q, 3), Enqueue(Q, 7) Dequeue(Q) Data Structures and Algorithms (152)

23 Queue Operations Enqueue and Dequeue This pseudo code does not contain error handling functionality (see stack push and pop) Enqueue(Q,x) Q[tail[Q]] := x Precondition: queue not full if tail[q]=length[q] then tail[q] := 1 else tail[q] := tail[q]+1 Dequeue(Q) Precondition: queue not empty x := Q[head[Q]] if head[q]=length[q] then head[q] := 1 else head[q] := head[q]+1 return x Data Structures and Algorithms (153)

24 Pseudo Code for Queue Operations (Asymptotic) Runtime Enqueue and Dequeue: number of operations independent of size n of queue constant O(1) Data Structures and Algorithms (154)

25 Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(2) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, Erlangen

26 Typical Examples of Elementary Data Structures Array Stack Queue Linked List Tree Data Structures and Algorithms (156)

27 Linked List In a linked list, the elements are arranged in a linear order, i.e. each element (except the first one) has a predecessor and each element (except the last one) has a successor. Unlike an array, elements are not addressed by an index, but by a pointer (a reference). There are singly linked lists and doubly linked lists. A list may be sorted or unsorted. A list may be circular (i.e. a ring of elements). Here we consider mainly unsorted, doubly linked lists Data Structures and Algorithms (157)

28 Linked List Each element x of a (doubly) linked list has three fields A pointer prev to the previous element A pointer next to the next element A field that contains a key (value of a certain type) Possibly a field that contains satellite data (ignored in the following) One element x : (consist of 3 fields) prev key next Pointer fields that contain no pointer pointing to another element contain the special pointer NIL ( ) The pointer head[l] points to the first element of the linked list If head[l] = NIL the list L is an empty list Data Structures and Algorithms (158)

29 Linked List In a linked list, the insert operation is called List_Insert, and the delete operation is called List_Delete. In a linked list we may search for an element with a certain key k by calling List_Search. Linked List Example: dynamic set {11, 2,7, 13} prev key next head[l] Notice: prev[head] = NIL and next[tail] = NIL Data Structures and Algorithms (159)

30 Some Examples for the Use of Linked Lists Lists of passengers of a plane or a hotel Card games (sorting cards corresponding to a certain order, inserting new cards into or removing cards out of the sequence) To-do lists (containing entries for actions to be done) Hash Lists ( Hashing, dealt later in this lecture) Data Structures and Algorithms (160)

31 Searching a Linked List The procedure List_search (L, k) finds the first element with key k in list L and returns a pointer to that element. If no element with key k is found, the special pointer NIL is returned. List_Search(L,k) x := head[l] while x!=nil and key[x]!=k do x := next[x] return x It takes at most Θ(n) time to search a list of n objects (linear search) Data Structures and Algorithms (161)

32 Inserting into a Linked List The procedure List_insert(L,x) inserts a new element x as the new head of list L List_Insert(L,x) next[x] := head[l] if head[l]!=nil then prev[head[l]] := x head[l] := x prev[x] := NIL x key(x) head[l] The runtime for List_Insert on a list of length n is constant (O(1)) Data Structures and Algorithms (162)

33 Deleting from a Linked List The procedure List_Delete (L, x) removes an element x from the linked list L, where the element is given by a pointer to x. If you want to delete an element given by its key k, you have to compute a pointer to this element (e.g. by using List_search(L, k)) List_Delete(L,x) if prev[x]!=nil x not the first element then next[prev[x]] := next[x] else head[l] := next[x] if next[x]!=nil x not the last element then prev[next[x]] := prev[x] Data Structures and Algorithms (163)

34 Deleting from a Linked List a) a) b) head[l] List_Delete(L,x) if prev[x]!=nil then next[prev[x]] := next[x] else head[l] := next[x] if next[x]!=nil then prev[next[x]] := prev[x] x b) head[l] x Data Structures and Algorithms (164)

35 Deleting from a Linked List The runtime for List_Delete on a list of length n is constant (O(1)) If you want to delete an element with a certain key, you must first find that element by executing List_Search, which takes Θ(n) time in the worst case Data Structures and Algorithms (165)

36 Inserting and deleting : head[l] List_insert (L,x) with key[x] = 25 head[l] List_Delete (L,x) where x points to element with key[x] = 2 head[l] Data Structures and Algorithms (166)

37 Tree Any data structure consisting of elements of the same type can be represented with the help of pointers (in a similar way as we implemented lists). Very important examples of such data structures are trees. Trees are graphs that contain no cycle: every non-trivial path through a tree starting at a node and ending in the same node, does traverse at least one edge at least twice. There exist many kinds of trees. Examples are: Binary trees Trees with unbounded branching Binary search trees Red-black trees Data Structures and Algorithms (167)

38 Some Examples for the Use of Trees Systematically exploring various ways of proceeding (e.g. in chess or planning games) Morse trees (coding trees) Heaps ( heap sort) Search trees Data Structures and Algorithms (168)

39 Tree A binary tree consists of nodes with the following fields A key field Possibly some satellite data (ignored in the following) Three pointers p, left and right pointing to the parent node, left child node and right child node Be x an element (or node) of a tree If p[x] = NIL x represents the root node If both left[x] = NIL and right[x] = NIL x represents a leaf node For each tree T there is a pointer root[t] that points to the root of T If root[t] = NIL, the tree T is empty Data Structures and Algorithms (169)

40 Binary Tree (Example) p key (+ s.d.) left right Data Structures and Algorithms (170)

41 P-nary Trees The above scheme can be extended to any class of trees where the number of children is bounded by some constant k : child1,, child k a bit of memory space may be wasted for pointers which are not actually used k Trees with unbounded branching A tree with unbounded branching (if no upper bound on the number of a node's children is known a priori) can be implemented by the following scheme: Each node has a key field (and possibly some satellite data), and three pointers p, left_child and right_sibling In a leaf node, left_child=nil If a node is the rightmost child of its parent, then right_sibling=nil Data Structures and Algorithms (171)

42 Unbounded Tree (Example) p key (+ s.d.) l_child r_sibl Data Structures and Algorithms (172)

43 Unbounded Tree (Example) leaves Data Structures and Algorithms (173)

### Stacks, Queues and Linked Lists

Stacks, Queues and Linked Lists Adnan Aziz 1 Dynamic sets CLRS Part III, page 197 In mathematics, a set is a well-defined collection of elements (elements could be numbers, functions, geometric shapes);

### \Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,

Elementary Data Structures \Mankinds's progress is measured by the number of things we can do without thinking." Elementary data structures such as stacks, queues, lists, and heaps will be the \of-the-shelf"

### TIE-20106 1 TIE-20106 2

TIE-20106 1 1 List structures In this chapter, a few simple data structures (stack and queue) that can be implemented with arrays and/or lists are covered. Two more complex structures based on lists are

### Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Chapter: Binary Search Trees Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Search Trees Search trees can be used

### Data Structure [Question Bank]

Unit I (Analysis of Algorithms) 1. What are algorithms and how they are useful? 2. Describe the factor on best algorithms depends on? 3. Differentiate: Correct & Incorrect Algorithms? 4. Write short note:

### Algorithms Chapter 12 Binary Search Trees

Algorithms Chapter 1 Binary Search Trees Outline Assistant Professor: Ching Chi Lin 林 清 池 助 理 教 授 chingchi.lin@gmail.com Department of Computer Science and Engineering National Taiwan Ocean University

### 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

### Sequential Data Structures

Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

### UNIVERSITI MALAYSIA SARAWAK KOTA SAMARAHAN SARAWAK PSD2023 ALGORITHM & DATA STRUCTURE

STUDENT IDENTIFICATION NO UNIVERSITI MALAYSIA SARAWAK 94300 KOTA SAMARAHAN SARAWAK FAKULTI SAINS KOMPUTER & TEKNOLOGI MAKLUMAT (Faculty of Computer Science & Information Technology) Diploma in Multimedia

### Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

### DATA STRUCTURES USING C

DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

### 12 Abstract Data Types

12 Abstract Data Types 12.1 Source: Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: Define the concept of an abstract data type (ADT).

### Data Structures and Algorithms Stacks and Queues

Data Structures and Algorithms Stacks and Queues Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/23 6-0: Stacks and

### Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

Tutorial#1 Q 1:- Explain the terms data, elementary item, entity, primary key, domain, attribute and information? Also give examples in support of your answer? Q 2:- What is a Data Type? Differentiate

### Analysis of a Search Algorithm

CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

### Algorithms and Data Structures

Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

### Binary Search Trees. A Generic Tree. Binary Trees. Nodes in a binary search tree ( B-S-T) are of the form. P parent. Key. Satellite data L R

Binary Search Trees A Generic Tree Nodes in a binary search tree ( B-S-T) are of the form P parent Key A Satellite data L R B C D E F G H I J The B-S-T has a root node which is the only node whose parent

### Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

### Common Data Structures

Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees

### Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems

### Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Prof. Dr. Harald Gall. Institut für Informatik Universität Zürich

Stacks, Queues & Trees Prof. Dr. Harald Gall Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch The Stack Interface!! Stack!! Data structure holding several items.!! New items added to the

### Data Structures and Algorithms

Data Structures and Algorithms CS245-2016S-04 Stacks and Queues David Galles Department of Computer Science University of San Francisco 04-0: Abstract Data Types An Abstract Data Type is a definition of

### A binary search tree is a binary tree with a special property called the BST-property, which is given as follows:

Chapter 12: Binary Search Trees A binary search tree is a binary tree with a special property called the BST-property, which is given as follows: For all nodes x and y, if y belongs to the left subtree

### 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

### CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

### Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that

### QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in real-world, namely,

### Collections & Data Structures. CS 3: Computer Programming in Java

Collections & Data Structures CS 3: Computer Programming in Java Objectives The concept of a collection Separating the interface from the implementation Dynamic data structures Linked lists Queues and

### What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Stacks and Queues What is a Stack? Stores a set of elements in a particular order Accessed in Last-In In-First-Out (LIFO) fashion Real life examples: Pile of books PEZ dispenser Cup trays in cafeteria

### Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets We ve been talking a lot about efficiency in computing and run time. But thus far mostly ignoring data

### csci 210: Data Structures Stacks and Queues

csci 210: Data Structures Stacks and Queues Summary Topics stacks and queues as abstract data types implementations arrays linked lists analysis and comparison application: searching with stacks and queues

Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points

### Memory Management. Memory Areas and their use. Memory Manager Tasks: Free List Implementations. acquire release

Memory Management Memory Areas and their use Memory Manager Tasks: acquire release Free List Implementations Singly Linked List Doubly Linked List Buddy Systems Memory Management Memory areas: In languages

### Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

### PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

### GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT. Course Curriculum. DATA STRUCTURES (Code: 3330704)

GUJARAT TECHNOLOGICAL UNIVERSITY, AHMEDABAD, GUJARAT Course Curriculum DATA STRUCTURES (Code: 3330704) Diploma Programme in which this course is offered Semester in which offered Computer Engineering,

### Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Data Structures Page 1 of 24 A.1. Arrays (Vectors) n-element vector start address + ielementsize 0 +1 +2 +3 +4... +n-1 start address continuous memory block static, if size is known at compile time dynamic,

### System Software Prof. Dr. H. Mössenböck

System Software Prof. Dr. H. Mössenböck 1. Memory Management 2. Garbage Collection 3. Linkers and Loaders 4. Debuggers 5. Text Editors Marks obtained by end-term exam http://ssw.jku.at/misc/ssw/ 1. Memory

### 5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

### AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm

AS-2261 M.Sc.(First Semester) Examination-2013 Paper -fourth Subject-Data structure with algorithm Time: Three Hours] [Maximum Marks: 60 Note Attempts all the questions. All carry equal marks Section A

### Data Structures. Topic #4

Topic #4 Today s Agenda Stack and Queue ADTs What are they Like Ordered Lists, are position oriented Use of Data Structures for Stacks and Queues arrays (statically & dynamically allocated) linear linked

### Binary Search Trees. Each child can be identied as either a left or right. parent. right. A binary tree can be implemented where each node

Binary Search Trees \I think that I shall never see a poem as lovely as a tree Poem's are wrote by fools like me but only G-d can make atree \ {Joyce Kilmer Binary search trees provide a data structure

### CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR:

CS0213 DATA STRUCTURES AND ALGORITHM LAB USING C & C++ LABORATORY MANUAL II - CSE III - SEMESTER ACADEMIC YEAR: 2012-2013 SCHOOL OF COMPUTER SCIENCE & ENGINEERING SRM UNIVERSITY, SRM NAGAR, KATTANKULATHUR-603203.

### Chapter 3: Restricted Structures Page 1

Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both

### 22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/

22c:31 Algorithms Ch3: Data Structures Hantao Zhang Computer Science Department http://www.cs.uiowa.edu/~hzhang/c31/ Linear Data Structures Now we can now explore some convenient techniques for organizing

### 1 2-3 Trees: The Basics

CS10: Data Structures and Object-Oriented Design (Fall 2013) November 1, 2013: 2-3 Trees: Inserting and Deleting Scribes: CS 10 Teaching Team Lecture Summary In this class, we investigated 2-3 Trees in

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

Priority Queues (Heaps) 1 Motivation Queues are a standard mechanism for ordering tasks on a first-come, first-served basis However, some tasks may be more important or timely than others (higher priority)

### Data Structure. Lecture 3

Data Structure Lecture 3 Data Structure Formally define Data structure as: DS describes not only set of objects but the ways they are related, the set of operations which may be applied to the elements

### BM267 - Introduction to Data Structures

BM267 - Introduction to Data Structures 3. Elementary Data Structures Ankara University Computer Engineering Department BLM267 1 Objectives Learn about elementary data structures - Data structures that

### B-Trees. Algorithms and data structures for external memory as opposed to the main memory B-Trees. B -trees

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

=============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

### 10CS35: Data Structures Using C

CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

### Previous Lectures. B-Trees. External storage. Two types of memory. B-trees. Main principles

B-Trees Algorithms and data structures for external memory as opposed to the main memory B-Trees Previous Lectures Height balanced binary search trees: AVL trees, red-black trees. Multiway search trees:

### CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Nicki Dell Spring 2014

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Nicki Dell Spring 2014 Registration We have 140 students registered and 140+ on the wait list! If you re thinking of

### Stacks & Queues. Data structures and Algorithms

Stacks & Queues Data structures and Algorithms Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++ Goodrich, Tamassia and Mount (Wiley, 2004) Outline

### Data Structures and Data Manipulation

Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval

### CS 253: Algorithms. Chapter 12. Binary Search Trees. * Deletion and Problems. Credit: Dr. George Bebis

CS 2: Algorithms Chapter Binary Search Trees * Deletion and Problems Credit: Dr. George Bebis Binary Search Trees Tree representation: A linked data structure in which each node is an object Node representation:

### Data Structures. value. key. 5 Alpha. 3 Beta. 7 Gamma

Data Structures key value 5 Alpha 10 2 7 5 1 4 9 3 6 8 3 Beta 7 Gamma Sequence Associative e.g., C-Arrays, std::vector, std::deque, std::list e.g., C-Arrays, std::map, std::set, std::unordered_map Data

### Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given

### Analysis of Algorithms I: Binary Search Trees

Analysis of Algorithms I: Binary Search Trees Xi Chen Columbia University Hash table: A data structure that maintains a subset of keys from a universe set U = {0, 1,..., p 1} and supports all three dictionary

### Definition. E.g. : Attempting to represent a transport link data with a tree structure:

The ADT Graph Recall the ADT binary tree: a tree structure used mainly to represent 1 to 2 relations, i.e. each item has at most two immediate successors. Limitations of tree structures: an item in a tree

### Binary Heap Algorithms

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

### St S a t ck a ck nd Qu Q eue 1

Stack and Queue 1 Stack Data structure with Last-In First-Out (LIFO) behavior In Out C B A B C 2 Typical Operations Pop on Stack Push isempty: determines if the stack has no elements isfull: determines

### Module 2 Stacks and Queues: Abstract Data Types

Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which

### A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called heap-order property

CmSc 250 Intro to Algorithms Chapter 6. Transform and Conquer Binary Heaps 1. Definition A binary heap is a complete binary tree, where each node has a higher priority than its children. This is called

### Converting a Number from Decimal to Binary

Converting a Number from Decimal to Binary Convert nonnegative integer in decimal format (base 10) into equivalent binary number (base 2) Rightmost bit of x Remainder of x after division by two Recursive

### Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

### Sample Questions Csci 1112 A. Bellaachia

Sample Questions Csci 1112 A. Bellaachia Important Series : o S( N) 1 2 N N i N(1 N) / 2 i 1 o Sum of squares: N 2 N( N 1)(2N 1) N i for large N i 1 6 o Sum of exponents: N k 1 k N i for large N and k

### Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.

Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png Consider the limit lim n f ( n) g ( n ) What does it

Universidad Carlos III de Madrid Algorithms and Data Structures (ADS) Bachelor in Informatics Engineering Computer Science Department Lists, Stacks and Queues. Authors: Isabel Segura Bedmar April 2011

### Linear ADTs. Restricted Lists. Stacks, Queues. ES 103: Data Structures and Algorithms 2012 Instructor Dr Atul Gupta

Linear DT-1: Restricted Lists Stacks, Queues tul Gupta Restricted Lists Stack Queue Circular queue Priority queue General Lists rrays Linked list Circular list Doubly linked list Linear DTs 1 Stacks Using

### Announcements. CSE332: Data Abstractions. Lecture 9: B Trees. Today. Our goal. M-ary Search Tree. M-ary Search Tree. Ruth Anderson Winter 2011

Announcements CSE2: Data Abstractions Project 2 posted! Partner selection due by 11pm Tues 1/25 at the latest. Homework due Friday Jan 28 st at the BEGINNING of lecture Lecture 9: B Trees Ruth Anderson

### Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

Class Overview CSE 326: Data Structures Introduction Introduction to many of the basic data structures used in computer software Understand the data structures Analyze the algorithms that use them Know

### Algorithms and Data Structures

Algorithms and Data Structures Lists and Arrays Marcin Sydow Web Mining Lab PJWSTK Marcin Sydow (Web Mining Lab PJWSTK) Algorithms and Data Structures 1 / 35 Topics covered by this lecture: Linked Lists

### Data Structures UNIT III. Model Question Answer

Data Structures UNIT III Model Question Answer Q.1. Define Stack? What are the different primitive operations on Stack? Ans: Stack: A stack is a linear structure in which items may be added or removed

### CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues Linda Shapiro Registration We have 180 students registered and others who want to get in. If you re thinking of dropping

### CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

### Binary Search Trees CMPSC 122

Binary Search Trees CMPSC 122 Note: This notes packet has significant overlap with the first set of trees notes I do in CMPSC 360, but goes into much greater depth on turning BSTs into pseudocode than

### Data Structures Fibonacci Heaps, Amortized Analysis

Chapter 4 Data Structures Fibonacci Heaps, Amortized Analysis Algorithm Theory WS 2012/13 Fabian Kuhn Fibonacci Heaps Lacy merge variant of binomial heaps: Do not merge trees as long as possible Structure:

### Symbol Tables. Introduction

Symbol Tables Introduction A compiler needs to collect and use information about the names appearing in the source program. This information is entered into a data structure called a symbol table. The

### Stacks. The stack ADT Stack Implementation. Stack Examples. using arrays using generic linked lists using List ADT. EECS 268 Programming II 1

Stacks The stack ADT Stack Implementation using arrays using generic linked lists using List ADT Stack Examples 1 Stacks and Queues Linear data structures each item has specific first, next, and previous

### Symbol Tables. IE 496 Lecture 13

Symbol Tables IE 496 Lecture 13 Reading for This Lecture Horowitz and Sahni, Chapter 2 Symbol Tables and Dictionaries A symbol table is a data structure for storing a list of items, each with a key and

### Collections and Data Structures. array vs ArrayList. Using a collection or ADT

Collections and Data Structures CMPT 126: Lecture 11 Collections: Abstract Data Types and Dynamic Representation (Chapt. 12) Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University

### Introduction to Data Structures

Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

### Analysis of Algorithms, I

Analysis of Algorithms, I CSOR W4231.002 Eleni Drinea Computer Science Department Columbia University Thursday, February 26, 2015 Outline 1 Recap 2 Representing graphs 3 Breadth-first search (BFS) 4 Applications

### Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Data Structures Jaehyun Park CS 97SI Stanford University June 29, 2015 Typical Quarter at Stanford void quarter() { while(true) { // no break :( task x = GetNextTask(tasks); process(x); // new tasks may

### International Journal Of Engineering Research & Management Technology

International Journal Of Engineering Research & Management Technology ISSN: 2348-4039 September- 2014 Volume 1, Issue-5 Dynamic Implementation Using Linked List Karuna Department of Information and Technology

### KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php info@kitestechnology.com technologykites@gmail.com Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

### Overview of Data Structures

UNIT 3 Concrete Data Types Classification of Data Structures Concrete vs. Abstract Data Structures Most Important Concrete Data Structures Arrays Records Linked Lists Binary Trees Overview of Data Structures

### Exam study sheet for CS2711. List of topics

Exam study sheet for CS2711 Here is the list of topics you need to know for the final exam. For each data structure listed below, make sure you can do the following: 1. Give an example of this data structure

### 6 March 2007 1. Array Implementation of Binary Trees

Heaps CSE 0 Winter 00 March 00 1 Array Implementation of Binary Trees Each node v is stored at index i defined as follows: If v is the root, i = 1 The left child of v is in position i The right child of

### Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!

### 406 memory pool memory allocation handle memory deallocation dynamic storage allocation

406 Chap. 12 Lists and Arrays Revisited 12.4 Memory Management Most of the data structure implementations described in this book store and access objects all of the same size, such as integers stored in

### ITEC2620 Introduction to Data Structures

ITEC2620 Introduction to Data Structures Lecture 8b Search Trees Traversals Typical covered as graph traversals in data structures courses I ve never seen a graph traversal in practice! AI background Tree

### Lecture 6: Binary Search Trees CSCI 700 - Algorithms I. Andrew Rosenberg

Lecture 6: Binary Search Trees CSCI 700 - Algorithms I Andrew Rosenberg Last Time Linear Time Sorting Counting Sort Radix Sort Bucket Sort Today Binary Search Trees Data Structures Data structure is a

### Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

Binary Search Trees Lecturer: Georgy Gimel farb COMPSCI 220 Algorithms and Data Structures 1 / 27 1 Properties of Binary Search Trees 2 Basic BST operations The worst-case time complexity of BST operations

### Lecture 2: Data Structures Steven Skiena. http://www.cs.sunysb.edu/ skiena

Lecture 2: Data Structures Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.sunysb.edu/ skiena String/Character I/O There are several approaches