0% found this document useful (0 votes)
46 views

Data Structures and Algorithms

This document summarizes key concepts about algorithms and data structures. It defines an algorithm as a step-by-step procedure that can be implemented in multiple programming languages. Common algorithm categories include search, sort, insert, update, and delete operations. Key characteristics of algorithms are that they are unambiguous, have well-defined inputs and outputs, terminate after a finite number of steps, and can be applied independently of programming language. Common data structures like stacks, queues, and linked lists are also summarized in terms of their properties and operations.

Uploaded by

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

Data Structures and Algorithms

This document summarizes key concepts about algorithms and data structures. It defines an algorithm as a step-by-step procedure that can be implemented in multiple programming languages. Common algorithm categories include search, sort, insert, update, and delete operations. Key characteristics of algorithms are that they are unambiguous, have well-defined inputs and outputs, terminate after a finite number of steps, and can be applied independently of programming language. Common data structures like stacks, queues, and linked lists are also summarized in terms of their properties and operations.

Uploaded by

Laen Onredor
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ALGORITHM BASICS

 Algorithm  Types
o Step by step procedure to be 1. Best Case: minimum
executed time
o Can be implemented in more 2. Average Case: average
than one programming time
language 3. Worst Case: maximum
 Categories time
1. Search: searches data ALGORITHM APPROACH
2. Sort: sorts data
3. Insert: inserts data  Greedy Algorithm
4. Update: updates an existing o Optimum solution is chosen
data o Do not provide globally
5. Delete: removes data optimized solutions
 Characteristics  Divide and Conquer
o Unambiguous: clear and o Problems are divided into
must lead to one meaning subproblems and each
o Input: 0 or well-defined problem is solved
inputs independently
o Output: 1 or well-defined o Steps:
output and should match the 1. Divide/Break
desired output 2. Conquer/Solve
o Finiteness: must terminate 3. Merge/Combine
after a number of processes  Dynamic Algorithm
o Feasibility: can be done with o Uses sub-problems but does
the available resources not solve them
o Independent: can be applied independently.
to one or more programming o Results from sub-problems
language are remembered which may
be used for another sub-
problem.
o IsEmpty: check if queue is
empty
BASIC DATA STRUCTURES
o IsFull: check if queue is full
1. Stack o Peek: get the value without
 Last in, first out principle removing
 Stack Operations  How it works?
oPush: add on top i. Two pointers: front and
oPop: remove from top rear
oIsEmpty: check if stack is ii. Initialize with -1
empty before popping iii. Enqueueing: increase
oIsFull: check if stack full value of rear
before pushing iv. Dequeueing: increase the
oPeek: get the value without front index
removing v. If enqueueing: check if
 How it works? queue is full
i. “Top” pointer keeps track vi. If dequeueing: check if
ii. Set its value to -1 to check empty
if empty. (top == -1) vii. Enqueue first element: set
iii. Pushing: increasing the value to 0; dequeueing:
value of the top set value to -1
iv. Popping: reducing the 3. Circular Queue
value of the top  Avoids wastage of space
v. If pushing, check if stack is  How it works?
full i. First (front) and Last (rear)
vi. If popping, check if stack is pointers
empty ii. When initializing the stack,
2. Queue we set the value of front
 First in, first out principle and rear to -1.
 Queue Operations: iii. Enqueueing: increase the
o Enqueue: add in the last rear value
o Dequeue: remove from the iv. Dequeueing: increase the
front front value
v. If enqueueing: check if o Traverse to the last node
queue is full o Change next of last node
vi. If dequeueing: check if to recently created node
queue is empty ii. Add to middle
vii. First element: value= 0 o Allocate and store
viii. Dequeueing: set value= -1; o Traverse to node just
However (to check if full) before the required
o Case 1: front==0 && position
rear==size-1 o Change next pointers to
o Case 2: front = rear +1 include new node
4. Linked List iii. Delete from beginning
 connected nodes that o Point head to second node
contains addresses of the iv. Delete from end
next node o Traverse to second last
 Head: start element
 Null: after the last node o Change its next pointer to
 Nodes contain data item and null
address of the next node v. Delete from middle
 Types: o Traverse to element
i. Singly Linked List: next before the element to be
ii. Doubly Linked List: has deleted
previous and next links o Change pointers
iii. Circular Linked List: last
node to first; can be singly
or doubly linked list
 Head: first node
 Next: pointer of last node is
null
 Operations:
i. Add to beginning
o Allocate
o Store

You might also like