• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Data Structures 2007

Data Structures 2007



Lecture Notes on Data Structures by Sanjay Goel, JIIT, July-Dec, 2007

Lecture Notes on Data Structures by Sanjay Goel, JIIT, July-Dec, 2007



Total Views
Views on SlideShare
Embed Views



1 Embed 1

http://www.linkedin.com 1



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Data Structures 2007 Data Structures 2007 Document Transcript

    • Sanjay Goel, JIIT, DS, 2007 Data Structures Lecture and lab AssignmentsPractice assignments will not be evaluated in lab. However, every fortnight there will bea lab test which will be based on practice assignments. The 4 hrs of lab for all batchesare divided as follows:Lab A: first 2 lab hrs of the weekLab B: next 2 lab hrs of the weekThe test will be conducted in Lab A and Lab B on rotational basis. 1. Assignment #1 : (Practice) • Create and traverse linked list (of structure of anything) and write the records content onto a file. Let them then read the file and recreate linked list in same/reverse order. • Practice simple Graphics 2. Assignment #2 : (Lab A: 10 Marks, last date of evaluation 11.08.07) • create a linked list of at least 20 user inputted point (x,y), store it in file, and save it. • Open the file. draw a polyline using these points. • Ask the user to choose any two points for deletion from the point sequence through keyboard based interface • (No mouse programming). update the file. • clear screen and draw a new polyline using these points. • Ask the user to insert four new points between any two chosen points in the sequence through keyboard based interface (No mouse programming). Update the file. • Clear screen and draw a polyline using these points. • Enthusiastic students are encouraged to do mouse programming and delete and insert points through mouse operations. 3. Assignment #3 : (Practice) • WAP a polynomial calculator with keyboard based UI for following functionality for up to 3 variable polynomials: - Add, subtract, multiply, differential, and integrate polynomials. 4. Assignment #4 : (Practice) • WAP a software to automatically test your polynomial calculator using user specified database of test cases. 5. Assignment #5 : (Lab B: 20 Marks last date of evaluation 11.08.07) • WAP to test if a given chemical equation is balanced. Design a clear UI, data structure and testing algorithm. The equation may have up to 5 terms on each side and up to four elements in each molecule. (10 marks) • Also write a program to test it using user specified set of test-cases. (10 marks) 6. Assignment #6 : (Practice) • Propose a keyboard based UI of a possibly new simple application (new = not used by you) in any application domain of your familiarity. 7. Assignment #7 : (Practice) • Propose the functionality design of a new software.
    • Sanjay Goel, JIIT, DS, 2007 8. Assignment #8 : (Practice) • WAP to perform basic set operations and also optionally draw colored Venn diagram. • In a group of three, critically examine the user interface of some popular software systems and write an essay highlighting the problems related to UI in these software systems. 9. Assignment #9: (Lab A: 10 Marks last date of evaluation 25.08.07) • WAP to input (non-graphically), store, edit, and output (graphically) ER diagrams. Neatly design the UI, DS, Logic and Control. 10. Assignment #10 : (Practice) • Identify the Logic and control part of five programs already written by you. See how can you change the algorithm of these programs without changing the logic. Enthusiastic students are encouraged to refer Robert Kowalski’s paper, Algorithm = Logic + Control, Communication of ACM, July 1979. • Practice Recursion 11. Assignment #11 : (Practice) • Understand the history of evolution of product design by doing a self study of any specific technology other than IT and electronic. Identify what factors led to major changes. How much of this was dependent on change of demand? • Design UI, DS, Logic and control for following problems. Assess your design analytically, experimentally as well as through code review. Also see how different data structure and control designs affect the algorithm’s performance without changing the logic. Draw graphs showing the performance of different algorithm wrt increasing data size. • Store polynomial functions and series of numbers. Test if the given series is a Taylor series approximation (at x) for a given polynomial function and x0. Taylor series approx. of a given function is as : While equating real numbers do not use ==, instead, check if abs (n1-n2) is <= e1, where e1 is very small real number and its value depends on application. See how different data structure and control designs effect the algorithm’s performance without changing the logic. • Design a dynamic data structure for storing a randomly ordered collection of single variable polynomial functions and another static data structure
    • Sanjay Goel, JIIT, DS, 2007 for storing randomly-ordered collection of real number-sequences. The records in both the collections also should have additional provision for storing indices of all the matching entries (if any) in another collection. One entry in any collection may match with none, one or many entries in another. A number-sequence is declared as matching with a polynomial, if all the numbers in the sequence match with corresponding terms of the Taylor series expansion of a function for given x and x0 within the limits of a user-defined ‘permitted-mismatch’. Design an algorithm for updating matching indices in both the collections for a given user-defined input of ‘permitted-mismatch’, x and x0. 12. Assignment #12 : (Practice) • Refer Sander’s paper “Using Jackson diagrams to classify and define data structures” (ACM SIGCSE Bulletin Feb 1983) for diagrammatic representation of DS. Represent the data structures of all the assignments of this course using this method. • Using this method draw a DS diagram for storing Book. • Understand and analyze the relation of UI, Algorithm and DS in the context of popular Software. 13. Assignment #13 : (Practice) • Learn about ASCII codes. 14. Assignment #14 : (Lab B: 10 Marks last date of evaluation 28.08.07) • Write a program to create a linked list of 10000 nodes of even numbers in increasing order starting from zero. (0 mark) • Write four versions of programs for printing this linked list in backward order by varying data structure in your program. Understand the relationship of DS with algorithm. Empirically compare the memory requirement and run time efficiency of these programs. (2+2+2+2+2) 15. Assignment #15: (Practice) • Refer: G. M. Galler Algorithms: evaluation of the Legendre polynomial Pn(X) by recursion June 1960 Communications of the ACM, Volume 3 Issue 6 • Practice recursion: o Binomial coefficient o Chebyshev Polynomial o Laguerre Polynomial o Hermite Polynomial o Legendra Polynomial o Bessel Function • Practice multi-way recursion. Fibonacci, Ackerman, and so on. • Create multi-way linked data structure, and populate it with some data to create varied configurations of data. Use various forms of multi-way
    • Sanjay Goel, JIIT, DS, 2007 recursion to display the subset of stored data in this data structure in many different ways on varied configurations of data. Compare the hand simulated results with computer outputs. Practice at least 20-30 cases. • Store 5 variable multi-function truth table using at least four different data structures. Write program to create and use this data. 16. Assignment #16: (Practice) • Refer: • Ivan B. Liss, Thomas C. McMillan, Fractals with turtle graphics: a CS2 programming exercise for introducing recursion, ACM SIGCSE Bulletin , Proceedings of the eighteenth SIGCSE technical symposium on Computer science education SIGCSE 87, Volume 19 Issue 1 , February 1987 • Peter E. Oppenheimer, Real time design and animation of fractal plants and trees, ACM SIGGRAPH Computer Graphics , Proceedings of the 13th annual conference on Computer graphics and interactive techniques SIGGRAPH 86, Volume 20 Issue 4, August 1986 • Aaron Gordon, Teaching recursion using recursively-generated geometric designs, Journal of Computing Sciences in Colleges, Volume 22 Issue 1, October 2006, ACM Digital Library • Practice recursive programs for simple geometric fractals like Koch curve, Sierpinski Triangle, Cantor set and so on. Try different configurations of multi-way recursion call for each of these fractals. Analytically estimate and experimentally verify the effect of changing the order of recursive calls on the order of growth of the graphic pattern. 17. Assignment #17: (Lab A: 10 Marks last date of evaluation 4.09.07) • Write a non recursive program for drawing fractal such as Koch Curve / Sierpienski Triangle/ Cantor Set/ Sierpienski Carpet /Box Fractal/Cantor Square/ Haferman Carpet/Tree or some other fractal that basically uses the logic of multi-way recursion. 18. Assignment #18: (Practice) • WAP for doing Binary search using recursive as well as non recursive techniques. • Write non-recursive programs for drawing more fractals. Generate varied growth patterns using varied control strategies on the same logic. Understand the DS requirements for each case. 19. Assignment#19: (Practice) • The shape of the initial polygon (Level (L) =1) is repeatedly transformed till the perimeter of the resultant polygon becomes more than 1000 times the initial perimeter using 5-segment Koch curve process for each polygon- segment. Design an algorithm to carry out this transformation on the initial polygon and store the vertices of each stage of new polygon in an appropriate Data structure. Propose an algorithm for drawing the polygon for user
    • Sanjay Goel, JIIT, DS, 2007 specified ‘stage/level’ (L= 1, 2, 3…) using this stored data without regenerating the points. 20. Assignment#20: (Lab B: 10 Marks last date of evaluation 20.09.07) • Write a recursive program for checking the feasibility of a Knight to traverse a chessboard to a given destination pt. from a given starting pt. Use of Graphics is welcome but not compulsory. [This is based on rat in the maze] (Check with your lab faculty for the batch specific variation of this problem) 21. Assignment#21: (Practice) • Write a recursive program for solving tower of Hanoi for variable number of discs and poles. • Write recursive programs for array and list processing (print elements, add elements, multiply elements, count the number of elements etc.). 22. Assignment#22: (Practice) • Write a recursive program for searching kth smallest and jth largest element in an unsorted array (Median search). 23. Assignment#23: (Practice) • Write recursive program for multiplying two numbers by addition. • Write a recursive program to count the occurrences of a string in a linked list of strings. • Write a recursive program to take n words and print them in reverse order. • Write a recursive program for drawing line, circle, and spiral. • Review iterative versions of selection, insertion, and bubble sort algorithms and propose recursive logic for these. 24. Assignment#24: (Practice) • Write a recursive program for floodfill (x,y,boundary colour, new colour) • Group of three: Write a recursive program for patternfill (x,y, boundary colour, pattern), where pattern is matrix of colours. [These are based on rat in the maze, divide and conquer]. • Group of three: Write non recursive versions of above mentioned Knight Problem, floodfill, and patternfill problems. 25. Assignment#25: (Practice) • Write a recursive program for interpolation search. • Group of three: Write a program to simulate 2d multi limb virtual toy assemblies. Define your own assemblies. [A case of kinematics - 2d graphic transformations (translation and rotation), recursion and data structures]. • Group of three: Write a program to store sphere/ellipse/ paraboloid /hyperbolid / any other kind of 3d object as a polyhedron.
    • Sanjay Goel, JIIT, DS, 2007 26. Assignment#26: (Practice) • Write recursive programs for descending sorting using the sort strategy of selection, insertion, and bubble sort algorithms. Generate and analyze different implementation approaches at least, two, for each. 27. Assignment#27: (Practice) • Write recursive s for implementing 2-way merge sort, 3-way merge sort, and quick sort algorithms. • Implement Merge sort and Quick sort without recursion. • Evaluate the performance of all your sorting programs with varied configurations of input data. • Update your sorting programs to graphically demonstrate the dynamics of sorting algorithms. (Reference: Algorithms by Robert Sedgewick). • Refer: A system for algorithm animation, Marc H. Brown, Robert Sedgewick, ACM SIGGRAPH Computer Graphics , Proceedings of the 11th annual conference on Computer graphics and interactive techniques SIGGRAPH 84, Vol. 18 Issue 3 • Refer: Implementing Quicksort programs, Robert Sedgewick , Communications of the ACM, Volume 21 Issue 10, October 1978. • Sorting on Electronic Computer Systems, Edward H. Friend, Journal of the ACM (JACM), Volume 3 Issue 3, July 1956 • Refer Brian project gallery for beautiful simulation of many algorithms. http://www.brian-borowski.com 28. Assignment#28: (Lab B: 10 Marks last date of evaluation 13.10.07 ) • One unsorted list of integers having 50,000 elements is given. WAP for displaying the elements ranging between 10,000th smallest element to 11,000th smallest element in ascending order. Estimate the number of comparisons required for performing this task using your approach. 29. Assignment#29: (Lab A: 20 Marks last date of evaluation 17.10.07 ) • A large rectangular floor’s area is tiled with thick triangular tiles with grooves between adjacent tiles as shown in figure below. These grooves are to be used for laying several types of cables and pipes. Maximum of three cables/pipes may pass through any groove. However, more are allowed to pass through groove intersections. (a) Propose a machine readable format for specifying the cabling/piping requirements in terms of end points. (b) Propose an output format for a computer generated textual cabling/piping specifications in terms of the complete paths for each cabling/piping requirement. (c) WAP to process the data as in (a) and generate the output as in (b).
    • Sanjay Goel, JIIT, DS, 2007 30. Assignment#30: (Practice) • Develop formula based logic for accessing elements of compactly stored k dimensional triangular matrices with different storage sequences. Using this compact storage, write programs for matrix multiplication and matrix inversion. 31. Assignment#31: (Practice) • WAP for creating and updating a database about inter-webpage links. The program should answer the frequent query - if webpage x is connected with webpage y without accessing the webpage at query time. Your program should also update the database on every insertion/deletion of webpage and/or hyperlinks. Design different types of DS, and corresponding algorithms. Evaluate the performance difference in terms of memory and processing complexity in different mechanisms. (Based on the concepts of sparse matrix and/or graph). • To access some of original and classical papers on sorting, study various papers presented at ACM sort symposium in 1962. Refer the May, 1963 issue of Communications of ACM. • Refer: Review of Storage Techniques for Sparse Matrices, Shahnaz, Rukhsana Usman, Anila Chughtai, Imran R., 9th International Multitopic Conference, IEEE INMIC 2005 • N. Goharian, A. Jain, Q. Sun, "Comparative Analysis of Sparse Matrix Algorithms for Information Retrieval", Journal of Systemics, Cybernetics and Informatics, 2003. 32. Assignment#32:(Bonus marks for theory = 20, Last date: 10 Nov) • This assignment is only open to those whose assignments are up-to-date and regular. Others should first complete at least 80% assignments (Including practice assignments) and show the same to their concerned faculty. Take the prior approval of your lab faculty to undertake this assignment. All students with odd enroll numbers will consult and will be evaluated by faculty in LAB A. All students with even enroll numbers will consult and will be evaluated faculty in LAB B. • Study at least two of the papers recommended so far or otherwise. Take your lab faculty’s prior approval for confirming the choice of the paper. Prepare small report; summarize the paper, analytically and experimentally validate some of the algorithms presented in these papers. The bonus marks will depend upon the quality of the paper chosen by you and your work. 33. Assignment#33:(Practice) • Understand the relationship and interchangeability between Table, Matrix, and Graph representations of databases. Evaluate the pros and cons of these logical representations. Reflect on the implementation options of underlying
    • Sanjay Goel, JIIT, DS, 2007 data structures for these logical representations. Evaluate the performance of different options in terms of memory usage and processing efficiency. Validate your analysis with the help few real life (real life like) examples. • Transform database tables of your DBMS project into n-dimensional sparse matrices (also called n-dimensional data cubes). Design DS for storing these logical matrices in varied physical implementations based on formula based and linked addressing techniques. Design algorithms and write programs for processing at least 5 of the complex queries (database lookup) and transactions (add, delete, update data) of your DBMS project. Evaluate the performance difference in terms of memory and processing complexity in different mechanisms. (Refer Data Structures by Sartaj Sahani for addressing technique based classification of data structures). Those students who are not studying DBMS can take any kind of simpler database tables and queries and transactions in consultation with their faculty. 34. Assignment#34:(Practice) • Understand what characterizes a good function for formula based direct addressing. Contextually evaluate the merits and demerits for different functions. • Carry out a survey of Hashing functions and collision resolution policies. 35. Assignment#35: (Lab A: 25 Marks last date of evaluation 7.11.07 ) • WAP to transfer the data of a database of large number of records stored as a linked list to a Hash Table, HT1 using bucket hashing. Your program should then transfer the data from HT1 to HT2 using open hashing with linear probing. It should finally transfer the data from HT2 to HT3 using closed hashing (chaining). • Experimentally compare the performance of linked list, HT1, HT2, and HT3 for various data base operations wrt different hash functions. • The record in this assignment represents different kind of objects depending upon your context. Batch wise distribution is as follows: B1 and B2 = B&W Images or sound file B3 and B4 = chemical equations B5 and B6 = 3d Polygons B7 and B8 = Polyhedrons B9 and B10 = Polynomials C1 and C2 = Biochemical cycles. C3 = DNA sequence In all these cases the content itself is used as the key. Do not use file name or object id as the key. Highly motivated and creative students can propose and choose an alternate context on the discretion of your lab faculty. Your context should not be of lesser complexity that the suggested list.
    • Sanjay Goel, JIIT, DS, 2007 36. Assignment#36: (Practice ) • Implement and evaluate a stack with fixed top. Use this stack to check if a word is a palindrome or not. • Use this stack also to check if any given C program has syntactical errors of the type of mismatching brackets i.e. {and}. 37. Assignment#37: (Lab B: 15 Marks last date of evaluation 10.11.07 ) • Write programs to generate 6 different types of tri-nary tree traversal sequences using stacks, queues, double ended queues, or a combination of these or other types of buffers. The tri-nary tree is to be implemented using linked storage. (Practice ) • Write non-recursive version of pre-order, post-order, and in-order traversal of binary tree traversal. • Write non-recursive version of Rat in the maze. Understand and experimentally evaluate the functional difference in using stack vs queue to solve this problem. • Implement binary and 3-ary tree in an array using formulae based addressing. Analytically and experimentally compare array based binary tree’s performance with linked storage version wrt addition, deletion, in-order traversal, pre-order traversal post-order traversal, and level order traversal operations. 38. Assignment#38: (Practice) • Write program using linked list based stack to 1. Test if the data sequence of a linked list makes a palindrome or not. 2. Evaluate postfix expressions. 3. Convert Infix expression to postfix expressions. 39. Assignment#39: (Practice) • Transform Quick-sort algorithm into a non-recursive algorithm. 40. Assignment#40: (Practice) • WAP to implement in-order, post-order, pre-order, and level-order traversals using single buffer. Analyze the similarity and differences in these algorithms. • Write three programs for k-way tree traversal using 3 different configuration of multi stage buffering. • WAP to convert postfix, infix, and prefix expressions to binary expression trees. 41. Assignment#41: (Practice) • Extend your recursive as well non-recursive tree traversal programs to transform each one of them into graph traversal programs. • WAP to sort an array in descending order using 4-ary tree based heap sort.
    • Sanjay Goel, JIIT, DS, 2007 42. Assignment#42: (Practice) • WAP to radix sort an array of names. • WAP to simulate to simulate petrol pump customer movement.