CSE 211: Data Structures Lecture Notes VII

Size: px
Start display at page:

Download "CSE 211: Data Structures Lecture Notes VII"

Transcription

1 CSE 211: Data Structures Lecture Notes VII LINKED LISTS In the previous lectures we have seen the representation of ordered lists using an array and sequential mapping. These representations had the property that successive nodes of the data object were stored in a fixed distance apart. For example: If the element a ij of a table was stored at location L ij then a ij+1 was at the location L ij +c for a known constant c. Problems: The sequential storage schemes are adequate if one wished to access for given node in a table, insertion or deletions of nodes within a stack or queue. However insertions or deletions of arbitrary elements become expensive. If we have several ordered lists of varying sizes, by storing each list in a different array of maximum size, storage may be wasted. Additionally, in several cases we will need more than accessing the top item as in the stacks or inserting to the tail and accessing the head (queues). We need more general operations such as finding or removing any item in the list, inserting a new item at any point. Solution: The problem of data movement in sequential representations may be solved by using linked representations and dynamic memory allocation. Unlike a sequential representation where successive items of a list are located a fixed distance apart, in a linked representation each item of the list may be placed anywhere in memory. To access elements in the list in the correct order, with each element we store the location of the next element in that list. Associated with each data item in a linked representation there is a pointer to the next item. In modern languages providing built-in support for linked structures, the compiler associates a special storage with an object program which it leaves initially unassigned to any program variable. This area is usually called the heap or the dynamic storage pool. There is a heap manager program for the allocation of this storage from the heap at execution time. The allocated space can be referenced using pointers. Remember that pointer is just an abstraction for a machine address. Linked List Building Blocks: A linked list is an ordered sequence of elements called nodes. A list has a beginning, or head and an end, or tail. Every node on the list is the same type, although that type can take different forms. A central property of linked lists is their dynamic nature. Nodes can be added to or removed from a list at any time. Because the number of nodes cannot be predicted before run time. You should use pointers, rather than arrays, to achieve an efficient and reliable implementation. Nodes

