Data Structures and Algorithms C++ Implementation
|
|
- Damon Hunt
- 7 years ago
- Views:
Transcription
1 BK TP.HCM Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering BK TP.HCM Data Structures and Algorithms C++ Implementation Huỳnh Tấn Đạt Home Page:
2 Basic stack operations Linked-list implementation Stack applications Array implementation Stacks Slide 2
3 Linear List Concepts General list: no restrictions on where can be inserted/deleted, and on which operations can be used on the list Restricted list: can be inserted/deleted and operations are performed only at the ends of the list Slide 3
4 Stack All insertions and deletions are restricted to one end called the top Last-In First-Out (LIFO) structure Slide 4
5 Basic Stack Operations Data Push Top Top Stack Stack Slide 5
6 Basic Stack Operations Overflow Data Top Stack Slide 6
7 Basic Stack Operations Pop Data Top Top Stack Stack Slide 7
8 Basic Stack Operations Underflow Top Stack Slide 8
9 Basic Stack Operations Stack Top Data Top Top Stack Stack Slide 9
10 Linked-List Implementation Top Stack structure top 5 Conceptual Physical Slide 10
11 Linked-List Implementation Stack structure count top stack count <integer> top <node pointer> end stack Stack node structure node <Type> <node pointer> end node Slide 11
12 Linked-List Implementation template <class ItemType> struct Node { ItemType ; Node<ItemType> *; }; template <class List_ItemType> class Stack { public: Stack(); ~Stack(); Slide 12
13 Linked-List Implementation void Push(List_ItemType In); int Pop(List_ItemType &Out); int GetStackTop(List_ItemType &Out); void Clear(); int IsEmpty(); int GetSize(); Stack<List_ItemType>* Clone(); void Print2Console(); private: Node<List_ItemType>* top; int count; }; Slide 13
14 Create Stack Before After?? count top 0 count top (no stack) (empty stack) Slide 14
15 Create Stack Algorithm createstack (ref stack <meta>) Initializes meta for a stack Pre stack is structure for meta Post meta initialized 1 stack.count = 0 2 stack.top = null 3 return End createstack Slide 15
16 Linked-List Implementation template <class List_ItemType> Stack<List_ItemType>::Stack(){ this->top = NULL; this->count = 0; } template <class List_ItemType> Stack<List_ItemType>::~Stack(){ this->clear(); } Slide 16
17 Push Stack Before After pnew red pnew red stack stack 2 blue 3 blue count top count top green green Slide 17
18 Push Stack Algorithm pushstack (ref stack <meta>, val <Type>) Inserts (pushes) one item into the stack Pre stack is a meta structure to a valid stack contains to be pushed into stack Post have been pushed in stack Return true if successful; false if memory overflow Slide 18
19 Push Stack 1 if (stack full) 1 success = false 2 else 1 allocate (pnew) 2 pnew -> = 3 pnew -> = stack.top 4 stack.top = pnew 5 stack.count = stack.count success = true 3 return success End pushstack Before pnew red stack 2 blue count top green Slide 19
20 Push Stack template <class List_ItemType> void Stack<List_ItemType>::Push (List_ItemType value){ Node<List_ItemType>* pnew = new Node<List_ItemType>(); pnew-> = value; pnew-> = top; this->top = pnew; this->count++; } Slide 20
21 Pop Stack Before After dltptr red dltptr recycled stack stack 3 blue 2 blue count top count top green green Slide 21
22 Pop Stack Algorithm popstack (ref stack <meta>, ref Out <Type>) Pops the item on the top of the stack and returns it to caller Pre stack is a meta structure to a valid stack Out is to receive the popped Post have been returned to caller Return true if successful; false if underflow Slide 22
23 Pop Stack 1 if (stack empty) 1 success = false Before 2 else 1 dltptr = stack.top 2 Out = stack.top -> dltptr stack red 3 stack.top = stack.top -> 4 stack.count = stack.count recycle (dltptr) 3 count top blue 6 success = true 3 return success End popstack green Slide 23
24 Pop Stack template <class List_ItemType> int Stack<List_ItemType>::Pop(List_ItemType &Out){ if (count == 0) return 0; Node<List_ItemType>* dltptr = this->top; Out = this->top->; this->top = this->top->; this->count--; delete dltptr; return 1; } Slide 24
25 Stack Top Algorithm stacktop (val stack <meta>, ref Out <Type>) Retrieves the from the top of the stack without changing the stack Pre Post stack is a meta structure to a valid stack Out is to receive top stack have been returned to caller Return true if successful; false Slide 25
26 Stack Top 1 if (stack empty) 1 success = false 2 else 1 Out = stack.top -> 2 success = true 3 return success End stacktop Slide 26
27 Stack Top template <class List_ItemType> int Stack<List_ItemType>::GetStackTop (List_ItemType &Out){ if (count == 0) return 0; Out = this->top->; return 1; } Slide 27
28 Destroy Stack Algorithm destroystack (ref stack <meta>) Releases all nodes back to memory Pre stack is a meta structure to a valid stack Post stack empty and all nodes recycled 1 if (stack not empty) 1 loop (stack.top not null) 1 temp = stack.top 2 stack.top = stack.top -> 3 recycle (temp) 2 stack.count = 0 3 return End destroystack Slide 28
29 Destroy Stack template <class List_ItemType> void Stack<List_ItemType>::Clear() { Node<List_ItemType>* temp; while (this->top!= NULL){ temp = this->top; this->top = this->top->; delete temp; } this->count = 0; } Slide 29
30 Stack Empty template <class List_ItemType> int Stack<List_ItemType>::IsEmpty() { return (count == 0); } template <class List_ItemType> int Stack<List_ItemType>::GetSize() { return count; } Slide 30
31 Print a stack template <class List_ItemType> void Stack<List_ItemType>::Print2Console() { } Node<List_ItemType>* p; p = this->top; while (p!= NULL){ } printf("%d\t", p->); p = p->; printf("\n"); Slide 31
32 Using Stacks int main(int argc, char* argv[]){ Stack<int> *mystack = new Stack<int>(); int val; mystack->push(7); mystack->push(9); mystack->push(10); mystack->push(8); mystack->print2console(); mystack->pop(val); mystack->print2console(); delete mystack; return 0; } Slide 32
33 Exercises template <class List_ItemType> Stack<List_ItemType>* Stack<List_ItemType>::Clone() { //... } Slide 33
Stacks. Linear data structures
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
More informationDATA STRUCTURE - STACK
DATA STRUCTURE - STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming
More informationLinked Lists Linked Lists, Queues, and Stacks
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
More informationCourse: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions
More informationData 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
More informationList, Stack and Queue. Tom Chao Zhou CSC2100B Data Structures Tutorial 3
List, Stack and Queue Tom Chao Zhou CSC2100B Data Structures Tutorial 3 Outline Structure Linked List Overview Implementation Stack Overview Implementation Queue Overview Implementation Structure A collection
More informationCS 2412 Data Structures. Chapter 2 Stacks and recursion
CS 2412 Data Structures Chapter 2 Stacks and recursion 1 2.1 Stacks A stack is a data structure in which all insertions and deletions of entries are made at one end, called top of the stack. Examples:
More informationLinked 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
More informationChapter Objectives. Chapter 7. Stacks. Various Types of Stacks LIFO. Empty Stack. Stacks
Chapter Objectives Chapter 7 Stacks Learn about stacks Examine various stack operations Learn how to implement a stack as an array Learn how to implement a stack as a linked list Discover stack applications
More informationSt 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
More information1. 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
More information1) 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
More informationDATA STRUCTURE - QUEUE
DATA STRUCTURE - QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to
More informationThis lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues 1. 2004 Goodrich, Tamassia
This lecture Abstract data types Stacks Queues ADTs, Stacks, Queues 1 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations
More informationCSE 211: Data Structures Lecture Notes VII
CSE 211: Data Structures Lecture Notes VII LINKED LISTS In the previous lectures we have seen the representation of ordered lists using an array and sequential mapping. These representations had the property
More informationSoftware Engineering Techniques
Software Engineering Techniques Low level design issues for programming-in-the-large. Software Quality Design by contract Pre- and post conditions Class invariants Ten do Ten do nots Another type of summary
More informationData 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
More informationCommon 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
More informationModule 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
More informationShort Notes on Dynamic Memory Allocation, Pointer and Data Structure
Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double
More informationLinear 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
More informationPROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks
PROGRAMMING CONCEPTS AND EMBEDDED PROGRAMMING IN C, C++ and JAVA: Lesson-4: Data Structures: Stacks 1 STACK A structure with a series of data elements with last sent element waiting for a delete operation.
More informationQueues 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!
More informationBasic Data Structures and Algorithms
Tutorial 3 Basic Data Structures and Algorithms THINGS TO LOOK FOR 3.0 INTRODUCTION 3.1 Array Based Containers Definition and uses of containers. Array and list based containers. Designing and building
More informationCS104: 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
More informationAnalysis 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,
More informationTail call elimination. Michel Schinz
Tail call elimination Michel Schinz Tail calls and their elimination Loops in functional languages Several functional programming languages do not have an explicit looping statement. Instead, programmers
More informationMAX = 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
More informationAbstract 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
More information7.1 Our Current Model
Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.
More informationChapter 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
More informationLast not not Last Last Next! Next! Line Line Forms Forms Here Here Last In, First Out Last In, First Out not Last Next! Call stack: Worst line ever!
ECE 551 C++ Programming, Data structures, and Algorithms Abstract Data Type: Stack Last In First Out (LIFO) 1 2 2 1 4 3 1 3 4 Stacks in Programming Worst line ever! 5 3 1 5 Stacks are not useful for waiting
More informationOutline. The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack. Stacks 2
Stacks Outline The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack Stacks 2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure
More informationWhat Is Recursion? 5/12/10 1. CMPSC 24: Lecture 13 Recursion. Lecture Plan. Divyakant Agrawal Department of Computer Science UC Santa Barbara
CMPSC 24: Lecture 13 Recursion Divyakant Agrawal Department of Computer Science UC Santa Barbara 5/12/10 1 Lecture Plan Recursion General structure of recursive soluions Why do recursive soluions terminate?
More informationStacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1
Stacks (and Queues) 1 Stacks Stack: what is it? ADT Applications Implementation(s) 2 CSCU9A3 1 Stacks and ueues A stack is a very important data structure in computing science. A stack is a seuence of
More informationWhat 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
More informationUniversidad Carlos III de Madrid
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
More informationClass 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
More informationEE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)
EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE) UNIT I LINEAR STRUCTURES Abstract Data Types (ADT) List ADT array-based implementation linked list implementation cursor-based linked lists
More informationDATA 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
More informationSequential 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
More informationOutline. Computer Science 331. Stack ADT. Definition of a Stack ADT. Stacks. Parenthesis Matching. Mike Jacobson
Outline Computer Science 1 Stacks Mike Jacobson Department of Computer Science University of Calgary Lecture #12 1 2 Applications Array-Based Linked List-Based 4 Additional Information Mike Jacobson (University
More informationStack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1
Stack & Queue Explain Array in detail One Dimensional Array Simplest data structure that makes use of computed address to locate its elements is the onedimensional array or vector; number of memory locations
More informationGSM. Global System for Mobile Communications, 1992. Security in mobile phones. System used all over the world. Sikkerhed04, Aften Trusler
GSM Global System for Mobile Communications, 1992 Security in mobile phones System used all over the world 1 GSM: Threat Model What Cloning Eavesdropping Tracking Who Criminals Secret Services Why Break
More informationPractical Session 4 Java Collections
Practical Session 4 Java Collections Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack The Collections class Wrapper classes Collection A group
More informationData Structure with C
Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which
More informationBSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering
BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester
More informationQuiz 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
More informationQUEUES. 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,
More informationData Structures and Algorithms Lists
Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 5-0: Abstract Data Types An
More informationA binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:
Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)
More informationSTACKS,QUEUES, AND LINKED LISTS
STACKS,QUEUES, AND LINKED LISTS Stacks Queues Linked Lists Double-Ended Queues Case Study: A Stock Analysis Applet 1 Stacks Astack is a container of objects that are inserted and removed according to the
More informationParallelization: Binary Tree Traversal
By Aaron Weeden and Patrick Royal Shodor Education Foundation, Inc. August 2012 Introduction: According to Moore s law, the number of transistors on a computer chip doubles roughly every two years. First
More informationStacks. Data Structures and Data Types. Collections
Data Structures and Data Types Data types Set values. Set operations on those values. Some are built in to Java: int, double, char,... Most are not: Complex, Picture, Charge, Stack, Queue, Graph,... Data
More informationData Types. Abstract Data Types. ADTs as Design Tool. Abstract Data Types. Integer ADT. Principle of Abstraction
bstract ata Types Previous lectures: algorithms and their efficiency analysis. oming lectures: data structures In this lecture: bstract data types Ts as a design tool Examples: integer T, List T ata Types
More informationIntroduction 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
More informationData 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
More informationData Structures and Algorithms V22.0102. Otávio Braga
Data Structures and Algorithms V22.0102 Otávio Braga We use a stack When an operand is read, output it When an operator is read Pop until the top of the stack has an element of lower precedence Then push
More information1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: 15.1-15.3. Data Structures
1.00 Lecture 35 Data Structures: Introduction Stacks, Queues Reading for next time: Big Java: 15.1-15.3 Data Structures Set of reusable classes used in algorithms, simulations, operating systems, applications
More informationData Structures and Algorithms
Data Structures and Algorithms CS245-2016S-05 Abstract Data Types and Lists David Galles Department of Computer Science University of San Francisco 05-0: Abstract Data Types Recall that an Abstract Data
More informationIntroduction to Data Structures and Algorithms
Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures
More information22c: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
More informationCORBA Programming with TAOX11. The C++11 CORBA Implementation
CORBA Programming with TAOX11 The C++11 CORBA Implementation TAOX11: the CORBA Implementation by Remedy IT TAOX11 simplifies development of CORBA based applications IDL to C++11 language mapping is easy
More informationData 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
More informationLecture 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
More information1. What are Data Structures? Introduction to Data Structures. 2. What will we Study? CITS2200 Data Structures and Algorithms
1 What are ata Structures? ata Structures and lgorithms ata structures are software artifacts that allow data to be stored, organized and accessed Topic 1 They are more high-level than computer memory
More informationCpt S 223. School of EECS, WSU
Abstract Data Types 1 Topics Abstract Data Types (ADTs) Some basic ADTs: Lists Stacks Queues 2 Primitive Data Type vs. Abstract Data Types Primitive DT: ADT: programmer progra ammer Interface (API) e.g.,
More informationAlgorithms 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
More informationLecture Notes on Stacks & Queues
Lecture Notes on Stacks & Queues 15-122: Principles of Imperative Computation Frank Pfenning, André Platzer, Rob Simmons Lecture 9 February 12, 2013 1 Introduction In this lecture we introduce queues and
More informationApplication of Stacks: Postfix Expressions Calculator (cont d.)
Application of Stacks: Postfix Expressions Calculator (cont d.) Postfix expression: 6 3 + 2 * = FIGURE 7-15 Evaluating the postfix expression: 6 3 + 2 * = Data Structures Using C++ 2E 1 Application of
More information10CS35: 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
More informationOutput: 12 18 30 72 90 87. struct treenode{ int data; struct treenode *left, *right; } struct treenode *tree_ptr;
50 20 70 10 30 69 90 14 35 68 85 98 16 22 60 34 (c) Execute the algorithm shown below using the tree shown above. Show the exact output produced by the algorithm. Assume that the initial call is: prob3(root)
More informationStacks and queues. Algorithms and Data Structures, Fall 2011. Rasmus Pagh. Based on slides by Kevin Wayne, Princeton
Algorithms and Data Structures, Fall 2011 Stacks and queues Rasmus Pagh Based on slides by Kevin Wayne, Princeton Algorithms, 4 th Edition Robert Sedgewick and Kevin Wayne Copyright 2002 2011 Stacks and
More informationAdapter, Bridge, and Façade
CHAPTER 5 Adapter, Bridge, and Façade Objectives The objectives of this chapter are to identify the following: Complete the exercise in class design. Introduce the adapter, bridge, and façade patterns.
More informationComp151. Definitions & Declarations
Comp151 Definitions & Declarations Example: Definition /* reverse_printcpp */ #include #include using namespace std; int global_var = 23; // global variable definition void reverse_print(const
More informationBoolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)
Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the
More informationBinary Search Trees (BST)
Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search
More informationCSE373: 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
More informationPrevious 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:
More informationBig 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
More informationQueues and Stacks. Atul Prakash Downey: Chapter 15 and 16
Queues and Stacks Atul Prakash Downey: Chapter 15 and 16 Queues Queues occur in real life a lot. Queues at checkout Queues in banks In software systems: Queue of requests at a web servers Properties of
More informationData Structures Using C++
Data Structures Using C++ 1.1 Introduction Data structure is an implementation of an abstract data type having its own set of data elements along with functions to perform operations on that data. Arrays
More information5. 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
More informationG. H. RAISONI COLLEGE OF ENGG NAGPUR-16 Session 2006-2007 DEPARTMENT CSE Semester IV SUBJECT DSPD
G. H. RAISONI COLLEGE OF ENGG NAGPUR-16 Session 2006-2007 DEPARTMENT CSE Semester IV SUBJECT DSPD LIST OF EXPERIMENTS 1.Make a database. The record tag,tstudent consists of these fields: Name[20],RollNo.[5],Address[40],Phone[12],UT-1[2,from1
More informationIntroduction to Stacks
Introduction to Stacks What is a Stack Stack implementation using array. Stack implementation using linked list. Applications of Stack. What is a Stack? Stack is a data structure in which data is added
More informationData Structures and Algorithms(5)
Ming Zhang Data Structures and Algorithms Data Structures and Algorithms(5) Instructor: Ming Zhang Textbook Authors: Ming Zhang, Tengjiao Wang and Haiyan Zhao Higher Education Press, 2008.6 (the "Eleventh
More informationRecursion. Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive.
Recursion Definition: o A procedure or function that calls itself, directly or indirectly, is said to be recursive. Why recursion? o For many problems, the recursion solution is more natural than the alternative
More informationPES 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
More informationCourse: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1
Definition Course: Programming II - Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition
More informationThe Tower of Hanoi. Recursion Solution. Recursive Function. Time Complexity. Recursive Thinking. Why Recursion? n! = n* (n-1)!
The Tower of Hanoi Recursion Solution recursion recursion recursion Recursive Thinking: ignore everything but the bottom disk. 1 2 Recursive Function Time Complexity Hanoi (n, src, dest, temp): If (n >
More informationAbstract Data Types. Chapter 2
Chapter 2 Abstract Data Types The second idea at the core of computer science, along with algorithms, is data. In a modern computer, data consists fundamentally of binary bits, but meaningful data is organized
More informationSoftware Vulnerabilities
Software Vulnerabilities -- stack overflow Code based security Code based security discusses typical vulnerabilities made by programmers that can be exploited by miscreants Implementing safe software in
More informationData 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,
More informationAtmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1
Data Structure By Ajay Raiyani Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1 Linked List 4 Singly Linked List...4 Doubly Linked List...7 Explain Doubly Linked list: -...7 Circular Singly Linked
More informationCode Refactoring and Defects
Code Refactoring and Defects Reusing this material This work is licensed under a Creative Commons Attribution- NonCommercial-ShareAlike 4.0 International License. http://creativecommons.org/licenses/by-nc-sa/4.0/deed.en_us
More informationD06 PROGRAMMING with JAVA
Cicles Formatius de Grau Superior Desenvolupament d Aplicacions Informàtiques D06 PROGRAMMING with JAVA Ch20 Data Structures I PowerPoint presentation, created by Angel A. Juan - ajuanp(@)gmail.com, for
More informationComputer Programming using C
Computer Programming using C Lecture 11: Buffers and linked lists: solutions Dr Julian Miller Room P/M/101 Ext 2383; E-mail: jfm@ohm http://www.elec.york.ac.uk/intsys/users/jfm7 Contents Solution to buffers
More informationQueues. Manolis Koubarakis. Data Structures and Programming Techniques
Queues Manolis Koubarakis 1 The ADT Queue A queue Q of items of type T is a sequence of items of type T on which the following operations are defined: Initialize the queue to the empty queue. Determine
More informationTutorial on C Language Programming
Tutorial on C Language Programming Teodor Rus rus@cs.uiowa.edu The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:
More informationLecture 12 Doubly Linked Lists (with Recursion)
Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)
More information