Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

DataStructure and Algorithms

Data structures and algorithms are fundamental concepts in computer science. Data structures provide ways to organize and store data, like arrays, linked lists, stacks, queues, trees, and graphs. Algorithms are step-by-step procedures for solving problems, like searching, sorting, and finding shortest paths. Common algorithms include Dijkstra's algorithm for finding shortest paths in graphs and Floyd's algorithm for finding all-pairs shortest paths.

Uploaded by

Kaung Khant Lin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

DataStructure and Algorithms

Data structures and algorithms are fundamental concepts in computer science. Data structures provide ways to organize and store data, like arrays, linked lists, stacks, queues, trees, and graphs. Algorithms are step-by-step procedures for solving problems, like searching, sorting, and finding shortest paths. Common algorithms include Dijkstra's algorithm for finding shortest paths in graphs and Floyd's algorithm for finding all-pairs shortest paths.

Uploaded by

Kaung Khant Lin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Datastructure and Algorithms

Data : raw collection of facts.


Data Structure : a particular way of organizing, processing, retrieving and storing data for particular
types of operation. organizing and storing data in memory that considers not only the
elements stored but also their relationship to each other.A data structure is a way of
arranging data in a computer's memory or other disk storage.
Algorithm : is a step-by-step procedure for solving a problem or accomplishing some result. An
algorithm is a finite list of instructions, most often used in solving problems or
performing tasks.
Stack : is a linear data structure which follows a particular order in which the operations are
performed. Stack is also called last in first out (LIFO) or First in last out (FILO)system.
Push(element, stack) : which takes an element and pushes it on top of an existing stack.
Top(stack) : which gives back the top most element of a stack.
Pop(stack) : which gives back the stack without the top most element.
Queue : is a data structure used to model a First-In-First-Out (FIFO) strategy. Conceptually, we add
to the end of a queue and take away elements from its front.
Queue Simulation : Technique in which one system models the behavior of another system
Queue Operations and Specifications : Enqueue() - adds an element to the rear of a queue
Dequeue() − remove (access) an item from the queue.
Array : is a data structure to store an ordered collection of items. Array is stored in main memory.

Basic Array Operations : Traversal - Processing each element in the list.


Insertion - Adding a new element to the list.
Deletion - Removing an element from the list.
Searching - Finding the location of the element with a given
value or record with a given key.
Sorting - Arranging the elements in some type of order.
e.g., ascending or descending.
Linked list : is a linear collection of data elements as an array. But dynamic data storage which
allocates when it is needed.
Node : In a linked list, one element of data storage location is called a node. Each node is divided
into two parts: the first part contains the information of the element and the second part
contains the pointer that stores the address of the next node in the list.
Single Linked List : Each node that makes up a singly linked list consists of a value and a reference to
the next node (if any) in the list.
Linked List Operations: Insertion (Insertion is constant operation O(1))

Deletion (Deletion is linear operation O(n))

Searching (Searching is linear operation O(n))

Traversal (Searching is linear operation O(n))

Doubly linked lists: are very similar to singly-linked lists. The only difference is that each node has a
reference to both the next and previous nodes in the list.

Tree : A tree as consisting of nodes (also called vertices or points) and edges (also called lines, or,
in order to stress the directedness, arcs) with a tree-like structure.

Types Of Tree

 Quad Tree
 Binary Tree
 Binary Search Tree
 AVL Tree
 Heap Tree

Tree’s terminology: Root- a unique ‘top level’ node


Child node - is connected to the given node via a branch

Parent node – is connected to the given node (via an edge) on the level above

Sibling : Nodes that have the same parent are known as siblings

The depth or level of a node : is given by the length of this path.

The maximal length of a path in a tree : is also called the height of the tree.

The size of a tree : is given by the number of nodes it contains.

Heap Tree : is a complete binary tree.

Complete binary tree : binary tree that is completely filled, with the possible exception of

the bottom level, which is filled left to right.

Heap Tree Characteristics : It is complete.

It is implemented as an array.

Each node in a heap satisfies the heap conditions.

(i.e. In a max heap, every node’s key is larger than (or equal to) the keys of its children.)

Heap Strategies : There are two strategies in heap: (1) Min heap ,(2) Max heap.
Max heap: Each parent node in max heap have a value that is greater than or equal its children.

For example, the node at the root of the tree will have the largest value in the tree.

Min Heap : Each parent node in min heap have a value that is less than or equal its children.

For example, the node at the root of the tree will have the smallest value in the tree.

The binary heap :is a data structure that can be used to quickly find the maximum (or minimum) value
in a set of values.

Binary Search Tree : The defining characteristic of a binary search tree is this: A node’s left child must
have a key less than its parent, and a node’s right child must have a key greater
than or equal to its parents.

AVL Tree : A binary search tree with a self-balancing condition stating. The difference between the
height of the left and right subtrees cannot be no more than one .In an AVL tree, a well-
known technique is called tree rotation.

Graph : A graph is a non-linear datastructure consisting of nodes and edges . A graph consists of a
series of nodes (also called vertices or points) and edges(also called lines,links). It consists
of a finite set of vertices (or nodes) and set of edges which connect a pair of nodes.

Types of graph representation?

1. Adjacency Martix

2. Adjacency List