2 Each node of a list consists of two parts. The first part holds the data. The first part holds the data. The data can be a simple variable or, more generally a structure ( or pointer to a structure) of some type. The second part is a pointer that indicatesthe location of the next node of the list. The nodes of a list can be implemented by a recursive structure. Consider the case where a single integer varaible is to be stored at each node of the list. struct simplenode int item; struct simplenode *next;}; typedef struct simplenode simple_t; class simplenode int item; simplenode *next;... }; In this case the integer variable item holds the actual data in each node, and the pointer variable next holds the address of the next node. item next In general, the item part may contain several pieces of data defined in a strcut type. We can generalize the list definition above as: struct generallist infotype item; struct generallist *next; }; typedef struct generallist glist_t; template <class infotype> class generallist infotype item; generallist *next;... }; We assume that info_type has been defined before. The problem with this kind of implementation is that for each type of list you must assign the individual components one by one when transfering information to and from the nodes. Ex. if s1 and s2 are both structures. In C, you cannot say s1=s2. You can assign only a single structure component in each statement. You can however write a function called assign and call it whenever needed. assign(s1,s2); info_type s1,s2; /* assign each component of struct 2 to struct 1 } This function carries out the detailed transfer of the individual structure components from 21 to s1. You can then build a series of generic list manipulation functions that use assign.

3 The problem with this approach is the performance. You will be transfering data among different memory locations. However you only need to transfer the address of the blocks of data corresponding to the structures. Solution: use a structure composed of a pair of pointers. The first pointer points to the data, the second points to the next item. struct node infotype * item; struct node *next; }; typedef struct node node_type; template <class infotype> class Node infotype * item; Node *next;... }; item next Manipulation of Linked Lists The manipulation of linked lists involves allocating storage for nodes (in C using malloc) and assigning data and/or pointers so that the list is properly formed. List's boundary conditions must be decided. In other words how are the head and tail of a list will be indicated. For the representation of the tail NULL pointer can be used (show it on the example) but for the head different approaches are possible. Define a pointer variable to hold the starting adress of the list. Define a special header node with the same structure. In this case the next element of the header node indicates the beginning of the list. (item part is unused - a small waste) Define a header node with a separate structure which holds exactly the information required. In this case other information related to the list such as number of elements in the list can be added to the header.

4 struct head int length; node_type *first, *last; } typedef struct head head_type; template <class infotype> class LinkedList int length; Node<infoType> *first,*last; int insert(infotype *data) int append(infotype *data) int delete(node *ptr) } If a symmetric header is used: If a custom head is used: (length, last, first) Operations on One-way Lists and their Implementations Allocating Memory When an array is defined, storage is automatically allocated by the compiler. When you are using pointers, however you must allocate the storage. In C, two standard library functions are provided for this purpose. malloc--- allocates a single piece of storage space and leaves it uninitialized calloc() -- allocates entire set of storage locations and fills the total storage with zero char *malloc(size) allocates size number of bytes and returns a pointer to the first Although it returns a character pointer it can be used to allocate space for any type of element not just characaters by applying a simple type casting Size is the value returned by the sizeof operator sizeof expression sizeof(type name)

5 Type casting: new_variable = (type_name) old_variable We will define a fucntion called MALLOC and use it in the algorithms #define MALLOC(x) ((x *) malloc(sizeof(x))) float *place; /* A float pointer place = (float *) malloc (sizeof(float)); place = MALLOC(float); place = new float[1]; Creating a new list 1. allocate memory for header node 2. set length to 0 3. set first and last nodes to NULL head_type *create() head_type *new_node; if (new _node = MALLOC(head_type) ) new_node ->length = 0; new_node -> first = new_node -> last = NULL; } return(new _node); /* adress of new list } Inserting a new element at the beginning of a list A) Create a storage for the new node 1. Create storage for a new list node; 2. Assign appropriate pointer values to the new node 3. Assign new values to the components of the header node. Example given at the lecture. /* create a storage for the new node node_type *alloc_node(info_type * val, node_type * ptr) node_type *new_node; if (new_node = MALLOC(node_type)) new_node -> item = val; new_node -> next = ptr;} return(new_node); }

6 B) Inserting a new element at the beginning of a list 1. Allocate memory for the new node and set it (if possible) 2. Link the first pointer of header to the new node (?last) 3. Increment length by 1 int insert_node (info_type *data, head_type *list) node_type *new_node; if (new _node = alloc_node(data, list->first)) list->first = new_node; /* link in new node if (list->length == 0) /* if this is the first node list-> last = new_node; /* set last pointer to new list->length ++; return(1); /* success } else return(0); /* error } Appending a new item to the end of a list Another common operation appends a new item to the end of a list. The before and after situations are diagrammed below. You know where to find the current last node in the list by means of the last pointer, which is maintained in the header block. Thus you only need to allocate memory for a new node and rearrange pointers accordingly. int append (info_type *data, head_type *list) node_type *new_node;/* append data to end of list if (new_node=alloc_node(data, NULL) /* allocation OK, append data item if (list -> length) /* if the list is not empty list->last->next = new_node; /* link in new node else /* otherwise list->first = new_node; /* set first pointer to new list -> last = new_node; /* update last pointer list -> length++; /* update list length return(1); /* success } else /* allocation problem return(0); /* error } BEFORE: AFTER:

7 Deleting Nodes Study yourself. Doubly Linked Lists Finding the predecessor of a node in a one-way list requires a linear search. We can add a pointer to its predecessor, to each node. It will consume more space but search will be faster. Sometimes you may need to move through a list from the end to the beginning by following pointers. Inorder to be able to do this we can define two pointers in each node; One points to the next and one points to the previous node. Length Last First Previous Item Next (HEADER ) (NODE) (a doubly linked list) For doubly linked lists, you need to develop a new set of routines that are analogous to those for ordinary (singly linked) lists. The function to create a new doubly linked list is nearly the same as that for singly linked lists, in that you have to change only the data types of the header pointers. Let us first define the doubly linked list node: struct doubly info_type *item struct doubly *next, *prev; } typedef struct doubly doubly_type; template <infotype> class doubly infotype *item doubly *next, *prev;... } Header Node: It does not need to change. We only need to change the type of pointers from node_type to doubly_type.

8 Operations on Doubly Linked Lists (Two-Way Lists) Create operation head_db_type *create_db() head_db_type *new_node; /* attempt to allocate memory if (new_node =MALLOC(head_db_type)) /* allocation OK, initialize the values new_node -> length = 0; new_node -> first = NULL; new_node ->last = NULL; } /* return the address of the new lıst return(new_node); } DoublyLinkedList() first = NULL; last = NULL; length = 0; } We also need to write a function which creates a new node. /* create a storage for the new doubly linked node doubly_type *alloc_db_node(val, prev, next) info_type *val; doubly_type *prev, *next; doubly_type *new_node; if(new_node=malloc(doubly_type)) new_node -> item = val; new_node -> prev = prev; new_node -> next = next; } return(new_node); } doubly( info_type *val, doubly *prv, doubly *nxt) item = val; prev = prv; next = nxt; } Using this function we can write insert and append functions: /* Insert node at the beginning of a doubly linked list

9 int insert_dbl ( info_type *data, head_db_type *list ) doubly_type *new_node; if (new_node = alloc_db_node(data, NULL, list->first)) if (list->length == 0) /* if this is the first node list->last = new_node; /* set the last pointer to the new else /* if not the first node link it in list->first->prev = new_node; /* set prev field of first node list->first = new_node; /*set the first pointer to the new } list->length++; return(1); /* success }else return(0); } /* error Previous field of the first node is 0 Next field of the last node is 0 (before insertion) (after insertion) Append a node to the end of the list Home study-- do it yourself

10 Deleting first node from a doubly linked list We assume that before calling the delete function you have checked the length of the list. The function retıurns the data field of the deleted node and frees the memory used by this Node. info_type *del_dbl(head_db_type *list) doubly_type *temp; info_type *data; /* delete first node temp= list->first; /* save the pointer data = temp->item; /* save the data list->first = temp->next; /* reassign the first pointer list->length--; /* update list length if (list->length ) /* if new list is not empty list->first->prev = NULL; /* set prev field of first item to NULL else /* otherwise list->last = NULL; /* set last pointer to NULL ; free((char )temp); /* free node storage return(data); } (before deletion ) (after deletion) LINKED LIST ADT IMPLEMENTATION IN C / List ADT Type Defintions typedef struct node void* dataptr; struct node* link; } NODE;

11 typedef struct int count; NODE* pos; NODE* head; NODE* rear; int (*compare) (void* argu1, void* argu2); } LIST; // Prototype Declarations LIST* createlist (int (*compare) (void* argu1, void* argu2)); LIST* destroylist (LIST* list); int addnode (LIST* plist, void* datainptr); bool removenode bool searchlist (LIST* plist, void* keyptr, void** dataoutptr); (LIST* plist, void* pargu, void** pdataout); bool retrievenode (LIST* plist, void* pargu, void** dataoutptr); bool traverse (LIST* plist, int fromwhere, void** dataoutptr); int listcount (LIST* plist); bool emptylist (LIST* plist); bool fulllist (LIST* plist); static int _insert (LIST* plist, NODE* ppre, void* datainptr); static void _delete (LIST* plist, NODE* ppre, NODE* ploc, void** dataoutptr); static bool _search (LIST* plist, NODE** ppre, NODE** ploc, void* pargu); // End of List ADT Definitions /* =============== createlist ============== Allocates dynamic memory for a list head node and returns its address to caller Pre compare is address of compare function used to compare two nodes. Post head has allocated or error returned

12 Return head node pointer or null if overflow LIST* createlist (int (*compare) (void* argu1, void* argu2)) // Local Definitions LIST* list; list = (LIST*) malloc (sizeof (LIST)); if (list) list->head = NULL; list->pos = NULL; list->rear = NULL; list->count = 0; list->compare = compare; } // if return list; } // createlist /* ================== addnode ================= Inserts data into list. Pre plist is pointer to valid list datainptr pointer to insertion data Post data inserted or error Return -1 if overflow 0 if successful 1 if dupe key int addnode (LIST* plist, void* datainptr) // Local Definitions bool found; bool success; NODE* ppre; NODE* ploc; found = _search (plist, &ppre, &ploc, datainptr); if (found) // Duplicate keys not allowed return (+1); success = _insert (plist, ppre, datainptr); if (!success) // Overflow return (-1); return (0); } // addnode /* =================== _insert ================== Inserts data pointer into a new node. Pre plist pointer to a valid list

13 ppre pointer to data's predecessor datainptr data pointer to be inserted Post data have been inserted in sequence Return boolean, true if successful, false if memory overflow static bool _insert (LIST* plist, NODE* ppre, void* datainptr) // Local Definitions NODE* pnew; if (!(pnew = (NODE*) malloc(sizeof(node)))) return false; pnew->dataptr pnew->link = datainptr; = NULL; if (ppre == NULL) // Adding before first node or to empty list. pnew->link = plist->head; plist->head = pnew; if (plist->count == 0) // Adding to empty list. Set rear plist->rear = pnew; } // if ppre else // Adding in middle or at end pnew->link = ppre->link; ppre->link = pnew; // Now check for add at end of list if (pnew->link == NULL) plist->rear = pnew; } // if else (plist->count)++; return true; } // _insert /* ================= removenode ================ Removes data from list. Pre plist pointer to a valid list keyptr pointer to key to be deleted dataoutptr pointer to data pointer Post Node deleted or error returned. Return false not found; true deleted bool removenode (LIST* plist, void* keyptr, void** dataoutptr) // Local Definitions bool found;

14 NODE* ppre; NODE* ploc; found = _search (plist, &ppre, &ploc, keyptr); if (found) _delete (plist, ppre, ploc, dataoutptr); return found; } // removenode /* ================= _delete ================ Deletes data from a list and returns pointer to data to calling module. Pre plist pointer to valid list. ppre pointer to predecessor node ploc pointer to target node Post dataoutptr pointer to data pointer Data have been deleted and returned Data memory has been freed void _delete (LIST* plist, NODE* ppre, NODE* ploc, void** dataoutptr) *dataoutptr = ploc->dataptr; if (ppre == NULL) // Deleting first node plist->head = ploc->link; else // Deleting any other node ppre->link = ploc->link; // Test for deleting last node if (ploc->link == NULL) plist->rear = ppre; (plist->count)--; free (ploc); return; } // _delete /* ================== searchlist ================= Interface to search function. Pre plist pointer to initialized list. pargu pointer to key being sought Post pdataout contains pointer to found data -or- NULL if not found Return boolean true successful; false not found bool searchlist (LIST* plist, void* pargu, void** pdataout) // Local Definitions bool found;

15 NODE* ppre; NODE* ploc; found = _search (plist, &ppre, &ploc, pargu); if (found) *pdataout = ploc->dataptr; else *pdataout = NULL; return found; } // searchlist /* ================== _search ================= Searches list and passes back address of node containing target and its logical predecessor. Pre plist pointer to initialized list ppre pointer variable to predecessor ploc pointer variable to receive node pargu pointer to key being sought Post ploc points to first equal/greater key -or- null if target > key of last node ppre points to largest node < key -or- null if target < key of first node Return boolean true found; false not found bool _search (LIST* plist, NODE** ppre, NODE** ploc, void* pargu) // Macro Definition #define COMPARE \ ( ((* plist->compare) (pargu, (*ploc)->dataptr)) ) #define COMPARE_LAST \ ((* plist->compare) (pargu, plist->rear->dataptr)) // Local Definitions int result; *ppre = NULL; *ploc = plist->head; if (plist->count == 0) return false; // Test for argument > last node in list if ( COMPARE_LAST > 0) *ppre = plist->rear; *ploc = NULL; return false; } // if while ( (result = COMPARE) > 0 ) // Have not found search argument location *ppre = *ploc; *ploc = (*ploc)->link;

16 } // while if (result == 0) // argument found--success return true; else return false; } // _search /* ================== retrievenode ================ This algorithm retrieves data in the list without changing the list contents. Pre plist pointer to initialized list. pargu pointer to key to be retrieved Post Data (pointer) passed back to caller Return boolean true success; false underflow static bool retrievenode (LIST* plist, void* pargu, void** dataoutptr) // Local Definitions bool found; NODE* ppre; NODE* ploc; found = _search (plist, &ppre, &ploc, pargu); if (found) *dataoutptr = ploc->dataptr; return true; } // if *dataoutptr = NULL; return false; } // retrievenode /* ================= emptylist ================ Returns boolean indicating whether or not the list is empty Pre plist is a pointer to a valid list Return boolean true empty; false list has data bool emptylist (LIST* plist) return (plist->count == 0); } // emptylist /* ================== fulllist ================= Returns boolean indicating no room for more data. This list is full if memory cannot be allocated for another node. Pre plist pointer to valid list Return boolean true if full false if room for node

17 bool fulllist (LIST* plist) // Local Definitions NODE* temp; if ((temp = (NODE*)malloc(sizeof(*(pList->head))))) free (temp); return false; } // if // Dynamic memory full return true; } // fulllist /* ================== listcount ================== Returns number of nodes in list. Pre plist is a pointer to a valid list Return count for number of nodes in list int listcount(list* plist) return plist->count; } // listcount /* ================== traverse ================= Traverses a list. Each call either starts at the beginning of list or returns the location of the next element in the list. Pre plist pointer to a valid list fromwhere 0 to start at first element dataptrout address of pointer to data Post if more data, address of next node Return true node located; false if end of list bool traverse (LIST* plist, int fromwhere, void** dataptrout) if (plist->count == 0) return false; if (fromwhere == 0) //Start from first node plist->pos = plist->head; *dataptrout = plist->pos->dataptr; return true; } // if fromwhere else // Start from current position

18 if (plist->pos->link == NULL) return false; else plist->pos = plist->pos->link; *dataptrout = plist->pos->dataptr; return true; } // if else } // if fromwhere else } // traverse /* ================== destroylist ================= Deletes all data in list and recycles memory Pre List is a pointer to a valid list. Post All data and head structure deleted Return null head pointer LIST* destroylist (LIST* plist) // Local Definitions NODE* deleteptr; if (plist) while (plist->count > 0) // First delete data free (plist->head->dataptr); // Now delete node deleteptr = plist->head; plist->head = plist->head->link; plist->count--; free (deleteptr); } // while free (plist); } // if return NULL; } // destroylist

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ Answer the following 1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++ 2) Which data structure is needed to convert infix notations to postfix notations? Stack 3) The

More information

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists Lecture 11 Doubly Linked Lists & Array of Linked Lists In this lecture Doubly linked lists Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for a Sparse

More information

10CS35: Data Structures Using C

10CS35: Data Structures Using C CS35: Data Structures Using C QUESTION BANK REVIEW OF STRUCTURES AND POINTERS, INTRODUCTION TO SPECIAL FEATURES OF C OBJECTIVE: Learn : Usage of structures, unions - a conventional tool for handling a

More information

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2) Chapter 7 Data Structures for Computer Graphics (This chapter was written for programmers - option in lecture course) Any computer model of an Object must comprise three different types of entities: 1.

More information

Data Structure with C

Data Structure with C Subject: Data Structure with C Topic : Tree Tree A tree is a set of nodes that either:is empty or has a designated node, called the root, from which hierarchically descend zero or more subtrees, which

More information

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure

Short Notes on Dynamic Memory Allocation, Pointer and Data Structure Short Notes on Dynamic Memory Allocation, Pointer and Data Structure 1 Dynamic Memory Allocation in C/C++ Motivation /* a[100] vs. *b or *c */ Func(int array_size) double k, a[100], *b, *c; b = (double

More information

Stacks. Linear data structures

Stacks. Linear data structures Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations

More information

PES Institute of Technology-BSC QUESTION BANK

PES Institute of Technology-BSC QUESTION BANK PES Institute of Technology-BSC Faculty: Mrs. R.Bharathi CS35: Data Structures Using C QUESTION BANK UNIT I -BASIC CONCEPTS 1. What is an ADT? Briefly explain the categories that classify the functions

More information

Analysis of a Search Algorithm

Analysis of a Search Algorithm CSE 326 Lecture 4: Lists and Stacks 1. Agfgd 2. Dgsdsfd 3. Hdffdsf 4. Sdfgsfdg 5. Tefsdgass We will review: Analysis: Searching a sorted array (from last time) List ADT: Insert, Delete, Find, First, Kth,

More information

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Doubly Linked Lists Traversed in either direction Typical operations Initialize the list Destroy the list Determine if list empty Search list for a given

More information

1 Abstract Data Types Information Hiding

1 Abstract Data Types Information Hiding 1 1 Abstract Data Types Information Hiding 1.1 Data Types Data types are an integral part of every programming language. ANSI-C has int, double and char to name just a few. Programmers are rarely content

More information

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering

BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security. & BSc. (Hons.) Software Engineering BSc (Hons) Business Information Systems, BSc (Hons) Computer Science with Network Security & BSc. (Hons.) Software Engineering Cohort: BIS/05/FT BCNS/05/FT BSE/05/FT Examinations for 2005-2006 / Semester

More information

Common Data Structures

Common Data Structures Data Structures 1 Common Data Structures Arrays (single and multiple dimensional) Linked Lists Stacks Queues Trees Graphs You should already be familiar with arrays, so they will not be discussed. Trees

More information

Lecture 12 Doubly Linked Lists (with Recursion)

Lecture 12 Doubly Linked Lists (with Recursion) Lecture 12 Doubly Linked Lists (with Recursion) In this lecture Introduction to Doubly linked lists What is recursion? Designing a node of a DLL Recursion and Linked Lists o Finding a node in a LL (recursively)

More information

CS 2412 Data Structures. Chapter 2 Stacks and recursion

CS 2412 Data Structures. Chapter 2 Stacks and recursion CS 2412 Data Structures Chapter 2 Stacks and recursion 1 2.1 Stacks A stack is a data structure in which all insertions and deletions of entries are made at one end, called top of the stack. Examples:

More information

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1 Data Structure By Ajay Raiyani Yogidham, Kalawad Road, Rajkot. Ph : 572365, 576681 1 Linked List 4 Singly Linked List...4 Doubly Linked List...7 Explain Doubly Linked list: -...7 Circular Singly Linked

More information

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we learned about the ADT Priority Queue. A

More information

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. 1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D. base address 2. The memory address of fifth element of an array can be calculated

More information

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Data Structures Using C++ 2E. Chapter 5 Linked Lists Data Structures Using C++ 2E Chapter 5 Linked Lists Test #1 Next Thursday During Class Cover through (near?) end of Chapter 5 Objectives Learn about linked lists Become aware of the basic properties of

More information

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Questions 1 through 25 are worth 2 points each. Choose one best answer for each. Questions 1 through 25 are worth 2 points each. Choose one best answer for each. 1. For the singly linked list implementation of the queue, where are the enqueues and dequeues performed? c a. Enqueue in

More information

Linked List as an ADT (cont d.)

Linked List as an ADT (cont d.) Linked List as an ADT (cont d.) Default constructor Initializes list to an empty state Destroy the list Deallocates memory occupied by each node Initialize the list Reinitializes list to an empty state

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning Lecture 17 March 17, 2010 1 Introduction In the previous two lectures we have seen how to exploit the structure

More information

LINKED DATA STRUCTURES

LINKED DATA STRUCTURES LINKED DATA STRUCTURES 1 Linked Lists A linked list is a structure in which objects refer to the same kind of object, and where: the objects, called nodes, are linked in a linear sequence. we keep a reference

More information

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types

Abstract Data Type. EECS 281: Data Structures and Algorithms. The Foundation: Data Structures and Abstract Data Types EECS 281: Data Structures and Algorithms The Foundation: Data Structures and Abstract Data Types Computer science is the science of abstraction. Abstract Data Type Abstraction of a data structure on that

More information

Linked Lists Linked Lists, Queues, and Stacks

Linked Lists Linked Lists, Queues, and Stacks Linked Lists Linked Lists, Queues, and Stacks CSE 10: Introduction to C Programming Fall 200 Dynamic data structure Size is not fixed at compile time Each element of a linked list: holds a value points

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Part 2: Data Structures PD Dr. rer. nat. habil. Ralf-Peter Mundani Computation in Engineering (CiE) Summer Term 2016 Overview general linked lists stacks queues trees 2 2

More information

C Dynamic Data Structures. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell

C Dynamic Data Structures. University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell C Dynamic Data Structures University of Texas at Austin CS310H - Computer Organization Spring 2010 Don Fussell Data Structures A data structure is a particular organization of data in memory. We want to

More information

The C Programming Language course syllabus associate level

The C Programming Language course syllabus associate level TECHNOLOGIES The C Programming Language course syllabus associate level Course description The course fully covers the basics of programming in the C programming language and demonstrates fundamental programming

More information

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

KITES TECHNOLOGY COURSE MODULE (C, C++, DS) KITES TECHNOLOGY 360 Degree Solution www.kitestechnology.com/academy.php [email protected] [email protected] Contact: - 8961334776 9433759247 9830639522.NET JAVA WEB DESIGN PHP SQL, PL/SQL

More information

Lecture Notes on Binary Search Trees

Lecture Notes on Binary Search Trees Lecture Notes on Binary Search Trees 15-122: Principles of Imperative Computation Frank Pfenning André Platzer Lecture 17 October 23, 2014 1 Introduction In this lecture, we will continue considering associative

More information

DATA STRUCTURES USING C

DATA STRUCTURES USING C DATA STRUCTURES USING C QUESTION BANK UNIT I 1. Define data. 2. Define Entity. 3. Define information. 4. Define Array. 5. Define data structure. 6. Give any two applications of data structures. 7. Give

More information

Glossary of Object Oriented Terms

Glossary of Object Oriented Terms Appendix E Glossary of Object Oriented Terms abstract class: A class primarily intended to define an instance, but can not be instantiated without additional methods. abstract data type: An abstraction

More information

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority) Boolean Expressions, Conditions, Loops, and Enumerations Relational Operators == // true if two values are equivalent!= // true if two values are not equivalent < // true if left value is less than the

