Download presentation
Presentation is loading. Please wait.
1
Data Structure By Amee Trivedi
2
What is Data Structure Data structure is a particular way of storing and organizing data in a computer so that it can be used efficiently. It provide a means to manage huge amounts of data. They are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by an address. The implementation of a data structure usually requires writing a set of procedures that create and manipulate instances of that structure. Different kinds of data structures are suited to different kinds of applications.
3
Concept of Array and Pointer
Array is a collection of same type elements under the same variable identifier referenced by index number. It saves the memory space. It helps to arrange the data items in particular order. Searching is faster. use one name for similar objects. Can not be resize at runtime.
4
Concept of Array and Pointer(cont.)
A pointer is a variable which contains the address in memory of another variable. Dynamic memory allocations To return multiple value via functions. Manipulation of data at their memory location is easier. Two types of operator are use : & and * & is give the memory address of variable * is give the value of variable
5
Concept of Array and Pointer(cont.)
Example of pointer Int I =10; value Address &I -> points address is 2005 *I -> points value is 10 10 2005
6
Concept of Linked List Linear collection of class objects, called nodes Connected by pointer links Accessed via a pointer to the first node of the list Subsequent nodes are accessed via the link-pointer member of the current node Link pointer in the last node is set to null to mark the list’s end You have an unpredictable number of data elements Your list needs to be sorted quickly
7
Types of Linked List Singly linked list Circular, singly linked
Begins with a pointer to the first node Terminates with a null pointer Only traversed in one direction Circular, singly linked Pointer in the last node points back to the first node Doubly linked list Two “start pointers” – first element and last element Each node has a forward pointer and a backward pointer Allows traversals both forwards and backwards Circular, doubly linked list Forward pointer of the last node points to the first node and backward pointer of the first node points to the last node
8
Singly Linked Lists A singly linked list is a concrete data structure consisting of a sequence of nodes. Each node stores element and link to the next node. A B C D
9
Doubly Linked List Nodes store element, link to the previous node and link to the next node. It has special trailer and header nodes. trailer header nodes/positions
10
Circular Linked List Storing address of the first node in the link field of the last node. A B C D
11
Concept of Stack Stacks are linear lists.
All deletions and insertions occur at one end of the stack known as the TOP. Data going into the stack first, leaves out last. Stacks are also known as LIFO data structures (Last-In, First-Out). Bottom of stack indicated by a link member to NULL Stacks structures are usually implemented using arrays or linked lists. Similar to a pile of dishes
12
Stack Operation Push Pop Adds a new node to the top of the stack
Removes a node from the top Stores the popped value Returns true if pop was successful
13
Stack Applications Reversing Data Converting Decimal to Binary
Evaluating arithmetic expressions Prefix: + a b Infix: a + b Postfix: a b + Infix to Postfix Conversion
14
Example of Infix to Postfix Conversion
E.g 1 A + B * C Infix A + (B * C) A + (B C *) A (B C *) + A B C * + Postfix E.g 2 (A + B) * C Infix (A B +) * C (A B +) C * A B + C * Postfix
15
Concept of Queue Queue is an ADT data structure similar to stack, except that the first item to be inserted is the first one to be removed. Nodes are removed only from the head is front end. Nodes are inserted only at the tail is rear end. Similar to a supermarket checkout line It follow First-in, first-out (FIFO) method. Insert(Enqueue) and remove(dequeue) operations. Queues can be implemented using an array or using a linked list.
16
Queue Application line of people waiting for a bank teller. Rear Front
$ $
17
Queue Application New people must enter the queue at the rear.
Rear Front $ $
18
Queue Application When an item is taken from the queue, it always comes from the front. Rear Front $ $
19
Concept of Tree Tree nodes contain two or more links Binary trees
All nodes contain two links The root node is the first node in a tree. Each link in the root node refers to a child A node with no children is called a leaf node
20
Tree traversals Inorder traversal – prints the node values in ascending order 1. Traverse the left subtree with an inorder traversal 2. Process the value in the node (i.e., print the node value) 3. Traverse the right subtree with an inorder traversal Preorder traversal 1. Process the value in the node 2. Traverse the left subtree with a preorder traversal 3. Traverse the right subtree with a preorder traversal Postorder traversal 1. Traverse the left subtree with a postorder traversal 2. Traverse the right subtree with a postorder traversal 3. Process the value in the node
21
Example of Traversals Preorder: 15 8 2 6 3 7 11 10 12 14 20 27 22 30
Inorder: Postorder: 6 15 8 2 3 7 11 10 14 12 20 27 22 30
22
Thank You
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.