Directed Graph : In directed graphs (also called digraphs), each edge comes with one or two
directions, which are usually indicated by arrows. Same as undirected graph but
orientation of edges is significant.

Simple graph: A graph is said to be simple if it has no self-loops (i.e., edges connected at both ends to
the same vertex)

Connected graph: a graph is at least one path from every vertex to every other vertex.

Adjacency : two vertices are adjacent if they are connected by a single edge.

Path: a sequence of vertices that are connected by edges. (e.g. ABC)

A circle : is a non-empty path whose first vertex is the same as its last vertex.

A path is simple if no vertex appears on it twice.

A digraph is weakly connected if for every two vertices A and B there is either a path from A to B or a
path from B to A.

A digraph is strongly connected if there are paths leading both ways.


Weighted Graph : Graphs really become useful when we can give weights or costs to the edges.

One of the canonical applications for weighted graphs :is finding the shortest path between two
nodes. These algorithms are used in Google Maps for example.

Tranversals : Fundamental operation, to find out which vertices can be reached from a specified
vertex.An algorithm that provides a systematic way to start at a specified vertex and then
move along edges to other vertex.Every vertex that is connected to this vertex has to be
visited at the end.

Two common approaches : depth-first search (DFS) and

breadth-first search (BFS).

Depth-first Search : Can be implemented with a stack to remember where it should go when it reaches
a dead end.DFS goes far way from the starting point as quickly as possible and
returns only if it reaches a dead end.

Used in simulations of games.

What is the purpose of graph?

Graphs are a common method to visually illustrate relationships in the data.

The purpose of a graph is to present data that are too numerous or complicated to be described
adequately in the text and in less space (Do not use graphs for small amounts of data that could be
conveyed succinctly in a sentence).

Where are Graph theories used : Computer Science,Social Science,Economy,Electrical


Engineering,Physics and Chemistry,biology (for analyzing DNA),Mathematics,Other areas (…).

Algorithms : is a step-by-step procedure to be followed to reach the desired output.

is designed to achieve optimum solution for a given problem.

Type of Algorithms

 Simple recursive algorithms


 Backtracking algorithms
 Divide and conquer algorithms
 Dynamic programming algorithms
 Greedy algorithms
 Randomized algorithms

Dijkstra’s algorithm : is an algorithm for finding the shortest paths between nodes in a graph. It finds
the shortest path between that node and every other.

It is also called SPF (Shortest Path First), which is used in the routing protocol
OSPF, Open Shortest Path First.
Floyd’s algorithm : is an algorithm for finding the shortest path between all the pairs of vertices in a
weighted graph. It works for both the directed and undirected weighted graphs.

*(does not work for the graphs with negative cycles (where the sum of the edges in a cycle is negative))

Difference Between Dijkstra and Floyd’s algorithms

Floyd's algorithm finds the shortest path between all vertices.

(eg: Fire detection)

Dijkstra's algorithm finds the shortest path between a single vertex and all other vertices.

(eg: based on routing applications)

Algorithm Design : It is a specific method to create a mathematical process in solving problems.Before


designing an algorithm it is important to first understand what the problem is.

Importance of Algorithm Design

 It allows for analysis on different ways to compute things.


 It is used to store and access large quantities of data efficiently.
 It is used to solve complex computational problems and to design of good programs.
 It is important to justify an algorithm correctness mathematically.
 It provides clear, simple and unambiguous description.

Iterative Algorithms : An iterative algorithm executes steps in iterations.

It aims to find successive approximation in sequence to reach a solution.

They are most commonly used in linear programs where large numbers of
variables are involved.

Recursive Algorithms : Instead of executing a specific process within the function, the function calls
itself repeatedly until a certain condition is met.

There are two main parts of a recursive function; the base case and the recursive call.

The base case is important because without it, the function would theoretically
repeat forever.

Searching : is the process of finding a given value position in a list of values.

It decides whether a search key is present in the data or not.


A searching algorithm can be used to help find the item of data you are looking for.

Two most common searching algorithms

 Linear Search
 Binary Search

Linear search : (sequential search) is a method for finding an element within a list. It sequentially checks
each element of the list until a match is found or the whole list has been searched.

Binary Search: search a sorted array by repeatedly dividing the search interval in half.

It begins with an interval covering the whole array.

If the value of the search key is less than the item in the middle of the interval, narrow the
interval to the lower half.

How to use graphs theory in computer science?

 Flow of computation
 Networks of communication
 Data organization
 Shortest path in road or a network

What is the difference between Graph and Tree?

Different between Iterative & Recursive Algorithms


Different between Linear Search and Binary Search
Sorting : refers to arranging data in a particular format.
Most common orders are in numerical or lexicographical order.
Sorting can be done on names, numbers and records.
8 type of sorting
 Bubble Sort
 Selection Sort
 Insertion Sort
 Merge Sort
 Quick Sort
 Heap Sort
 Shell Sort
 Radix Sort
No of comparisons and Time Complexity

Type of Sorting No of comparisons Time Complexity

Bubble Sort n(n-1)/2 O(n2)

Selection Sort n(n-1)/2 O(n2)

Insertion Sort - O(n2)


Radix Sort - -

Shell Sort - O(nlog n)

Merge Sort - O(nlog n)

Heap Sort - O(nlog n)

Quick Sort - O(nlog n)

You might also like