More information

DATA STRUCTURE - QUEUE

DATA STRUCTURE - QUEUE DATA STRUCTURE - QUEUE http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm Copyright tutorialspoint.com Queue is an abstract data structure, somewhat similar to stack. In contrast to

More information

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and: Binary Search Trees 1 The general binary tree shown in the previous chapter is not terribly useful in practice. The chief use of binary trees is for providing rapid access to data (indexing, if you will)

More information

Data Structures and Algorithms C++ Implementation

Data Structures and Algorithms C++ Implementation BK TP.HCM Ho Chi Minh City University of Technology Faculty of Computer Science and Engineering BK TP.HCM Data Structures and Algorithms C++ Implementation Huỳnh Tấn Đạt Email: [email protected] Home

More information

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer.

Coding Rules. Encoding the type of a function into the name (so-called Hungarian notation) is forbidden - it only confuses the programmer. Coding Rules Section A: Linux kernel style based coding for C programs Coding style for C is based on Linux Kernel coding style. The following excerpts in this section are mostly taken as is from articles

More information

STACKS,QUEUES, AND LINKED LISTS

STACKS,QUEUES, AND LINKED LISTS STACKS,QUEUES, AND LINKED LISTS Stacks Queues Linked Lists Double-Ended Queues Case Study: A Stock Analysis Applet 1 Stacks Astack is a container of objects that are inserted and removed according to the

