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

Data Structure using Artificial intelligence

Rating
-
Sold
-
Pages
23
Uploaded on
06-04-2025
Written 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?

Show more Read less
Institution
Course

Content preview

NEHRU 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 – I

PYTHON PREVIEW
Building data structures and algorithms requires that we communicate detailed instructions to
a computer. An excellent way to perform such communications is using a high-level
computer language, such as Python.

The Python Interpreter

▪ Python is formally an interpreted language. Commands are executed through a piece of
software known as the Python interpreter. The interpreter receives a command, evaluates
that command, and reports the result of the command. While the interpreter can be used
interactively (especially when debugging), a programmer typically defines a series of
commands in advance and saves those commands in a plain text file known as source code
or a script. (e.g., demo.py).


EXAMPLE:
a=10
b=20
sum= a+b
Print(sum)

OUTPUT:

sum=30

EXAMPLE:

A Python program that computes a grade-point average (GPA).

print( Welcome to the GPA calculator. )

print(“Please enter all your letter grades, one per line.”)

print(“Enter a blank line to designate the end. “)

# map from letter grade to point value

,points = { A+ :4.0, A :4.0, A- :3.67, B+ :3.33, B :3.0, B- :2.67,

C+ :2.33, C :2.0, C :1.67, D+ :1.33, D :1.0, F :0.0}

num courses = 0

total points = 0

done = False

while not done:

grade = input( ) # read line from user

if grade ==“ “: # empty line was entered

done = True

elif grade not in points: # unrecognized grade entered
print("Unknown grade ’{0}’ being ignored”. Format (grade))

else:

num courses += 1

total points += points[grade]

if num courses > 0: # avoid division by zero

print(“Your GPA is {0:.3}” .format(total points / num courses))



ADTs and Classes
Abstract Data Type (ADT)
• An abstract data type (ADT) is a programmer defined data type that specifies a set of
data values and a collection of well-defined operations that can be performed on those
values. Abstract Data Type (ADT) are defined independent of their implementation,
allowing us to focus on the use of the new data type instead of how it is
implemented.
▪ By hiding the implementation details, we can work with an abstraction and focus on what
functionality the Abstract Data Type (ADT) provides instead of how that functionality is
implemented.
▪ The set of operations can be grouped into four categories:
1. Constructors: create and initialize new instances of the ADT.
2. Assessors: return data contained in an instance without modifying it.
3. Mutators: modify the contents of an Abstract Data Type (ADT) instance.

, 4. Iterators: process individual data components sequentially
Stack ADT
A stack is a LIFO (last in, first out) list with the following operations: Push,
Pop, Create (Init), Top, IsEmpty, Size. (Such a list is called a Signature or the Interface to the
ADT.)

1. Stack() creates a new stack that is empty. It needs no parameters and returns an empty stack.

2. push(item) adds a new item to the top of the stack. It needs the item and returns
nothing.

3. pop() removes the top item from the stack. It needs no parameters and returns the item.
The stack is modified.

4. top() returns the top item from the stack but does not remove it. It needs no
parameters. The stack is not modified.

5. isEmpty() tests to see whether the stack is empty. It needs no parameters and
returns a boolean value.

6. size() returns the number of items on the stack. It needs no parameters and returns an
integer.

EXAMPLE:

class Stack: def
init (self):
self.items = []
def IsEmpty(self):
return self.items == []def
push(self,item):
self.items.append(item)
def pop(self):
return self.items.pop()

QUEUE ADT:

A Queue is a FIFO (first in, first out) list with the following operations:Enqueue, Dequeue, Size,
Font.

1. Queue() creates a new queue that is empty. It needs no parameters and returns an empty
queue.

2. Enqueue(item) adds a new item to the rear of the queue. It needs the item and returns
nothing.

3. Dequeue() removes the item from the front of the queue. It needs no
parameters and returns the item. The queue is modified.

Written for

Institution
Course

Document information

Uploaded on
April 6, 2025
Number of pages
23
Written in
2024/2025
Type
Class notes
Professor(s)
Kalpana
Contains
All classes

Subjects

$8.89
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
sanjayramaiyarm

Get to know the seller

Seller avatar
sanjayramaiyarm everwin mat sec school
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
2
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