Singly and Doubly Linked Lists: Data Structures and Operations, Lecture notes of Data Structures and Algorithms

lecture notes of data structure and algorithms

Typology: Lecture notes

2019/2020

Uploaded on 11/16/2021

paranita44
paranita44 🇳🇵

1 document

1 / 180

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
DATA STRUCTURE AND
ALGORITHM
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Singly and Doubly Linked Lists: Data Structures and Operations and more Lecture notes Data Structures and Algorithms in PDF only on Docsity!

DATA STRUCTURE AND

ALGORITHM

DATA STRUCTURE

  • Organization of data in a well defined and structured manner so that the data can be processed efficiently and effectively.
  • Container structure for data.
  • is a specialized format for organizing, processing, retrieving and storing data.

TYPES OF DATA STRUCTURES

- Arrays - An array stores a collection of items at adjoining memory locations. Items that are the same type get stored together so that the position of each element can be calculated or retrieved easily. Arrays can be fixed or flexible in length. - Stacks - A stack stores a collection of items in the linear order that operations are applied. This order could be last in first out (LIFO) or first in first out (FIFO). - Queues - A queue stores a collection of items similar to a stack; however, the operation order can only be first in first out. - Linked lists - A linked list stores a collection of items in a linear order. Each element, or node, in a linked list contains a data item as well as a reference, or link, to the next item in the list.

ALGORITHM

  • An algorithm is a step by step method of solving a problem. It is commonly used for data processing, calculation and other related computer and mathematical operations.
  • used to manipulate data in various ways, such as inserting a new data item, searching for a particular item or sorting an item.

ALGORITHM EFFECTIVENESS

  • Measured in notations. Eg: Big O
  • Gives complexity of two dimensions; space and time
  • Space complexity: refers to how much of the space the program needs based on the size of input.
  • Time complexity: how much time it requires for the completion of execution if the input is changed?
  • Space complexity is not cared as space can be reused.
  • Time Complexity is important as time cannot be reused.

ABSTRACT DATA TYPES (ADT)

  • Consider the statement: “I put my lunch in my bag.”
  • What is meant by the term bag in this context?
  • Most likely it is a backpack, or satchel, but it could also be a hand bag, shopping bag, sleeping bag, body bag... (but probably not a bean bag).
  • It doesn’t actually matter. To parse the statement above, we simply understand that a bag is something that we can - 1. put things in, - 2. carry places, and - 3. take things out.
  • Such a specification is an Abstract Data Type.

ABSTRACT DATA TYPES (ADT)

  • Mathematical description of an object and the set of operations on the object
  • is the interface of a data structure without any specification of the implementation.
  • Eg: Class in object oriented programming.
    • List: can be any and operations are specific to specific lists.
      • But basic operations are: insert, retrieve, update, delete

Time Complexity Analysis

  • Nested Loops
    • We analyze the nested loop from inside out. Total time is always the product of all loop times.
    • Total time = c × n × n = cn 2 = O(n 2 ).

Time Complexity Analysis

  • Consecutive Statement
    • We add time complexities of each statement.
    • Total time = c 0 + c 1 n + c 2 n 2 = O(n^2 ).

Time Complexity Analysis

  • Logarithmic complexity:
    • n algorithm is O(logn) if it takes a constant time to cut the problem size by a fraction (usually by ½). As an example let us consider the following program:
    • If we observe carefully, the value of i is doubling every time. Initially i = 1, in next step i= 2, and in subsequent steps i = 4,8 and so on. Let us assume that the loop is executing some k times. At kth step 2k = n, and at (k + 1)th step we come out of the loop. Taking logarithm on both sides, gives
    • Total time = O(log n).

Time Complexity Analysis

  • Recursive function:
    • Since recursive function is called n times, the complexity is simply O(n)
    • Total time = O(n).
    • Sometimes if the code is cutting the number of recursive calls by half then the time complexity is Olog(n).
    • So gewnerally depends upon how the recursive function is called.

Classwork

  • Find the worst case time complexity of the following code in big O notation.

Classwork

  • Answer