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

Similar documents
R13. II B. Tech I Semester Supplementary Examinations, May/June DATA STRUCTURES (Com. to ECE, CSE, EIE, IT, ECC)

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

Course Name: B.Tech. 3 th Sem. No of hours allotted to complete the syllabi: 44 Hours No of hours allotted per week: 3 Hours. Planned.

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Introduction p. 1 Pseudocode p. 2 Algorithm Header p. 2 Purpose, Conditions, and Return p. 3 Statement Numbers p. 4 Variables p. 4 Algorithm Analysis

Syllabus for Bachelor of Technology. Computer Engineering. Subject Code: 01CE0301. Subject Name: Data Structure. B.Tech. Year - II

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

Algorithms and programs, basic idea of pseudo-code.algorithm efficiency and analysis, time and space analysis of algorithms order notations.

1. Attempt any three of the following: 15

ASSIGNMENTS. Progra m Outcom e. Chapter Q. No. Outcom e (CO) I 1 If f(n) = Θ(g(n)) and g(n)= Θ(h(n)), then proof that h(n) = Θ(f(n))

DATA STRUCTURES THROUGH C++

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

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

VALLIAMMAI ENGINEERING COLLEGE

Prepared By: Ms. Nidhi Solanki (Assist. Prof.) Page 1

PROGRAMMING IN C++ (Regulation 2008) Answer ALL questions PART A (10 2 = 20 Marks) PART B (5 16 = 80 Marks) function? (8)

GUJARAT TECHNOLOGICAL UNIVERSITY COMPUTER ENGINEERING (07) / INFORMATION TECHNOLOGY (16) / INFORMATION & COMMUNICATION TECHNOLOGY (32) DATA STRUCTURES

QUESTION BANK. Prepared by,mrs.d.maladhy AP/IT,RGCET. Page 1

R10 SET - 1. Code No: R II B. Tech I Semester, Supplementary Examinations, May

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

E.G.S. PILLAY ENGINEERING COLLEGE (An Autonomous Institution, Affiliated to Anna University, Chennai) Nagore Post, Nagapattinam , Tamilnadu.

