A Programming Approach with C DHARMENDER SINGH KUSHWAHA

Similar documents
Analysis of Algorithms

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

EC8393FUNDAMENTALS OF DATA STRUCTURES IN C Unit 3

CLOUD COMPUTING. M.N. Rao

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

COMPUTER GRAPHICS, MULTIMEDIA AND ANIMATION, Second Edition (with CD-ROM) Malay K. Pakhira

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

Fundamentals of Discrete Mathematical Structures

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

FUNDAMENTALS OF DIGITAL CIRCUITS

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING UNIT-1

17CS33:Data Structures Using C QUESTION BANK

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

Honorary Professor Supercomputer Education and Research Centre Indian Institute of Science, Bangalore

Telecommunication Switching Systems and Networks

PESIT Bangalore South Campus Department of MCA Course Information for

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

Object-Oriented Analysis and Design Using UML

DYNAMIC MEMORY ALLOCATION AND DEALLOCATION

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

MICROPROCESSOR 8085 AND ITS INTERFACING SUNIL MATHUR. Second Edition A 1 ALE AD 0 - AD 7. Latch. Keyboard data V CC 8 P A D D 0 7 STB STB G G A

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

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

OBJECT ORIENTED DATA STRUCTURE & ALGORITHMS

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

INSTITUTE OF AERONAUTICAL ENGINEERING

SAURASHTRA UNIVERSITY

DATA STRUCTURE : A MCQ QUESTION SET Code : RBMCQ0305

COMMUNICATION PROTOCOL ENGINEERING

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

Microcontrollers. Principles and Applications. Ajit Pal +5 V 2K 8. 8 bit dip switch. P2 8 Reset switch Microcontroller AT89S52 100E +5 V. 2.

Sample Question Paper

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

DATA STRUCTURE UNIT I

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))

FORTH SEMESTER DIPLOMA EXAMINATION IN ENGINEERING/ TECHNOLIGY- OCTOBER, 2012 DATA STRUCTURE

STRUCTURE AND SYLLABUS APPROVED IN THE BOARD OF STUDIES MEETING ON 2001 TO BE EFFECTIVE FROM THE ACADEMIC YEAR

S.E. (Computer) (First Semester) EXAMINATION, 2011 DATA STRUCTURES AND ALGORITHM (2008 PATTERN) Time : Three Hours Maximum Marks : 100

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.

V.S.B ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY I IT-II Semester. Sl.No Subject Name Page No. 1 Programming & Data Structures-I 2

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

CS W3134: Data Structures in Java

Data Structures. Chapter 06. 3/10/2016 Md. Golam Moazzam, Dept. of CSE, JU

CS PROGRAMMING & ATA STRUCTURES I. UNIT I Part - A

MULTIMEDIA COLLEGE JALAN GURNEY KIRI KUALA LUMPUR

DATA STRUCTURES USING C

DIGITA L LOGIC AND COMPUTER ORGA NIZATION

Fundamentals of Data Structure

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

Cryptography and Network Security

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

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

Department of Computer Science and Technology

CS8391-DATA STRUCTURES QUESTION BANK UNIT I

1. Attempt any three of the following: 15

VALLIAMMAI ENGINEERING COLLEGE

MICROPROCESSOR Architecture, Programming and Interfacing SUNIL MATHUR. Assistant Professor Maharaja Agrasen Institute of Technology Delhi

Objective Questions for Online Practical Exams under CBCS Scheme Subject: Data Structure-I (CS-113)

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

Aryan College. Fundamental of C Programming. Unit I: Q1. What will be the value of the following expression? (2017) A + 9

DATA STRUCUTRES. A data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently.

Fundamentals of. Mobile Computing. Second Edition. Prasant Kumar Pattnaik Rajib Mall

PHI Learning Private Limited

Postfix (and prefix) notation

CS301 - Data Structures Glossary By

A6-R3: DATA STRUCTURE THROUGH C LANGUAGE

St. MARTIN s ENGINERING COLLEGE Dhulapally,Secunderabad

Programming and Data Structure Solved. MCQs- Part 2

Data Structures in C++ Using the Standard Template Library

DEEPIKA KAMBOJ UNIT 2. What is Stack?

C Programming. Course Outline. C Programming. Code: MBD101. Duration: 10 Hours. Prerequisites:

DATA STRUCTURES THROUGH C++

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

Content: Learning Objectives

Government of Karnataka Department of Technical Education Bengaluru

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

CS 445: Data Structures Final Examination: Study Guide

Data Structure (CS301)

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

KLiC C. About. Tools: Turbo C++ Syllabus:

Linked List. April 2, 2007 Programming and Data Structure 1

1 P age DS & OOPS / UNIT II


PA3 Design Specification

Reg. No. : Question Paper Code : 27157

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

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

Some Applications of Stack. Spring Semester 2007 Programming and Data Structure 1

Lecture No.04. Data Structures

Abstract Data Types. Stack. January 26, 2018 Cinda Heeren / Geoffrey Tien 1

Solution: The examples of stack application are reverse a string, post fix evaluation, infix to postfix conversion.

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

INSTITUTE OF AERONAUTICAL ENGINEERING (Autonomous) Dundigal, Hyderabad

Data Structures Through C. Student Workbook

ENEE 150: Intermediate Programming Concepts for Engineers Spring 2018 Handout #27. Midterm #2 Review

Computer Graphics. Apurva A. Desai

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

CS8391-DATA STRUCTURES

12 Abstract Data Types

DATA COMMUNICATIONS AND COMPUTER NETWORKS

Transcription:

DATA STRUCTURES A Programming Approach with C SECOND EDITION DHARMENDER SINGH KUSHWAHA Associate Professor Department of Computer Science and Engineering Motilal Nehru National Institute of Technology (MNNIT) Allahabad ARUN KUMAR MISRA Professor Department of Computer Science and Engineering Motilal Nehru National Institute of Technology (MNNIT) Allahabad Delhi-110092 2014

DATA STRUCTURES: A Programming Approach with C, Second Edition (with CD-ROM) Dharmender Singh Kushwaha and Arun Kumar Misra 2014 by PHI Learning Private Limited, Delhi. All rights reserved. No part of this book may be reproduced in any form, by mimeograph or any other means, without permission in writing from the publisher. The authors and the publisher make no warranty of any kind, expressed or implied, with regard to programs contained in this companion CD. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs. ISBN-978-81-203-5029-8 The export rights of this book are vested solely with the publisher. Second Printing (Second Edition) September, 2014 Published by Asoke K. Ghosh, PHI Learning Private Limited, Rimjhim House, 111, Patparganj Industrial Estate, Delhi-110092 and Printed by Baba Barkha Nath Printers, Bahadurgarh, Haryana-124507.

To My parents Flt. Lt. Balwant Singh (Retd.) and Mrs. Savitri Singh, wife Seema, daughter Nikita & son Karan To Dharmender Singh Kushwaha My wife, Mrs. Kalpana Misra Arun Kumar Misra

Contents Preface xv 1. A Quick Overview of C Fundamentals 1 38 Introduction 1 Programming Fundamentals 1 Variables 2 Constants 2 Data Types 2 Flow Control 3 Type Conversion 5 Declaring, Initializing and Assigning Variables 5 Variable Scope 5 Operators 6 Arithmetic Operators 7 Relational Operators 7 Logical Operators 7 Assignment Operators 8 Ternary Operators 8 Bitwise Operators 9 Special Operators 9 Input/Output Instructions 9 Control Statements 11 Decision Control Instructions 11 Functions in C 16 Modifying Function Arguments 17 The Scope and Lifetime of Variables in Functions 18 Auto Specifier 18 Static Specifier 19 Register Specifier 19 Extern Specifier 20 Recursion 21 Arrays 21 Pointers 22 v

vi Contents Structures 23 sizeof Function 26 Structure and sizeof Function Structure Padding 26 Union 27 The Storage Class Qualifiers 28 Standard Library Functions 28 Let us Rewind! 29 Quiz 30 2. Introduction to Data Structure 39 60 Introduction 39 Data Types and Data Structures 40 Linear and Nonlinear Data Structures 41 Theta (Q) Notation: Average Case Behaviour 46 Big O(O) Notation: Wrost Case Behaviour 47 Omega (W) Notation: Best Case Behaviour 47 Computation of Asymptotic Notations 48 Best-case and Average-case Complexity 52 When do Constants Matter 53 Data Structures Widely Used in Computer Sciences 53 Let us Rewind! 55 Quiz 55 Review Questions 59 3. Understanding Pointers in C 61 94 Introduction 61 Pointer/Pointee 61 Dereference 61 Pointers and Arrays 66 Pointers and Two-dimensional Array 67 Operation with Pointers 69 Void Pointer or Generic Pointer 76 Dynamic Allocation of Memory 77 Dangling References 78 Null Pointers 78 Using a Null Pointer 78 Bad Pointer 78 Far and Near Pointer 79 Tricks to Tame Pointers 79 Pointers and Function 79 Pointers and Structures 81 Precedence and Associativity in Pointer Declaration 83 Miscellaneous Programs 85 Let us Rewind! 87 Quiz 88 Review Questions 94