More information

Node-Based Structures Linked Lists: Implementation

Node-Based Structures Linked Lists: Implementation Linked Lists: Implementation CS 311 Data Structures and Algorithms Lecture Slides Monday, March 30, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected]

More information

Stack Allocation. Run-Time Data Structures. Static Structures

Stack Allocation. Run-Time Data Structures. Static Structures Run-Time Data Structures Stack Allocation Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers,

More information

ADTs,, Arrays, Linked Lists

ADTs,, Arrays, Linked Lists 1 ADTs,, Arrays, Linked Lists Outline and Required Reading: ADTs ( 2.1.2) Arrays ( 1.5) Linked Lists ( 4.3.1, 4.3.2) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Abstract Data Type (ADT) 2 abstract

More information

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Linked Lists, Stacks, Queues, Deques. It s time for a chainge! Linked Lists, Stacks, Queues, Deques It s time for a chainge! Learning Goals After this unit, you should be able to... Differentiate an abstraction from an implementation. Define and give examples of problems

More information

CmpSci 187: Programming with Data Structures Spring 2015

CmpSci 187: Programming with Data Structures Spring 2015 CmpSci 187: Programming with Data Structures Spring 2015 Lecture #12 John Ridgway March 10, 2015 1 Implementations of Queues 1.1 Linked Queues A Linked Queue Implementing a queue with a linked list is

More information

Data Structures and Algorithms Lists

Data Structures and Algorithms Lists Data Structures and Algorithms Lists Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/19 5-0: Abstract Data Types An

More information

Unordered Linked Lists

Unordered Linked Lists Unordered Linked Lists Derive class unorderedlinkedlist from the abstract class linkedlisttype Implement the operations search, insertfirst, insertlast, deletenode See code on page 292 Defines an unordered

More information

Module 2 Stacks and Queues: Abstract Data Types

Module 2 Stacks and Queues: Abstract Data Types Module 2 Stacks and Queues: Abstract Data Types A stack is one of the most important and useful non-primitive linear data structure in computer science. It is an ordered collection of items into which

More information

Lecture 11 Array of Linked Lists

Lecture 11 Array of Linked Lists Lecture 11 Array of Linked Lists In this lecture Array of Linked Lists Creating an Array of Linked Lists Representing a Sparse Matrix Defining a Node for Sparse Matrix Exercises Solutions An Array of Linked

More information

Illustration 1: Diagram of program function and data flow

Illustration 1: Diagram of program function and data flow The contract called for creation of a random access database of plumbing shops within the near perimeter of FIU Engineering school. The database features a rating number from 1-10 to offer a guideline

More information

C++ INTERVIEW QUESTIONS

C++ INTERVIEW QUESTIONS C++ INTERVIEW QUESTIONS http://www.tutorialspoint.com/cplusplus/cpp_interview_questions.htm Copyright tutorialspoint.com Dear readers, these C++ Interview Questions have been designed specially to get

More information

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1

Course: Programming II - Abstract Data Types. The ADT Stack. A stack. The ADT Stack and Recursion Slide Number 1 Definition Course: Programming II - Abstract Data Types The ADT Stack The ADT Stack is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit insertions

More information

Binary Heap Algorithms

Binary Heap Algorithms CS Data Structures and Algorithms Lecture Slides Wednesday, April 5, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected] 2005 2009 Glenn G. Chappell

More information

Sources: On the Web: Slides will be available on:

Sources: On the Web: Slides will be available on: C programming Introduction The basics of algorithms Structure of a C code, compilation step Constant, variable type, variable scope Expression and operators: assignment, arithmetic operators, comparison,

More information

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) -----------------------------------------

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push) ----------------------------------------- =============================================================================================================================== DATA STRUCTURE PSEUDO-CODE EXAMPLES (c) Mubashir N. Mir - www.mubashirnabi.com

More information

7.1 Our Current Model

7.1 Our Current Model Chapter 7 The Stack In this chapter we examine what is arguably the most important abstract data type in computer science, the stack. We will see that the stack ADT and its implementation are very simple.