Total No. of Questions :09] [Total No. of Pages : 02. II/IV B.Tech. DEGREE EXAMINATIONS, NOV/DEC First Semester CSE/IT DATA STRUCTURES USING C

VALLIAMMAI ENGINEERING COLLEGE SRM Nagar, Kattankulathur

Discuss the following operations on One-Dimensional array with algorithms.

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY THIRD SEMESTER B.TECH DEGREE EXAMINATION, JULY 2017 CS205: DATA STRUCTURES (CS, IT)

Bachelor Level/ First Year/ Second Semester/ Science Full Marks: 60 Computer Science and Information Technology (CSc. 154) Pass Marks: 24

CS301 - Data Structures Glossary By

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

Department of Computer Science and Technology

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

Data Structures Question Bank Multiple Choice

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 8391 DATA STRUCTURES

CS8391-DATA STRUCTURES

17CS33:Data Structures Using C QUESTION BANK

Analysis of Algorithms

Visit ::: Original Website For Placement Papers. ::: Data Structure

Tribhuvan University Institute of Science and Technology Computer Science and Information Technology (CSC. 154) Section A Attempt any Two questions:

DS ata Structures Aptitude

PESIT Bangalore South Campus Department of MCA Course Information for

Preface... (vii) CHAPTER 1 INTRODUCTION TO COMPUTERS

DEPARTMENT OF COMPUTER APPLICATIONS B.C.A. - FIRST YEAR ( REGULATION) SECOND SEMESTER LESSON PLAN SRM INSTITUTE OF SCIENCE AND TECHNOLOGY

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- MARCH, 2012 DATA STRUCTURE (Common to CT and IF) [Time: 3 hours

CLASSIC DATA STRUCTURES IN JAVA

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

Overview of Data Structures, Algorithm Analysis

( ). Which of ( ) ( ) " #& ( ) " # g( n) ( ) " # f ( n) Test 1

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

logn D. Θ C. Θ n 2 ( ) ( ) f n B. nlogn Ο n2 n 2 D. Ο & % ( C. Θ # ( D. Θ n ( ) Ω f ( n)

9. The expected time for insertion sort for n keys is in which set? (All n! input permutations are equally likely.)

CS DATA STRUCTURES AND ALGORITHMS

( ) + n. ( ) = n "1) + n. ( ) = T n 2. ( ) = 2T n 2. ( ) = T( n 2 ) +1

Algorithm Class. C C++ DS JAVA DATA STRUCTURES TRAINING INSTITUTE KPHB HYDERABAD. Mobile:

LESSON PLAN B.C.A. - FIRST YEAR ( REGULATION) SECOND SEMESTER

CS 445: Data Structures Final Examination: Study Guide

COURSE: DATA STRUCTURES USING C & C++ CODE: 05BMCAR17161 CREDITS: 05

Thomas H. Cormen Charles E. Leiserson Ronald L. Rivest. Introduction to Algorithms

WITH C+ + William Ford University of the Pacific. William Topp University of the Pacific. Prentice Hall, Englewood Cliffs, New Jersey 07632

MLR Institute of Technology

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

Bharati Vidyapeeth s College Of Engineering for Women Pune-43 Department E & TC. SE- Unit Test I Subject-DS

Sample Question Paper

& ( D. " mnp ' ( ) n 3. n 2. ( ) C. " n

UCS-406 (Data Structure) Lab Assignment-1 (2 weeks)

OBJECT ORIENTED DATA STRUCTURE & ALGORITHMS

Introduction to Algorithms Third Edition

Question Paper Code : 97044

BRONX COMMUNITY COLLEGE of the City University of New York DEPARTMENT OF MATHEMATICS AND COMPUTER SCIENCE. Sample Final Exam

Course Review for Finals. Cpt S 223 Fall 2008

Data Structures Through C. Student Workbook

( ) 1 B. 1. Suppose f x

Multiple Choice. Write your answer to the LEFT of each problem. 3 points each

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

CS302 Data Structures using C++

DATA ABSTRACTION AND PROBLEM SOLVING WITH JAVA

MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC Certified)

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING B.E SECOND SEMESTER CS 6202 PROGRAMMING AND DATA STRUCTURES I TWO MARKS UNIT I- 2 MARKS

( ) ( ) C. " 1 n. ( ) $ f n. ( ) B. " log( n! ) ( ) and that you already know ( ) ( ) " % g( n) ( ) " #&

DATA STRUCTURES AND ALGORITHMS

Section I. 1 Review of user defined function,recursion, pointer, structure 05 2 Introduction to Data Structures and stack

A Programming Approach with C DHARMENDER SINGH KUSHWAHA

7.1 Introduction. A (free) tree T is A simple graph such that for every pair of vertices v and w there is a unique path from v to w

) $ f ( n) " %( g( n)

( ) D. Θ ( ) ( ) Ο f ( n) ( ) Ω. C. T n C. Θ. B. n logn Ο

Data Structures in C++ Using the Standard Template Library

Course Review. Cpt S 223 Fall 2009

Fundamentals of Data Structure

Computer Science 302 Fall 2009 (Practice) Second Examination, October 15, 2009

Test 1 Last 4 Digits of Mav ID # Multiple Choice. Write your answer to the LEFT of each problem. 2 points each t 1

DC104 DATA STRUCTURE JUNE Q.2 a. If you are using C language to implement the heterogeneous linked list, what pointer type will you use?

Data Structures. 1. Each entry in a linked list is a called a (a)link (b)node (c)data structure (d)none of the above

4.1.2 Merge Sort Sorting Lower Bound Counting Sort Sorting in Practice Solving Problems by Sorting...

Friday, March 30. Last time we were talking about traversal of a rooted ordered tree, having defined preorder traversal. We will continue from there.

12 Abstract Data Types

n 2 ( ) ( ) + n is in Θ n logn

R16 SET - 1 '' ''' '' ''' Code No: R

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

D. Θ nlogn ( ) D. Ο. ). Which of the following is not necessarily true? . Which of the following cannot be shown as an improvement? D.

Transcription:

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 and storing in an array... 7 1.3 Linked List... 8 1.4 Trees... 8 1.5 Graphs... 9 1.6 Structures... 10 Specifying the Structure... 11 Defining a Structure Variable... 12 Accessing Structure Members... 13 Initialization of Structure Variable... 14 1.7 Iteration... 15 1.8 Recursion... 16 1.9 Fibonacci Numbers... 20 1.10 Comparison of Recursion with Iteration... 24 1.11 Tail Recursion... 24 1.12 Advantage of Recursion... 25 1.13 Pointers... 25 1.14 Pass by Value and Pass by Reference... 33 Pass by Value... 33 Pass by Reference... 34 Passing an Array to a Function... 35 Passing a Structure to a function by the Value Method... 36 Passing a Structure to the Function by Reference Method... 37 Using a Pointer to a Structure... 38 1.15 Classes... 39 1.16 Static Memory Allocation... 41 1.17 Dynamic Memory Allocation... 41 New Operator... 42 Delete Operator... 42

viii Table of Contents Summary... 43 Exercise... 44 Chapter 2: Arrays... 45 2.1 Row Major Representation... 47 2.2 Column Major Representation... 48 Summary... 54 Exercise... 54 Chapter 3: Linked List... 55 3.1 Advantages of a Linked List... 57 3.2 Disadvantages of a Linked List... 57 3.3 Types of a Linked List... 57 Singly Linked List... 58 Doubly Linked list (Two-way Linked List)... 74 Reversing a Singly Linked List... 122 3.4 Header Linked List... 128 3.5 Deleting a Node... 133 3.6 Two-Way Header Lists... 136 3.7 Reversing the Links of a Linked List... 144 First method... 144 Second Method... 146 3.8 Sorting a Linked List... 150 Summary... 154 Exercises... 154 Chapter 4: Stacks and Queues... 155 4.1 Abstract Data Types (ADT)... 156 4.2 Implementing Stacks with Arrays... 156 4.3 Algorithm for the Push Operation... 157 4.4 Algorithm for the Pop Operation... 158 4.5 Algorithm for the Peep Operation... 158 4.6 Queue... 161 Types of Queues... 161 4.7 Circular Linked List... 183 4.8 Sparse Matrix... 187 Summary... 202 Exercises... 203 Chapter 5: Trees... 205 5.1 Properties of a Tree... 206 5.2 Types of Trees... 206 5.3 Levels of a Tree... 207 5.4 Converting a General Tree into a Binary Tree... 207

Table of Contents ix 5.5 Forest... 209 5.6 Binary tree... 210 Complete Binary Tree... 210 Counting Binary Trees... 212 5.7 Binary Search Tree... 212 Efficiency of Binary Search Tree Operations... 213 5.8 Traversing Binary Trees... 214 Preorder Traversal... 214 Inorder Traversal... 214 Postorder Traversal... 214 5.9 Describing Preorder Traversal... 215 5.10 Describing Inorder Traversal... 217 5.11 Describing Postorder Traversal... 220 5.12 Algorithm to Create a Binary Tree... 223 Calling build(root,nn)function... 224 5.13 Algorithm for the Inorder Traversal of a Tree... 224 5.14 Algorithm for the Preorder Traversal of a Tree... 225 5.15 Algorithm for the Postorder Traversal of a Tree... 225 5.16 Sequential Representation of Binary Trees... 244 5.17 Deleting a Node from a Binary Search Tree... 253 Algorithm to Delete a Node from a Binary Search Tree... 257 5.18 Threaded Binary Tree... 263 5.19 Types of Threaded Binary Trees... 265 Rightin Threaded Binary Tree... 265 InThreaded Binary Tree... 272 5.20 Deleting a node From a Threaded Binary Tree... 279 5.21 2-3 Trees... 306 5.22 Height Balanced Trees (AVL Tree)... 307 Rotate Left... 309 Rotate Right... 311 Double Rotation... 312 Deletion From an AVL Tree... 331 5.23 Red Black Tree... 341 5.24 Multiway Search Tree... 341 Algorithm for Inserting Keys into a B-tree... 342 Deleting a Key From a B-tree... 356 5.25 B+ tree... 357 5.26 B*-tree... 358 Creating a Binary Tree When Two Traversal Orders are Given... 358 5.27 Expression Tree... 363 5.28 Decision Tree (Comparison tree)... 366

x Table of Contents Summary... 366 Exercises... 367 Chapter 6: Graphs... 369 6.1 Types of Graphs... 370 Complete Graphs... 370 Regular Graphs... 370 Tree Graphs... 371 Sub Graphs... 371 6.2 Application of Graphs... 372 6.3 Methods of Representing Graphs... 375 Adjacency Matrix... 375 Adjacency List... 379 6.4 Types of Traversals... 392 Breadth First Traversal... 392 Depth First Traversal... 397 6.5 Spanning Trees... 402 Minimum Spanning Trees... 403 6.6 Kruskal Algorithm... 405 6.7 Prim s Algorithm... 411 6.8 Huffman Algorithm... 417 6.9 Warshall s Algorithm for Transitive Closure... 420 Summary... 421 Exercises... 422 Chapter 7: Searching and Sorting... 423 7.1 Efficiency of an Algorithm... 423 7.2 Big O Notation... 424 7.3 Searching Types and Algorithms... 426 Linear Search... 426 Binary Search... 427 7.4 Internal/External Sorting... 431 Bubble Sort... 431 Insertion Sort... 435 Simple Selection Sort... 440 Straight Selection Sort... 440 7.5 Divide and Conquer Method For Sorting... 444 Quick sort... 444 Merge Sort... 453 Comparison of Merge Sort with Quick Sort... 454 Merge sort: Recursive Method... 459 7.6 Heap Sort... 466 Heap and Its Construction... 466

Table of Contents xi Algorithm for Heap Sort... 477 7.7 Radix Sort... 484 7.8 Shell Sort... 487 7.9 Comparison of Sorted Algorithms... 491 Summary... 493 Exercises... 493 Chapter 8: Hashing... 495 8.1 Hash Table... 496 8.2 Methods of Hashing... 496 Division Method... 496 Mid Square Method... 496 Folding Method... 496 8.3 Collision Resolution Methods... 497 Open Addressing... 497 Chaining... 498 Summary... 500 Exercise... 500 Chapter 9: Dynamic Memory Management... 501 9.1 Methods of Dynamic Memory Allocation... 502 Methods for Allocating Memory... 502 Methods of Freeing the Memory... 505 9.2 Buddy System... 506 9.3 Boundary Tag Method... 510 Summary... 511 Exercises... 512 Chapter 10: Miscellaneous... 513 10.1 Algorithm for Pattern Matching... 515 10.2 Knuth Morris Pratt Algorithm... 517 Algorithm for Pattern Matching by KMP... 518 10.3 Polish Notation... 521 10.4 Infix, Prefix, Postfix... 521 Converting from Infix to Postfix... 522 Algorithm for Converting the Infix Form into the Postfix Form... 523 Algorithm for Converting the Infix into Prefix Form... 530 Algorithm for Converting the Postfix Form into the Prefix Form... 536 Algorithm for Converting the Postfix Form to Infix Form... 539 10.5 Evaluating a Postfix Expression... 542 10.6 Evaluating a Polynomial... 548 10.7 Skip List... 556 10.8 Trie... 556 10.9 Searching for a key (word)... 557

xii Table of Contents 10.10 Dictionary... 558 Adding the Numerical Values of the Corresponding Characters... 558 Multiplying the Numerical Values of the Characters by the Power of 10 corresponding to its position... 558 10.11 Unrolled linked lists... 559 10.12 Tower of Hanoi... 561 10.13 Parentheses Matching... 567 Parentheses Matching Algorithm... 567 10.14 Algorithm Writing and Convention... 568 Conventions Used in an Algorithm... 569 Analysis of Algorithm... 570 Analysis of Algorithm in Linear Search... 571 Algorithm for Linear Search in an Array... 571 10.15 Associative Array... 572 10.16 Grafting... 572 10.17 Bounded Queue... 574 10.18 Methods of Designing a System... 574 Top-Down Design... 574 Bottom-Up Design... 575 Summary... 575 Exercises... 576 Model Paper 1 to 3... 577 Index... 581 What s on the CD ROM... 588