Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

concepts of Data structure

Rating
-
Sold
-
Pages
17
Uploaded on
07-03-2024
Written in
2023/2024

ata structures are essential components that help organize and store data efficiently in computer memory. They provide a way to manage and manipulate data effectively, enabling faster access, insertion, and deletion operations. Common data structures include arrays, linked lists, stacks, queues, trees, and graphs , each serving specific purposes based on the requirements of the problem at hand. Understanding data structures is fundamental for designing efficient algorithms and optimizing software performance.

Show more Read less
Institution
Course

Content preview

UNIT II

LINEAR DATA STRUCTURES
Stack : Definition Operation, Uses, Implementation etc.,
Queue: Definition, Operations, Uses, Implementation, Types of Queue etc.,
Linked List: Definition, Operation, Uses, Implementation, Types (Singly, Doubly, Circular)

LINEAR DATA STRUCTURE

Linear data structure is a type of structure where data items are arranged in a linear fashion
(sequential elements).

Each data elements are attached to their members (previous and next elements).

Data storage is allowed in only single level as elements are attached in linear fashion.

Data traversal is only one run.

Such data structures are easy to implement as the computer memory is also sequential.

Linear data structures include,

 Arrays,
 Stack
 Queue
 Linked Lists



Arrays

Arrays are collection of elements stored in contiguous memory.

It is used to store homogenous elements at contiguous locations.

The size of an array need to be provided much before storing data.

Array uses index based data structure for identifying each of the elements.

Arrays can be categorized as single dimensional array and double dimensional array.




Practice Questions

1. Write a program in C to read n number of values in an array and display them in
reverse order.
2. Write a program in C to copy the elements of one array into another array.
3. Write a program in C to count the total number of duplicate elements in an array.

,Uses

Arrays can be used for sorting data elements.

It is used for storing contacts on a mobile device, storing data in table format, performing
matrix operations.

Operation

Analysis of Arrays

Let the size of an array be n,

Accessing Time : O(1) (Constant Time)

All elements are stored in contiguous memory locations.

Searching Time: O(n) (Linear Time)

Linear Time in case of sequential search.

O(log n) in case of binary search.

Inserting Time: O(n)

Deleting Time : O(n)

Advantages

1. Arrays take constant time to access its elements.
2. Memory allocation / location is contiguous.
3. The method of implementation is easy.



Stack
A Stack ( LIFO – Last in First Out) is an ADT (Abstract Data Type)

It is a collection of elements.

It has two principal operations : Push() and Pop().

Push() adds elements into the collection where as Pop() removes elements from the
collection.

Pop() always removes elements that are added last.

Both operations take place at the same end that is at the top of the stack.

Analysis

, Insertion time takes  O(1)

The time taken to insert elements into a stack is constant represented by O(1).

Deletion time takes  O(1)

The time taken to delete elements from a stack is constant represented by O(1).

Access time

Acesssing time of elements in a stack takes O(n) ( linear time) (Worst Case)

That is, in simple terms, as input grows time taken also grows linearly.

Where all Stack used ? (Application of Stack)

1) Stacks are used in function calls.
2) Stacks are used in reversing a word
3) Check for balanced parenthesis
4) In Editors, the last typed word is the first to be removed (Undo operation).

Operations

push()  An element is inserted into stack

pop() An element is popped out of stack.

top()  This will return the last inserted element.

size ()  This will return the size of the stack.

isEmpty()  This indicates if the stack is empty or not

isFull()  This indicates if the stack is full or not.



Implementation of (Sample Programs) stack functions.
(Pending)
#include <stdio.h>


// stack using array with choices.
#define MAX_SIZE 5

int ctr=0;
int stack[MAX_SIZE];
int top = -1;
int elements;

int push()

Written for

Course

Document information

Uploaded on
March 7, 2024
Number of pages
17
Written in
2023/2024
Type
Class notes
Professor(s)
Sudha
Contains
All classes

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
manoj2

Get to know the seller

Seller avatar
manoj2 HICET
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
7
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions