Sie sind auf Seite 1von 29

What is Data Structure?

An Intentional arrangement of Data within a running program.

RECORD: Collection of different type of data, also termed as Tuple in Mathematical terms.
FIELD: An Individual column/data type is termed as field.

-------------------------------------------------------------------------------------------------------------Data Structure: 1: Struct:

EXAMPLES OF STRUCTS:

Defining the coordinates

Defining the colors

COMPARISION FOR ALL LANGUAGES:

-------------------------------------------------------------------------------------------------------------Data Structure 2: ARRAY (Called as List in Python):


Ordered arrangement of Data of similar types and size.

Multidimensional Array (Or called as Array of Array):

ARRAY OF ARRAY: Same thing can be represented as follows:

EXAMPLES: Data for weather report (Row Day, Column Hours), Cricket Score (Row Teams, Column Overs).

Jagged Array:
Consider an example where your first dimension is Month and second dimension is days as shown below. For such cases
your Array is not a rectangle, you have different columns for different row number. Such array is called as Jagged Array.

This type of array is created by building a logic in your program as show below:

Resizable Array or Dynamic Array or Mutable Array or Changeable Array:


Its there in some languages like Java, Ruby. To resize an array in Java you create a List Array.

Sorting of Custom Data type:


Sorting of existing data types like Integer, Character data types is easy and can be done using the existing data types of a
language, however you need to write you own code if for Custom created data type (Struct as shown above).

-------------------------------------------------------------------------------------------------------------Searching the Array: (Linear Search):


In linear search mostly you go over all the elements until you find your desired result. Linear search is not for when you
have large amount of data, complexity will be more.

-------------------------------------------------------------------------------------------------------------Binary Searching or Half-Interval Search or Divide & Conquer Algorithm:


In this all data is sorted first then sorting is performed (Check the mobile application).

DS 3: List (array of Python, can create custom in Java and other lang.) VS Array:
Main difference between both of them is direct access (also called as Random access) and sequential access. In array
direct access of any element is very easy and fast because of its structure. Instead of Index of a particular elements, each
node in the list stores the link to another node and the value. See the list structure:

Arrays are good for directly access of an element while list are good for frequently adding/removing a node.

Singly, Doubly and Circular Doubly link list:


See the diagram and connectivity and you will understand.

Next link of last node of singly list is connected to a terminator.

Previous link of object 1 and next link of object 5 are pointed to a terminator in Doubly link.

-------------------------------------------------------------------------------------------------------------List in Java:
Part of Collection framework, List is not a class in Java it is an interface. Following Java classes can also be used, called
as ArrayList or LinkList. NOTE: Python lists are array; Python dont have any linked list support.

Data Structure 4: Stack for Last In-First Out:


Unlike array it doesnt have any index just have three operations LIFO.

Push: To add a value; Pop: To show and delete a value; Peek: To view the value

Data Structure 5: Queue: First in First Out:


Best way to understand this is considering examples of a print jobs, an actual queue in store etc. A queue can be an
array or LinkList.

Priority queues and dequeues:


Data with high priority will jump ahead.

Using a Deque (Double ended Queue):


It is combination of both Stack and a Queue, i.e., you can add/remove from both end and start not anywhere else.

-------------------------------------------------------------------------------------------------------------HASH BASED DATA STRUCTURE:


Data Structure 6: Associative Array: (Key/Value pair):
It this instead of numeric index we have other data type unique index. Which can be Integer or String or char.

-------------------------------------------------------------------------------------------------------------Understanding Hash: One-way function:

A default Hash value will return a integer always.

-------------------------------------------------------------------------------------------------------------Data Structure 7: SETS:

-------------------------------------------------------------------------------------------------------------Data Structure 8: Tree:


In Binary tree a Parent node cannot have a parent with more than two child nodes.

Binary Search Tree either have left child node or right child node or both or none. It is already sorted tree.

Left value is always less then right value. Suppose 3000 needs to be added to the tree, then first comparison will be with
50, its greater then it will right of 50. Now comparing with 100 its greater, it will move to the right again. Now comparing
with 1000 its greater again and so on.

Binary search tree should be balance (i.e., equal number of levels on the right and on the left of root node.

-------------------------------------------------------------------------------------------------------------Data Structure 10: Heap:


Heap is more of a sorting algorithm. It assigns the values from left to right, also by comparing a child value with its
parent value.

First 49 is kept on the top, now 99 will always be added to left. Next value is 50, is 50 greater than 49 yes, so it will be
placed to right. Next value is 150. Which will be added to left. Is 150 greater than 99 yes. Is not than 99 will be swapped
with 150. After that 150 will be compared to its parent again which is 49 and so on.

Heap can be used for priority queue.

Data Structure 11: Graph:


A graph is can have any number of nodes connected to each other in any order. It can be of following types. Its node is
termed as Vertices and each link is called as edge.

--------------------------------------------------------------------------------------------------------------

Recap: Strength and Weaknesses of each of the Data Structure:

Das könnte Ihnen auch gefallen