Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

design

Beoordeling
-
Verkocht
-
Pagina's
25
Geüpload op
06-04-2025
Geschreven in
2024/2025

1. Understand the Problem Before designing anything, ask: What operations need to be fast? (Insert, delete, search, update?) Are there any constraints on memory? Do I need to preserve order, uniqueness, or frequency? How big is the dataset? Will it grow? 2. Choose a Suitable Data Structure Depending on the problem, you might choose from: Problem Good Candidate Fast lookups Hash Map / Hash Table Sorted data Binary Search Tree, Heap First-in-first-out Queue Last-in-first-out Stack Graph relationships Graph (Adjacency List/Matrix) Range queries Segment Tree, Binary Indexed Tree Fast access by index Array / List 3. Custom Data Structures Sometimes built-ins aren't enough. You might need to: Combine data structures (e.g. HashMap + LinkedList for LRU cache) Optimize for space (e.g. Tries for autocomplete) Design with trade-offs (e.g. skip lists for probabilistic balance) 4. Example: LRU Cache You want: Fast access (O(1)) to check if an item is in cache Fast insert + delete Fast access to "least recently used" item Solution: HashMap for lookup Doubly Linked List for order This is a classic example of designing a hybrid data structure to meet multiple needs. 5. Test the Design Think through edge cases: What if it’s empty? What if the data structure is full? What if you repeatedly insert/delete the same elements?

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

INSTITUTE OF ENGINEERING AND TECHNOLOGY
T. M. Palayam, Coimbatore-641 105
(Approved by AICTE, New Delhi and Affiliated to Anna University, Chennai)
Accredited by NAAC “A+”, Recognized by UGC under Section 2(f) and 12(B)
NBA ACCRDIATED COURSES: AERO&CSE


UNIT – II
LINEAR DATA STRUCTURES - LIST

What is a Data Structure?
A Data Structure is a collection of data elements which defines the way of storing and
organizing data in a computer so that it can be used efficiently.
It comprises of

• a collection of data elements
• the relationships among them and
• the functions or operations that can be applied to the data.

Why is Data Structure needed?
• It influences the ability of a computer to store/retrieve data to/from any location in the
memory.

• It enables a computer system to perform its task more efficiently.
Classification of Data Structures
Data structures can be classified into two classes namely:
Primitive data structures and Non-Primitive data structures.
A primitive data structure refers to the fundamental data types which are supported by a
programming language. Examples are integer, real, character, and boolean. Non-primitive
data structures are created using primitive data structures.
Non-primitive data structures can further be classified into two categories:
Linear data structures and Non-linear data structures.
If the elements of a data structure are stored in a linear or sequential order, then it is a linear
data structure. Examples are arrays, linked lists, stacks, and queues. Linear data structures can
be implemented in memory in two different ways. One way is to use an array based
implementation and the other is to use a linked list implementation.
If the elements of a data structure are not stored in a sequential order, then it is a non-linear
data structure. Examples are trees and graphs.


ABSTRACT DATA TYPES (ADTs)
An abstract data type (ADT) is a set of operations. Abstract data types are mathematical
abstractions. They do not mention how the set of operations is implemented.

, An ADT is as an extension of modular design.
Modularity has two advantages :

1. Debugging is easier
2. Many people can work on the modular program simultaneously.
Examples:
Data structures such as lists, stacks, queues, trees and graphs along with their operations, can
be viewed as abstract data types.



Fig: 1.2 An array of 6 elements represented in memory

Limitations of Arrays:
1. Arrays are of fixed size.
2. Contiguous memory locations may not be always available.
3. Insertion and deletion are quite difficult in an array as the elements are stored in
consecutive memory locations and the shifting operation is costly.
To overcome the limitations of arrays, we use linked lists.

LIST ADT
A list is of the form a1,a2,a3,a4,… ............ ,an. The size of the list is n. The first element of the list
is a1 and an is the last element. The position of element ai in a list is i. A list of size 0 is called as a
null list. Some of the operations that can be performed on a list are insert,
delete, find, print etc. Let us look at the operations with the help of an example. If the list
contains the following elements 34,82,14,62,18,12 then

• find(13) returns 3

• insert(72,4) makes the list into 34,82,14,62,72,18,12 (i.e) 72 is inserted after position
4.

• delete(18) makes the list into 34,82,14,62,72,12.

Array Implementation of Lists #
assigning elements to list list1 =[]
for i in range(0, 11):
list1.append(i)
# accessing elements from a list for
i in range(0, 11):
print(list1[i])
Deletion from a list
list1 = [1, 2, 3, 4, 5]

, print(list1)
# deleting element
del list1[2]
print(list1)

Note : Arrays are generally not used to implement lists as the insertions and deletions is time
consuming and expensive due to the shifting operation involved and the list size must also be known
in advance.



LINKED LIST
• The linked list consists of a series of nodes, which are not necessarily
adjacent in
memory.

• Each node contains two fields namely the data element and a pointer(called as the
next pointer) to the next node as shown in Fig 1.3.

• The next pointer of t he last node in the list points to NULL.

Data Next
element pointer




Fig Structure of a node in a linked list

Fig A Linked List
(Adapted from “Data Structures and Algorithm in Python” )




In Fig 1.4, the linked list consists of 5 elements a1,a2,a3,a4,a5 respectively. Let us
Fig : Linked List with actual pointer values
assume that these 5 nodes reside in memory locations 890,496,345,900,254
respectively. Then we can represent our linked list as shown in Fig 1.5.

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
6 april 2025
Aantal pagina's
25
Geschreven in
2024/2025
Type
College aantekeningen
Docent(en)
Kalapana
Bevat
Alle colleges

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
sanjayramaiyarm

Maak kennis met de verkoper

Seller avatar
sanjayramaiyarm everwin mat sec school
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
0
Documenten
2
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen