IT training c data structures deshpande kakde 2004 01 15

695 14 0
  • Loading ...
1/695 trang
Tải xuống

Thông tin tài liệu

Ngày đăng: 05/11/2019, 15:54

ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html C & Data Structures P S Deshpande O G Kakde CHARLES RIVER MEDIA, INC Hingham, Massachusetts Copyright © 2003 Dreamtech Press Reprint Copyright © 2004 by CHARLES RIVER MEDIA, INC All rights reserved No part of this publication may be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means or media, electronic or mechanical, including, but not limited to, photocopy, recording, or scanning, without prior permission in writing from the publisher Acquisitions Editor: James Walsh Production: Dreamtech Press Cover Design: Sherry Stinson CHARLES RIVER MEDIA, INC 10 Downer Avenue Hingham, Massachusetts 02043 781-740-0400 781-740-8816 (FAX) info@charlesriver.com http://www.charlesriver.com Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html P.S Deshpande and O.G Kakde C & Data Structures 1-58450-338-6 All brand names and product names mentioned in this book are trademarks or service marks of their respective companies Any omission or misuse (of any kind) of service marks or trademarks should not be regarded as intent to infringe on the property of others The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products Library of Congress Cataloging-in-Publication Data Deshpande, P S C & data structures / P.S Deshpande, O.G Kakde p cm ISBN 1-58450-338-6 (Paperback with CD-ROM : alk paper) C (Computer program language) Data structures (Computer science) I Kakde, O G II Title QA76.73.C15D48 2003 005.7'3—dc22 2003021572 04 First Edition CHARLES RIVER MEDIA titles are available for site license or bulk purchase by institutions, user groups, corporations, etc For additional information, please contact the Special Sales Department at 781-740-0400 Requests for replacement of a defective CD-ROM must be accompanied by the original disc, your mailing address, telephone number, date of purchase and purchase price Please state the nature of the problem, and send the information to CHARLES RIVER MEDIA, INC., 10 Downer Avenue, Hingham, Massachusetts 02043 CRM's sole obligation to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not on the operation or functionality of the product Acknowledgments Writing any book is not an easy task We spent about one year designing the contents, implementing the programs and testing the programs Our 12 years of teaching experience has helped us to explain the issues in the language and complex problems in data structures We are thankful to our student Rupesh Nasre who, after receiving an M.Tech degree in computer science from IIT Mumbai, helped us in implementing advanced problems in data structures We are also thankful to our students Ms Usha Agrawal and Mr Ramchandra Vibhute for helping us in writing programs for II Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html C & Data Structures byP.S DeshpandeandO.G Kakde ISBN:1584503386 Charles River Media 2004 (700 pages) This thorough text provides a comprehensive guide to all the data types in C with internal implementation, while providing examples to demonstrate their behavior Table of Contents C & Data Structures Preface Part I - C Language Chapte - Introduction to the C Language r1 Chapte - Data Types r2 Chapte - C Operators r3 Chapte - Control Structures r4 Chapte - The printf Function r5 Chapte - Address and Pointers r6 Chapte - The scanf Function r7 Chapte - Preprocessing r8 Chapte - Arrays r9 Chapte - Function r 10 Chapte - Storage of Variables r 11 Chapte - Memory Allocation r 12 Chapte - Recursion r 13 Chapte - Strings r 14 Chapte - Structures r 15 Chapte - Union r 16 Chapte - Files r 17 Part II - Data Structures Chapte - Arrays, Searching, and Sorting Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html r 18 Chapte - Stacks and Queues r 19 Chapte - Linked Lists r 20 Chapte - Trees r 21 Chapte - Graphs r 22 Part III - Advanced Problems in Data Structures Chapte - Problems in Arrays, Searching, Sorting, Hashing r 23 Chapte - Problems in Stacks and Queues r 24 Chapte - Problems in Linked Lists r 25 Chapte - Problems in Strings r 26 Chapte - Problems in Trees r 27 Chapte - Problems in Graphs r 28 Chapte - Miscellaneous Problems r 29 Index List of Figures List of Tables Back Cover CD Content Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Preface The book is written for both undergraduate and graduate students of core computer science areas The book would be very useful for other students to learn programming for the purpose of making a career in computer science It covers all those topics that generally appear in aptitude tests and interviews It not only gives the language syntax but also discusses its behavior by showing the internal implementation We have covered almost the entire range of data structures and programming such as non-recursive implementation of tree traversals, A* algorithm in Artificial Intelligence, 8-queens problems, etc We also have supplied a CD-ROM which contains all the source material that appears in the book We welcome comments from our readers Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Part I: C Language Chapter 1: Introduction to the C Language Chapter 2: Data Types Chapter 3: C Operators Chapter 4: Control Structures Chapter 5: The printf Function Chapter 6: Address and Pointers Chapter 7: The scanf Function Chapter 8: Preprocessing Chapter 9: Arrays Chapter 10: Functions Chapter 11: Storage of Variables Chapter 12: Memory Allocation Chapter 13: Recursion Chapter 14: Strings Chapter 15: Structures Chapter 16: Union Chapter 17: Files Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Chapter 1: Introduction to the C Language THE FIRST PROGRAM IN C Introduction The C program is a set of functions The program execution begins by executing the function main () You can compile the program and execute using Turbo C compiler or using the following commands in Unix/Linux: $ cc -o a a.c where a.c is the file in which you have written the program This will create an executable file named a.exe $./a This will execute the program Program #include main() { printf("Hello \n"); /* prints Hello on standard output */ } Output : Hello Explanation The program execution begins with the function main() The executable statements are enclosed within a block that is marked by ‘{’ and ‘}’ The printf() function redirects the output to a standard output, which in most cases is the output on screen Each executable statement is terminated by ‘;’ The comments are enclosed in ‘/* */’ Variables Introduction When you want to process some information, you can save the values temporarily in variables In the following program you can define two variables, save the values, and put the addition in the third variable Program #include main() { int i,j,k; // Defining variables Statement A i = 6; // Statement B j = 8; k = i + j; Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html printf("sum of two numbers is %d \n",k); // Printing results } output : sum of two numbers is 14 Explanation Statement A defines variables of the type integer For each variable you have to attach some data type The data type defines the amount of storage allocated to variables, the values that they can accept, and the operations that can be performed on variables The ‘ // ’ is used as single line comment The ‘%d’ is used as format specifier for the integer Each data type has a format specifier that defines how the data of that data type will be printed The assignment operator is ‘=’ and the statement is in the format: Var = expression; Points to Remember The variables are defined at the begining of the block The data type is defined at the begining of declaration and followed by a list of variables It is the data type that assigns a property to a variable Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html INPUTTING THE DATA Introduction In C, the input from a standard input device, such as a keyboard, is taken by using the function scanf In scanf, you have to specify both the variables in which you can take input, and the format specifier, such as %d for the integer Program #include main() { int i,j,k; scanf("%d%d",&i,&j); // statement A k = i + j; printf("sum of two numbers is %d \n",k); } Input Output: sum of two numbers is Explanation Statement A indicates the scanf statement that is used for taking input In scanf you have to specify a list of addresses of variables (&i, &j) which can take input Before specifying the list of variables you have to include a list of format specifiers that indicate the format of the input For example, for the integer data type the format specifier is %d In scanf, you have to specify the address of the variable, such as &i The address is the memory location where a variable is stored The reason you must specify the address will be discussed later The number of format specifiers must be the same as the number of variables Point to Remember In scanf, you have to specify the address of a variable, such as &i, &j, and a list of format specifiers Page ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html THE CONTROL STATEMENT (if STATEMENT) Introduction You can conditionally execute statements using the if or the if else statement The control of the program is dependent on the outcome of the Boolean condition that is specified in the if statement Program #include main() { int i,j,big; //variable declaration scanf("%d%d",&i,&j); big = i; if(big < j) { // statement A // C big = j; } // Part Z, then part // D printf("biggest of two numbers is %d \n",big); if(i < j) // statement B { big = j; // Part X } else { big = i; // Part Y } printf("biggest of two numbers(using else) is %d \n",big); } Explanation 10 Statement A indicates the if statement The general form of the if statement is if(expr) { s1 ; s2 ; } expr is a Boolean expression that returns true (nonzero) or false (zero) In C, the value nonzero is true while zero is taken as false If you want to execute only one statement, opening and closing braces are not required, which is indicated by C and D in the current program 11 The else part is optional If the if condition is true then the part that is enclosed after the if is executed (Part X) If the if condition is false then the else part is executed (Part Y) 12 Without the else statement (in the first if statement), if the condition is true then Part Z is executed Points to Remember if and if else are used for conditional execution After the if statement the control is Page 10 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index O Octal numbers 21 One-dimensional array 167 Operator precedence 43 Overflow chaining 219 Page 681 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index P Parameter passing 106 Placeholders 58 Pointers 64 Postfix expression 240 Precision 60 Precision 58 Prefix expression 241 Preorder 355 Preprocessor 71 Prim's algorithm 414 printf function 57 Programming 141 Page 682 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index Q qsort 197 Queue 242 Quick sort 195 Page 683 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index R Random access 148 Random-access data structure 167 Recursion 127 Recursive function 128 Recursive programs 267 Register variables 118 Rehashing 219 Relational operator 34 Right shift operation 43 Row-major representation 168 Page 684 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index S Saddle point 189 of a matrix 439 scanf 67 scanf placeholder 68 Searching 192 Selection structure 45 Sequential file operations open 147 read 147 write 147 close 147 Sequential mapping 167 Sequential search 210 Sequential structure 45 Singly linked circular list 325 Sorted list merging 180 Sorting 192 Sparse matrices 308 Stack 103 Stack overheads 128 Stacks 227 applications 236 implementation using array 228 implementation using linked representation 231 push operation 228 pop operation 228 Static lifetime, of variables 115 Storage, of variables 115 String argument 67 String 133 Structure pointers 143 Structures 137 Swapping of left and right subtrees 367 switch Statement 50 Symbol table 217 Page 685 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index T Target key 370 Ternary operator 37 The all-cost shortest path 661 Three-dimensional array 95 Topological sort 632 Trees 347 Two-class classification 667 Two-dimensional array 168 Type casting 27 Type conversion 25 Type indicators 68 Type prefixes 59 Type identifiers 58 Page 686 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index U Unary operators 32 undef directive 72 Union 145 Page 687 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index V Value 63 Page 688 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Index W-Z while loop 51 Page 689 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html List of Figures Chapter 18: Arrays, Searching, and Sorting Figure 18.1: Representation of an array Figure 18.2: Row-major representation of a two-dimensional array Figure 18.3: Column major representation of a two-dimensional array Figure 18.4: Implementation of a static contiguous list Figure 18.5: A heap Figure 18.6: Hash table implementation using overflow chaining for collision handling Chapter 19: Stacks and Queues Figure 19.1: Stack operations Figure 19.2: Linked stack Figure 19.3: Operations on a queue Figure 19.4: Circular queue Figure 19.5: Linked queue Chapter 20: Linked Lists Figure 20.1: Sorting of a linked list Figure 20.2: A linked list showing the previous, current, and next nodes at some point during reversal process Figure 20.3: Sorting of a linked list Figure 20.4: Reversal of a list Figure 20.5: Before deletion Figure 20.6: After deletion Figure 20.7: Before insertion Figure 20.8: After insertion Figure 20.9: Insertion in a sorted list Figure 20.10: Polynomial representation Figure 20.11: A sparse matrix Figure 20.12: Linked list representation of sparse matrix of Figure 20.11 Figure 20.13: Result of application of the procedure sadd Figure 20.14: A circular list Page 690 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Figure 20.15: (A) A circular list with head node, (B) an empty circular list Figure 20.16: List containing 2n nodes Figure 20.17: Splitting of a circular list Figure 20.18: A doubly linked list maintained as chain Figure 20.19: A doubly linked list maintained as a circular list Figure 20.20: A doubly linked list maintained as a circular list with a header node Figure 20.21: Before termination of process p1 Figure 20.22: After termination of process p1 Chapter 21: Trees Figure 21.1: A tree structure Figure 21.2: A non-tree structure Figure 21.3: Binary tree structure Figure 21.4: Skewed trees Figure 21.5: A full binary tree Figure 21.6: A complete binary tree Figure 21.7: An array representation of a complete binary tree having nodes and depth Figure 21.8: An array representation of a complete binary tree with nodes and depth Figure 21.9: An array representation of a binary tree Figure 21.10: Linked representation of a binary tree Figure 21.11: A binary tree along with its inorder, preorder and postorder Figure 21.12: A binary tree of an expression along with its inorder and postorder Figure 21.13: Binary trees constructed using the given inorder Figure 21.14: A unique binary tree constructed using its inorder and postorder Figure 21.15: The binary search tree Figure 21.16: A unique binary tree constructed using the inorder and postorder Figure 21.17: A binary tree before deletion of a node pointed to by x Figure 21.18: A binary tree after deletion of a node pointed to by x Figure 21.19: A binary tree after deletion of a node pointed to by x Figure 21.20: A binary tree before deletion of a node pointed to by x Figure 21.21: A binary tree after deletion of a node pointed to by x Figure 21.22: A binary tree before deletion of a node pointed to by x Figure 21.23: A binary tree after deletion of a node pointed to by x Page 691 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Chapter 22: Graphs Figure 22.1: Graphs Figure 22.2: The subgraph of graph G2 Figure 22.3: Graph G Figure 22.4: Induced subgraph of Graph G of Figure 22.3 Figure 22.5: A connected graph Figure 22.6: A completely connected graph Figure 22.7: Adjacency matrices Figure 22.8: Adjacency list of G1 Figure 22.9: Graph G and its depth first traversals starting at vertex Figure 22.10: Breadth-first traversal of graph G starting at vertex v1 Figure 22.11: Connected component of G1 Figure 22.12: A diagraph Figure 22.13: Strongly connected components of the graph shown in Figure 22.12 Figure 22.14: Graph G Figure 22.15: Depth first spanning tree of the graph of Figure 22.14 Figure 22.16: Breadth-first spanning tree of the graph of Figure 22.14 Figure 22.17: A directed graph G Figure 22.18: Depth-first spanning forest for the graph G of Figure 22.17 Figure 22.19: A graph G Figure 22.20: Depth-first spanning tree of the graph G of Figure 22.19 Figure 22.21: A graph G Figure 22.22: The minimum-cost spanning tree of graph G of Figure 22.21 Figure 22.23: Directed acyclic graph Figure 22.24: DAG representation of expression (a+b)*c +((a+b) + e) Figure 22.25: A graph G Chapter 29: Miscellaneous Problems Figure 29.1: A knight can move to a maximum of eight positions Page 692 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html List of Tables Chapter 2: Data Types Table 2.1: Integer data type storage allocations Chapter 3: C Operators Table 3.1: Comparing the equality operator (= =) with the ‘=’ assignment operator Table 3.2: Results of AND, OR, and Negation Table 3.3: Operator precedence rules Chapter 17: Files Table 17.1: Random access Chapter 19: Stacks and Queues Table 19.1: Scanning the infex expression a*b+c/d from right to left Page 693 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html Back Cover Divided into three separate sections, C & Data Structures covers C programming, as well as the implementation of data structures and an analysis of advanced data structure problems Beginning with the basic concepts of the C language (including the operators, control structures, and functions), the book progresses to show these concepts through practical application with data structures such as linked lists and trees, and concludes with the integration of C programs and advanced data structure problem-solving The book covers a vast range of data structures and programming issues, such as syntactic and semantic aspects of C, all control statements in C, concepts of function, macro, files and pointers with examples, graphs, arrays, searching and sorting techniques, stacks and queues, files, and preprocessing C & Data Structures provides a comprehensive guide to all the data types in C with internal implementation, while providing examples to demonstrate their behavior KEY FEATURES  Explains all operators, expressions, control statements, and rules of C in detail  Demonstrates language syntax, as well as discussing its behavior by showing specific internal implementations  Covers data structures such as linked lists, trees, graphs, arrays, and commonly used algorithms, as well as advanced data structures such as B- trees and B+ trees About the Authors P.S Deshpande is a faculty member in the Department of Computer Science at Visvesvarya National Institute of Technology He has acted as a consultant to various government and private organizations in the field of database management, software engineering, data warehousing, WAP, and J2EE design patterns, and has published a number of papers on Oracle, data warehousing, and programming languages O.G Kakde is also a faculty member in the Department of Computer Science at Visvesvarya National Institute of Technology He has done consulting work for the government as well as private organizations in the fields of embedded systems, language translators, WAP, and several programming languages He is the author of Algorithms for Compiler Design Page 694 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html CD Content Following are select files from this book's Companion CD-ROM These files are for your personal use, are governed by the Books24x7 Membership Agreement, and are copyright protected by the publisher, author, and/or other third parties Unauthorized use, reproduction, or distribution is strictly prohibited Click on the link(s) below to download the files to your computer: File All CD Content Description Size 79,201 Page 695 ... C & data structures / P.S Deshpande, O.G Kakde p cm ISBN 1-58450-338-6 (Paperback with CD-ROM : alk paper) C (Computer program language) Data structures (Computer science) I Kakde, O G II Title... 14 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html checked after each iteration Page 15 ABC Amber CHM Converter Trial version, http://www.processtext.com/abcchm.html... characters are stored internally as integers Since each character can have bits, you can have 256 different character values (0–255) Each integer is associated with a character using a character
- Xem thêm -

Xem thêm: IT training c data structures deshpande kakde 2004 01 15 , IT training c data structures deshpande kakde 2004 01 15 , [Trial version] THE do...while LOOP

Mục lục

Xem thêm

Gợi ý tài liệu liên quan cho bạn