Vous êtes sur la page 1sur 10

NATIONAL INSTITUTE OF FASHION TECHNOLOGY

Algorithm Design and Data Structure

Assignment-2

Submitted by: Submitted to:

Anushree Chand Ms. Usha Yadav

Assistant Professor

NIFT Jodhpur
Object Oriented Programming in Python

 Class: Classes are a user-defined data type that is used to encapsulate data and associated functions
together. It also helps in binding data together into a single unit.
 Object: Objects are the basic runtime entities of object-oriented programming. It defines the
instance of a class.
 Methods: Methods are functions defined inside the body of a class. They are used to define the
behaviors of an object.

 Class variable: Class variables have the same value across all class instances (i.e. static variables).
 Instance variable: Instance variables have different values for each object instance.

 Method__init__constructor: This is a method in OOPS which is called when an object is created


from the class and it allows the class to initialize the attributes of a class.
 Data Encapsulation: Hiding the private details of a class from other objects.
 Data Abstraction: Data abstraction refers to providing only essential information about the data to
the outside world, hiding the background details or implementation.
 Inheritance: It allows us to define a class that inherits all the methods and properties from
another(parent) class.
Codings:

Input1:

Output1:

Input2:
Output2:

Input3:

Output3:

Input4:
Output4:

Input5:
Output5:
General Data Structures
The various data structures in computer science are divided broadly into two categories
shown below as shown below:

Integers: any whole number, ranging from negative infinity to infinity.

Float: any number ending with a decimal figure.

Strings: characters, letters or words which need to be single or double quoted to be made into a string
in python.

Boolean: an inbuilt data type which uses either of the two values: True or False. The values are
interchangeable with 0 or 1.

LINEAR DATA STRUCTURES

These are the data structures which store the data elements in a sequential manner.

 Array: It is a sequential arrangement of data elements paired with the index of the data
element.
 Linked List: Each data element contains a link to another element along with the data present
in it.
 Example: Human Brain
 Stack: It is a data structure which follows only to a specific order of operation that is
LIFO(last in First Out) or FILO(First in Last Out), which means the element inserted last in
sequence will come out first as we can remove only from the top of the stack.
 Example- History of a browser.
 Queue: It is similar to Stack but the order of operation is only FIFO (First in First Out). The
items are allowed at one end but removed form the other end. So it is a First-in-First out
method.
 Deque: A double-ended queue, or deque, supports adding and removing elements from either
end. The more commonly used stacks and queues are degenerate forms of deques, where the
inputs and outputs are restricted to a single end.
 Matrix: It is two dimensional data structure in which the data element is referred by a pair of
indices.
 Pseudo Code: it is simply an implementation of an algorithm that has no syntax and written
in plain English. It improves the readability and acts as a bridge between the program and the
algorithm.

Spanning Tree: A spanning tree of a graph can be defined as a graph with minimal set of
edges that connect all vertices.

Minimum Spanning Tree: A minimum spanning tree (MST) or minimum weight spanning
tree for a weighted, is a spanning tree with weight less than or equal to the weight of every
other spanning tree.

Prim’s Algorithm: is a minimum spanning tree algorithm that takes a graph as input and
finds the subset of the edges of that graph which form a tree that includes every vertex has the
minimum sum of weights among all the trees that can be formed from the graph.

Greedy Method: Greedy is an algorithmic paradigm that builds up a solution piece by piece,
always choosing the next piece that offers the most obvious and immediate benefit.

Flowcharts: They help project users to identify the different elements of a process and
understand the interrelationships among the various steps, by providing a graphical
representation.
Kruskal’s algorithm: is a minimum-spanning-tree algorithm which finds a subset of the
edges that forms a tree that includes every vertex, where the total weight of all the edges in
the tree is minimized.

Depth First Search: It marks the current vertex as being visited and explores each adjacent
vertex that is not included in the visited set.

Breadth First Search: The actions performed on each explored vertex are the same as the
depth-first implementation, however, replacing the stack with a queue will instead explore the
breadth of a vertex depth before moving on.

Algorithms in Python
Algorithms are a basic guideline for solving a problem in a programming language. Below
mentioned are some important categories of algorithms:

 Sort– This algorithm sorts data in a certain order. There are different types of
sorting:
a. Bubble Sorting: Bubble sort steps through the list and compares adjacent pairs of
elements. The elements are swapped if they are in the wrong order. Because Bubble
sort repeatedly passes through the unsorted part of the list, it has a worst case
complexity of O(n²).
b. Selection Sorting: Selection sort divide the input list / array into two parts, finds the
smallest element in the unsorted sublist and place it at the end of the sorted sublist.
c. Insertion Sorting: Insertion sort removes one element from the array and then finds
the location where that element belongs within another sorted array and inserts it
there. Insertion sort is both faster and well-arguably more simplistic than both bubble
sort and selection sort.
d. Merge: Merge sort is a perfect example of a Divide and Conquer algorithm. It
continuously divides the unsorted list until N sublists and then repeatedly merges the
sublists together at a time to produce new sorted sublists until all elements have been
fully merged into a single sorted array.
e. Quick: It selects an element (pivot), move all other elements that are smaller than the
pivot to the left of the pivot; move all elements that are larger than the pivot to the right
of the pivot.

 Search– Helps with searching an item in the data order. Different searches in
Python are:
a. The Linear Search: This technique iterates over the sequence, one item at a
time, until the specific item is found or all items have been examined.
b. The Binary Search:The linear search algorithm for a sorted sequence
produced a slight improvement over the linear search with an unsorted
sequence, but both have a linear time-complexity in the worst case.
 Insert– Helps with inserting an element in the data order.

 Update– Updates an element in the data order that was existing.

 Delete– It helps with removing an item from the data order.

Vous aimerez peut-être aussi