Lecture Notes on Algorithms Basics | CSC 3102, Study notes of Computer Science

Material Type: Notes; Professor: Karki; Class: ADV DATA STRUCTURES; Subject: Computer Science; University: Louisiana State University; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 08/30/2009

koofers-user-6gf-1
koofers-user-6gf-1 🇺🇸

10 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
B.B. Karki, LSU
2
CSC 3102
Algorithm Basics
(Chapters: 1 and 2)
Notion of algorithm
Fundamentals of algorithmic problem solving
Important problem types
Analysis of algorithmic efficiency
Non-recursive algorithms
Recursive algorithms
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Lecture Notes on Algorithms Basics | CSC 3102 and more Study notes Computer Science in PDF only on Docsity!

Algorithm Basics

(Chapters: 1 and 2)

 Notion of algorithm  Fundamentals of algorithmic problem solving  Important problem types  Analysis of algorithmic efficiency  Non-recursive algorithms  Recursive algorithms

Fundamental Data Structures

(Chapter 1 - Section 4, and other parts of the textbook)

(Reference books in C and Java)

 Linear lists

 Trees

 Graphs

 Sets

Types

 Linear Lists

 Linked list, Stack, Queue

 Trees

 Balanced Trees (AVL and 2-3 Trees), B Trees

 Graphs

 Types, Graph traversals (DFS and BFS)

 Graph problems (e.g., Topological sorting)

 Sets

 Subsets, Union-find operations

Linear Lists

Linked Lists  A linked list is an ordered collection of data in which each element contains the location of the next element.  Each element (item) called node contains two parts: data and link  Link contains a pointer variable that identifies the first element in the list.  Nodes are called self-referential structures. Each instance of the structure contains a pointer to another instance of the same structural type.  Unlike arrays, data can be easily inserted and deleted in the linked list. But the search becomes sequential because the elements are no longer physically sequenced.  Linked list ADT consists of the data structure and all operations that manipulate the data.

X

plist data link data link data link data link data null

Linked Lists: Data Structure  A head node contains metadata about the list such as count, a head pointer to the first node, and a rear pointer to the last node.  Data node contains the data type which depends entirely on the application and a pointer to another data structure of its own type. count pos head data link list count pos head end list node data link end node list head structure list data structure

Linked List Using JAVA

 Declaring a class for nodes

public class IntNode { private int data private IntNode link }

 Declaring two nodes

IntNode head IntNode tail

 Constructor for the IntNode

public IntNode(int initialData, IntNode initialLink) { data = initialData link = initialLink }

 Methods for

manipulating nodes

 Get and set the data and link  Add a new node  Remove a node  List length  Traverse a linked list  Search a node  Copy a linked list …………..

Complex Linked List Structures

 Circularly-linked list

 The last node’s link always point to the first node of the last.

 Doubly-linked list

 Each node has a pointer to both its successor and its predecessor.

 Multilinked list

 List has two or more logical key sequences  Data can be ordered choronologically and also by the president’s name or by his first wife’s name.

Stacks: Data Structure  Head node contains metadata about the stack such as count, and a pointer to the top of the stack  Data node looks like a typical linked list data node. count top data next stack count top end stack node data next end node stack head structure stack data structure

Stack Algorithms

 Create stack

 Push stack

 Pop stack

 Stack top

 Empty stack

 Full stack

 Stack count

 Destroy stack

Queues  A queue is a linear list in which data can be inserted at one end, called the rear, and deleted from the other end, called the front. It is a First In, First Out (FIFO) data structure.  Basic queue operations:  Enqueue: inserts an element at the rear of the queue  Dequeue: deletes an element at the front of the queue  Queue front: examines the element at the front of the queue  Queue rear: examines the element at the rear of the queue.  Queue-linked list implementation  Usually implemented as a linked list in dynamic memory. head X Conceptual view Physical view data nodes front rear front rear

Queues: Data Structure  Head node contains metadata about the stack such as count, and two pointers to the front and rear of the queue  Data node looks like a typical linked list data node. front count rear data next queue front count rear end queue node data next end node queue head structure queue data structure

Queue Applications

 Queuing theory

 Deals with the performance of queues  Two factors that most affect the performance of queues are the arrival rate and the service time

 Queue simulations

 Categorizing data

 Other applications

 Processing customer requests, jobs and orders  CPU scheduling: processing jobs waiting for execution.

Stack and Queue ADT

 Both stack and queue ADT consist of the specific datatype and all the

operations that manipulate the data.

 Data structure: Both head node and data nodes are encapsulated

in the ADT

 Algorithms: All the functions are implemented within the ADT.

 Two types of ADT implementation

 Linked list implementation

 Array implementation