Contents vii 4. Recursion 95 119 Introduction 95 Function Calls in Recursion 96 Recursive Function Calls Definition 96 How Recursive Function Call Works? 97 How Recursion Works? 99 Use of External Stack in Recursion 103 Recursive Data Structures 105 Type of Recursions 105 Classical Problems and Their Solution Using Recursion 110 The Tower of Hanoi Problem 110 Writing Linked List Backwards 111 Let us Rewind! 114 Quiz 115 Review Questions 118 5. Arrays 120 158 Introduction 120 1-Dimensional Array 121 Memory Space Required 121 Initializing 1-Dimensional Array 121 Implementation of 1-Dimensional Array in Memory 122 Basic Operations on Array 122 Character Array 126 Multi-dimensional Array 129 2-Dimensional Array 129 Initializing a 2-Dimensional Array 130 Implementation of 2-dimensional Array 135 3-Dimensional Array 138 Operations on Matrix 140 Matrix Addition 140 Matrix Multiplication 141 Matrix Transpose 141 Array as Parameter to a Function 144 Arrays and Pointers 145 Difference between Pointer to an Array and Array of Pointers 147 Array of Pointer 148 Array and Structures 149 Array within Structure Complex Structures 149 Array of Structure 149 Let us Rewind! 152 Quiz 152 Review Questions 158

viii Contents 6. Linked List 159 246 Introduction 159 Linked Lists Structure 160 Linked List Abstract Data Type 161 Singly Linked List 162 Insertion of an Element in a Singly Linked List 165 Deleting an Element from a Singly Linked List 166 Inserting Nodes in a Singly Linked List 166 Inserting Node at the End of Linked List 168 Deleting Nodes from a Linked List 171 Doubly Linked List 176 Inserting a Node at the Front of Doubly Linked List 177 Inserting Node at the End of a Doubly Linked List 179 Deleting a Node from the Front of a List 180 Deleting a Node from the End of a Doubly Linked List 181 Circular Linked List 182 Creating Circular Linked List 183 Operations on Circular Linked List 184 Inserting a Node at the Front of the Circular Linked List 184 Inserting a Node at the End of Circular Linked List 188 Deletion of Node from the Start of the Circular Linked List 192 Deleting Node from the Rear of Circular Linked List 197 Circularly Double Linked List 198 Inserting Node at the Front of a Doubly Circular Linked List 199 Inserting a Node at the End of the Doubly Circular Linked List 201 Deleting a Node from the Start of a Doubly Circular Linked List 210 Deleting Last Node from the Doubly Circular Linked List 210 Application of Linked List 215 Addition of Two Polynomials 215 Deciding on the Choice of the Linked List 238 Doubly Linked vs Singly Linked List 238 Circularly Linked vs Linearly Linked 238 Linked List Variants 238 Linked Lists Using Array of Nodes 239 Unrolled Linked List 239 Ordered List 240 Multi-linked list 240 Additional Useful Programs (In the CD) 241 Let us Rewind! 242 Quiz 243 Review Questions 245 7. Sorting 247 287 Introduction 247 Bubble Sort 247 Selection Sort 250

Contents ix Insertion Sort 252 Comparisons of Insertion Sort with Other Sorting Algorithms 254 Shell Sort 255 Bucket Sort 258 Heap Sort 261 Merge Sort 268 Complexity Analysis of Merge Sort 270 Quick Sort 271 Radix Sort 276 Let us Rewind! 282 Quiz 283 Review Questions 287 8. Strings 288 313 Introduction 288 String Implementation 288 A String ADT 289 Reading and Writing Strings: String I/O: gets() and puts() 290 Manipulating C Strings Using string.h 290 String Palindrome 297 Other Important Operations on Strings 299 Let us Rewind! 309 Quiz 309 Review Questions 313 9. Stacks 314 351 Introduction 314 Uses of Stacks in Computing 317 The Stack Abstract Data Type 317 Relevance of Stack in Function Call and Return 318 Push and Pop 320 Applications of Stack 322 Computation of Expressions 326 Infix Notation: a + b 327 Postfix Notation: ab+ 327 Prefix Notation: +ab 327 Reverse Polish Notation 332 Converting an Expression from Infix Notation to RPN 335 Converting Infix Expression to Prefix 340 Prefix to Infix Conversion 345 Let us Rewind! 346 Quiz 347 Review Questions 350

Data Structures: A Programming Approach 30% OFF Publisher : PHI Learning ISBN : 9788120350298 Author : Dharmender Singh Kushwaha Type the URL : http://www.kopykitab.com/product/7674 Get this ebook