More information

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap

Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap Algorithms and Data Structures Exercise for the Final Exam (17 June 2014) Stack, Queue, Lists, Trees, Heap Singly linked list (1) Data about exam results are stored into a singly linked list. Each list

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Java Method Dispatch Zoran Budimlić (Rice University) Always remember that you are absolutely unique. Just like everyone else. - Margaret Mead

More information

Unit 1. 5. Write iterative and recursive C functions to find the greatest common divisor of two integers. [6]

Unit 1. 5. Write iterative and recursive C functions to find the greatest common divisor of two integers. [6] Unit 1 1. Write the following statements in C : [4] Print the address of a float variable P. Declare and initialize an array to four characters a,b,c,d. 2. Declare a pointer to a function f which accepts

More information

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation Dynamic Storage Allocation CS 44 Operating Systems Fall 5 Presented By Vibha Prasad Memory Allocation Static Allocation (fixed in size) Sometimes we create data structures that are fixed and don t need

More information

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1 Definition Course: Programming II - Abstract Data Types The ADT Queue The ADT Queue is a linear sequence of an arbitrary number of items, together with access procedures. The access procedures permit addition

More information

DATA STRUCTURE - STACK

DATA STRUCTURE - STACK DATA STRUCTURE - STACK http://www.tutorialspoint.com/data_structures_algorithms/stack_algorithm.htm Copyright tutorialspoint.com A stack is an abstract data type ADT, commonly used in most programming

More information

Introduction to Data Structures

Introduction to Data Structures Introduction to Data Structures Albert Gural October 28, 2011 1 Introduction When trying to convert from an algorithm to the actual code, one important aspect to consider is how to store and manipulate

More information

Universidad Carlos III de Madrid

Universidad Carlos III de Madrid Universidad Carlos III de Madrid Algorithms and Data Structures (ADS) Bachelor in Informatics Engineering Computer Science Department Lists, Stacks and Queues. Authors: Isabel Segura Bedmar April 2011

More information

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic

Queues Outline and Required Reading: Queues ( 4.2 except 4.2.4) COSC 2011, Fall 2003, Section A Instructor: N. Vlajic Queues Outline and Required Reading: Queues ( 4. except 4..4) COSC, Fall 3, Section A Instructor: N. Vlajic Queue ADT Queue linear data structure organized according to first-in/first-out (FIFO) principle!

More information

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C 1 An essential part of any embedded system design Programming 2 Programming in Assembly or HLL Processor and memory-sensitive

More information

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc()

Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc() CS61: Systems Programming and Machine Organization Harvard University, Fall 2009 Lecture 10: Dynamic Memory Allocation 1: Into the jaws of malloc() Prof. Matt Welsh October 6, 2009 Topics for today Dynamic

More information

C++ Programming Language

C++ Programming Language C++ Programming Language Lecturer: Yuri Nefedov 7th and 8th semesters Lectures: 34 hours (7th semester); 32 hours (8th semester). Seminars: 34 hours (7th semester); 32 hours (8th semester). Course abstract

More information

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example Announcements Memory management Assignment 2 posted, due Friday Do two of the three problems Assignment 1 graded see grades on CMS Lecture 7 CS 113 Spring 2008 2 Safe user input If you use scanf(), include

More information

Sequential Data Structures

Sequential Data Structures Sequential Data Structures In this lecture we introduce the basic data structures for storing sequences of objects. These data structures are based on arrays and linked lists, which you met in first year

More information

Data Structures and Data Manipulation

Data Structures and Data Manipulation Data Structures and Data Manipulation What the Specification Says: Explain how static data structures may be used to implement dynamic data structures; Describe algorithms for the insertion, retrieval

More information

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010 Problem 1. In each of the following question, please specify if the statement

More information

EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE)

EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE) EE2204 DATA STRUCTURES AND ALGORITHM (Common to EEE, EIE & ICE) UNIT I LINEAR STRUCTURES Abstract Data Types (ADT) List ADT array-based implementation linked list implementation cursor-based linked lists

More information

Introduction to Data Structures and Algorithms

Introduction to Data Structures and Algorithms Introduction to Data Structures and Algorithms Chapter: Elementary Data Structures(1) Lehrstuhl Informatik 7 (Prof. Dr.-Ing. Reinhard German) Martensstraße 3, 91058 Erlangen Overview on simple data structures

More information

Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor

Data Structures. Level 6 C30151. www.fetac.ie. Module Descriptor The Further Education and Training Awards Council (FETAC) was set up as a statutory body on 11 June 2001 by the Minister for Education and Science. Under the Qualifications (Education & Training) Act,

More information

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes. 1. The advantage of.. is that they solve the problem if sequential storage representation. But disadvantage in that is they are sequential lists. [A] Lists [B] Linked Lists [A] Trees [A] Queues 2. The

