Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Successfully reported this slideshow.

Like this presentation? Why not share!

1,948 views

Published on

No Downloads

Total views

1,948

On SlideShare

0

From Embeds

0

Number of Embeds

36

Shares

0

Downloads

0

Comments

0

Likes

4

No embeds

No notes for slide

- 1. Introduction to Data StructuresObjectivesIn this lesson, you will learn to: Classify and list the types of data structures List the types of arrays List the types of linked lists Implement nodes insertion on single linked list ©NIIT Introduction to Data Structures/Lesson 1/Slide 1 of 34
- 2. Introduction to Data Structures Data Structures Data Structure is : A collection of data items or objects Relationships among data items or objects Collection of functions or operations that can be applied to that data ©NIIT Introduction to Data Structures/Lesson 1/Slide 2 of 34
- 3. Introduction to Data Structures Types and Classification of Data Structures Some of the commonly used data structures are: Strings Arrays Linked Lists Stacks Queues Binary trees Graphs ©NIIT Introduction to Data Structures/Lesson 1/Slide 3 of 34
- 4. Introduction to Data Structures Types and Classifications of Data Structures (Contd..) Data structures can be classified into: Static data structures (one-dimensional array, two- dimensional array, and multi-dimensional array) Dynamic data structures (linked lists, binary trees, and graphs) Elastic data structures (stack, queue) Data structures can also be classified based on the linkages between the different structures: Linear Structures (arrays and linked lists) Hierarchical Structures (binary trees) ©NIIT Introduction to Data Structures/Lesson 1/Slide 4 of 34
- 5. Introduction to Data Structures Types and Classification of Data Structures (Contd..) Network Structures (graphs) ©NIIT Introduction to Data Structures/Lesson 1/Slide 5 of 34
- 6. Introduction to Data Structures Just a Minute… 2. An array is an example of dynamic data structure. (T/ F) 3. Queues works on a concept of FIFO. (T/F) 4. ______________________ are called terminal nodes. ©NIIT Introduction to Data Structures/Lesson 1/Slide 6 of 34
- 7. Introduction to Data Structures Types of Arrays Arrays are the simplest type of data structures Arrays are of two types: One-dimensional arrays Multi-dimensional arrays ©NIIT Introduction to Data Structures/Lesson 1/Slide 7 of 34
- 8. Introduction to Data Structures One-dimensional Arrays Example: Let NOFDAYS be an array of 12 element representing total number of days in a month. int NOFDAYS[12]; Then, NOFDAYS[0] = 31 NOFDAYS[1] = 28 NOFDAYS[2] = 31 and so on... The array will be represented as shown in the following figure: 31 28 31 30 31 30 NOFDAYS[0] NOFDAYS[1] NOFDAYS[2]… ©NIIT Introduction to Data Structures/Lesson 1/Slide 8 of 34
- 9. Introduction to Data Structures Multi-dimensional Arrays Programming languages like PASCAL, COBOL, C, and C++ allow declaration of multidimensional arrays. These can be stored in the memory in the following two ways: Row-major order: The elements are listed so that the last element varies first (more rapidly). Then, the second last element varies next (less rapidly) and so on. Column-major order : The elements are listed so that the first element varies more rapidly then, the second element varies next and so on. ©NIIT Introduction to Data Structures/Lesson 1/Slide 9 of 34
- 10. Introduction to Data Structures Array Referencing Elements of an array are stored in contiguous locations To reference an element in the array we need to know only the address of the starting element The first element’s address can be denoted as the base address of the array The first element number is known as Lower Bound The last element number is known as Upper Bound ©NIIT Introduction to Data Structures/Lesson 1/Slide 10 of 34
- 11. Introduction to Data Structures Array Referencing (Contd..) From the base address, the computer will calculate the address of any element with the formula: BA+LEN*(ENUM- FNUM)=Address of the required element Where, BA is the Base Address LEN is the length per element ENUM is the element Number FNUM is the first element number ©NIIT Introduction to Data Structures/Lesson 1/Slide 11 of 34
- 12. Introduction to Data Structures Multi-dimensional Arrays (Contd..) (1, 1) (1, 1) (2, 1) (1, 2) Column 1 (3, 1) (1, 3) Row 1 (1, 2) (1, 4) (2, 2) Column 2 (2, 1) (3, 2) (2, 2) (1, 3) (2, 3) Row 2 (2, 3) (2, 4) Column 3 (3, 3) (3, 1) (1, 4) (3, 2) (2, 4) (3, 3) Row 3 Column 4 (3, 4) (3, 4) Column‑major order Row‑major order ©NIIT Introduction to Data Structures/Lesson 1/Slide 12 of 34
- 13. Introduction to Data Structures Just a Minute… 2. Find the address of numbers [13] and numbers [40] of the array numbers [40] assuming a Base address of 250 and length of each element as 4. 3. Matrix is an example of _________ dimensional array. 4. How many types of arrays are available? ©NIIT Introduction to Data Structures/Lesson 1/Slide 13 of 34
- 14. Introduction to Data Structures Array Complexities Inserting and deleting from array involves complexities. If an element is deleted from the middle of an array, then that element remains empty unless all the names in the succeeding elements are moved back by one element position to occupy the empty element. If an element is inserted in the middle of an array, all names have to be moved forward by one element position. ©NIIT Introduction to Data Structures/Lesson 1/Slide 14 of 34
- 15. Introduction to Data Structures Linked Lists A linked list is a chain of objects in which each object consists of the data and a pointer that stores the address (link) of the next logical object in the list. The main advantages of linked lists are: Memory is allocated whenever required. Inserting to and deleting from linked lists can be handled efficiently without having to restructure the list. ©NIIT Introduction to Data Structures/Lesson 1/Slide 15 of 34
- 16. Introduction to Data Structures Types of Linked Lists Linked lists can be of different types: Single linked list Circular linked list Double linked list ©NIIT Introduction to Data Structures/Lesson 1/Slide 16 of 34
- 17. Introduction to Data Structures Single Linked List Is a chain of structures in which each structure consists of data and a pointer to the address of next subsequent node START Data LINK Data LINK Data LINK Data LINK NULL ©NIIT Introduction to Data Structures/Lesson 1/Slide 17 of 34
- 18. Introduction to Data Structures Circular Linked List Has the START pointer pointing to the first node and the last pointer also pointing to the first node START Data LINK Data LINK Data LINK Data LINK ©NIIT Introduction to Data Structures/Lesson 1/Slide 18 of 34
- 19. Introduction to Data Structures Double Linked List Has 3 parts: the INFO, NEXT pointer, and PREV pointer Is also called a two-way list LAST START NULL PREV Data NEXT PREV Data NEXT NULL PREV Data NEXT ©NIIT Introduction to Data Structures/Lesson 1/Slide 19 of 34
- 20. Introduction to Data Structures Operations on Lists Are: Insertion Traversal Deletion Modification Sorting ©NIIT Introduction to Data Structures/Lesson 1/Slide 20 of 34
- 21. Introduction to Data Structures Some Common Applications of Lists Are: Word processing applications Index maintenance in a file-based database package Maintenance of linked lists for data files that have read-write overhead ©NIIT Introduction to Data Structures/Lesson 1/Slide 21 of 34
- 22. Introduction to Data Structures Complexities in Lists Are: The START pointer, pointing to the first node, cannot be moved as it depicts the starting point of the list. ©NIIT Introduction to Data Structures/Lesson 1/Slide 22 of 34
- 23. Introduction to Data Structures Single Linked List The three basic classes that are required to make a complete linked list are as follows: A class to represent the DATA or INFO part of the node. The Node class, which contains an object of the built-in data class called INFO and a pointer to a Node object called NEXT. The List class that will contain the start pointer to a Node object. ©NIIT Introduction to Data Structures/Lesson 1/Slide 23 of 34
- 24. Introduction to Data Structures Insertion Of Nodes In A Linked List Insertion involves adding a new node to an existing linked list or creating a new linked list if one does not already exist. Insertion can be performed: At the beginning of the list In the middle of the list At the end of the list ©NIIT Introduction to Data Structures/Lesson 1/Slide 24 of 34
- 25. Introduction to Data Structures Inserting a Node at the Beginning of a Linked List Existing Links on the list Links after inserting the new node START INFO NEXT INFO NEXT INFO NEXT NULL INFO NEXT ©NIIT Introduction to Data Structures/Lesson 1/Slide 25 of 34
- 26. Introduction to Data Structures Inserting a Node at the Beginning of a Linked List (Contd..) Requires to: Check whether or not the list exists Check whether the user supplied string is lesser than the INFO in the first node ©NIIT Introduction to Data Structures/Lesson 1/Slide 26 of 34
- 27. Introduction to Data Structures Inserting a Node in the Middle or at the End of a Linked List prev START curr Ann NEXT Tom NEXT NEXT NULL Existing Links on the list NEXT Links after inserting the new node ©NIIT Introduction to Data Structures/Lesson 1/Slide 27 of 34
- 28. Introduction to Data Structures Inserting a Node in the Middle or at the End of a Linked List (Contd..) Requires to: Allocate the memory for the new node. Position the pointer prev on the node after which the new node is to be inserted and the pointer curr to be positioned on the node before which the new node is to be inserted. Complete the link by making the NEXT of the previous node point to the new node. ©NIIT Introduction to Data Structures/Lesson 1/Slide 28 of 34
- 29. Introduction to Data Structures Problem Statement 1.D.1 Create an application that accepts the names of an unknown number of customers and displays them in alphabetical order. ©NIIT Introduction to Data Structures/Lesson 1/Slide 29 of 34
- 30. Introduction to Data StructuresSummaryIn this lesson, you learned that: Data structures are a collection of data values, the relationships among them, and the functions or operations that can be applied to the data. Some of the commonly used data structures are: Strings Arrays Linked lists Stacks Queues ©NIIT Introduction to Data Structures/Lesson 1/Slide 30 of 34
- 31. Introduction to Data StructuresSummary (Contd..) Binary trees Graphs Data structures can be categorized as: Static data structures (multi-dimensional arrays) Dynamic data structures (linked lists, binary trees graphs) Elastic data structures (stack, queue) The array is the simplest type of data structure. The elements of an array are stored in contiguous locations. ©NIIT Introduction to Data Structures/Lesson 1/Slide 31 of 34
- 32. Introduction to Data StructuresSummary (Contd..) Arrays are of two types—One-dimensional array (also called linear array) and multi-dimensional arrays. Arrays will be stored in memory by the programming language in one of the two ways available: Column-major order Row-major order Linked lists can be of different types: Single linked list Circular linked list Double linked list ©NIIT Introduction to Data Structures/Lesson 1/Slide 32 of 34
- 33. Introduction to Data StructuresSummary (Contd..) The different operations that can be performed on a linked list are: Insertion Traversal Modification Deletion The three classes, which make a complete linked list are as follows: A class to represent the data or INFO part of the node The Node class, which will contain an object of the built-in data class called INFO and a pointer to a Node object called NEXT ©NIIT Introduction to Data Structures/Lesson 1/Slide 33 of 34
- 34. Introduction to Data StructuresSummary (Contd.) The List class that will contain the starting pointer to a Node object The insertion of a node can be performed at three different levels: At the beginning of the list In the middle of the list At the end of the list ©NIIT Introduction to Data Structures/Lesson 1/Slide 34 of 34

No public clipboards found for this slide

Be the first to comment