More information

Basic Data Structures and Algorithms

Basic Data Structures and Algorithms Tutorial 3 Basic Data Structures and Algorithms THINGS TO LOOK FOR 3.0 INTRODUCTION 3.1 Array Based Containers Definition and uses of containers. Array and list based containers. Designing and building

More information

Programming languages C

Programming languages C INTERNATIONAL STANDARD ISO/IEC 9899:1999 TECHNICAL CORRIGENDUM 2 Published 2004-11-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE

More information

Binary storage of graphs and related data

Binary storage of graphs and related data EÖTVÖS LORÁND UNIVERSITY Faculty of Informatics Department of Algorithms and their Applications Binary storage of graphs and related data BSc thesis Author: Frantisek Csajka full-time student Informatics

More information

Ordered Lists and Binary Trees

Ordered Lists and Binary Trees Data Structures and Algorithms Ordered Lists and Binary Trees Chris Brooks Department of Computer Science University of San Francisco Department of Computer Science University of San Francisco p.1/62 6-0:

More information

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Dr. Martin O. Steinhauser University of Basel Graduate Lecture Spring Semester 2014 Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct Friday, 7 th March

More information

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas CS 110B - Rule Storage Classes Page 18-1 Attributes are distinctive features of a variable. Data type, int or double for example, is an attribute. Storage class is another attribute. There are four storage

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-06 Binary Search Trees David Galles Department of Computer Science University of San Francisco 06-0: Ordered List ADT Operations: Insert an element in the list

More information

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q QUEUES A queue is simply a waiting line that grows by adding elements to its end and shrinks by removing elements from the. Compared to stack, it reflects the more commonly used maxim in real-world, namely,

More information

Binary Search Trees (BST)

Binary Search Trees (BST) Binary Search Trees (BST) 1. Hierarchical data structure with a single reference to node 2. Each node has at most two child nodes (a left and a right child) 3. Nodes are organized by the Binary Search

More information

Tutorial on C Language Programming

Tutorial on C Language Programming Tutorial on C Language Programming Teodor Rus [email protected] The University of Iowa, Department of Computer Science Introduction to System Software p.1/64 Tutorial on C programming C program structure:

More information

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON PROBLEM SOLVING WITH SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON Addison Wesley Boston San Francisco New York London

More information

TREE BASIC TERMINOLOGIES

TREE BASIC TERMINOLOGIES TREE Trees are very flexible, versatile and powerful non-liner data structure that can be used to represent data items possessing hierarchical relationship between the grand father and his children and

More information

Data Structures and Algorithms

Data Structures and Algorithms Data Structures and Algorithms CS245-2016S-05 Abstract Data Types and Lists David Galles Department of Computer Science University of San Francisco 05-0: Abstract Data Types Recall that an Abstract Data

More information

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms. COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms 1 Activation Records activation declaration location Recall that an activation

More information

Sequences in the C++ STL

Sequences in the C++ STL CS 311 Data Structures and Algorithms Lecture Slides Wednesday, November 4, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks [email protected] 2005 2009 Glenn

More information

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s Quiz 4 Solutions Q1: What value does function mystery return when called with a value of 4? int mystery ( int number ) { if ( number

More information

CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions

CS 2112 Spring 2014. 0 Instructions. Assignment 3 Data Structures and Web Filtering. 0.1 Grading. 0.2 Partners. 0.3 Restrictions CS 2112 Spring 2014 Assignment 3 Data Structures and Web Filtering Due: March 4, 2014 11:59 PM Implementing spam blacklists and web filters requires matching candidate domain names and URLs very rapidly

More information

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92.

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) 3 4 4 7 5 9 6 16 7 8 8 4 9 8 10 4 Total 92. Name: Email ID: CSE 326, Data Structures Section: Sample Final Exam Instructions: The exam is closed book, closed notes. Unless otherwise stated, N denotes the number of elements in the data structure

More information

Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1

Stack & Queue. Darshan Institute of Engineering & Technology. Explain Array in detail. Row major matrix No of Columns = m = u2 b2 + 1 Stack & Queue Explain Array in detail One Dimensional Array Simplest data structure that makes use of computed address to locate its elements is the onedimensional array or vector; number of memory locations

More information

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time Skip Lists CMSC 420 Linked Lists Benefits & Drawbacks Benefits: - Easy to insert & delete in O(1) time - Don t need to estimate total memory needed Drawbacks: - Hard to search in less than O(n) time (binary

More information

Java Interview Questions and Answers

Java Interview Questions and Answers 1. What is the most important feature of Java? Java is a platform independent language. 2. What do you mean by platform independence? Platform independence means that we can write and compile the java

More information

Linked Lists: Implementation Sequences in the C++ STL

Linked Lists: Implementation Sequences in the C++ STL Linked Lists: Implementation Sequences in the C++ STL continued CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 1, 2009 Glenn G. Chappell Department of Computer Science University

More information

Chapter 3: Restricted Structures Page 1

Chapter 3: Restricted Structures Page 1 Chapter 3: Restricted Structures Page 1 1 2 3 4 5 6 7 8 9 10 Restricted Structures Chapter 3 Overview Of Restricted Structures The two most commonly used restricted structures are Stack and Queue Both

More information