Linked Lists

You might also like

You are on page 1of 2

Cormen: 10.1-2, 10.1-6, 10.1-7, 10.2-6, 10.2-7, 10.2-8, 10.3-4, 10.3-5, All problems at the end of the chapter.

Cormen: 6.1-*, 6.4-*, 6.5-6 to 6.5-8, 19.2-5, 19.2-7, 19.2-9, All problems at the end of the chapters. From LinkedListProblems.pdf:- 12, 16, 18 1. What is a data structure? 2. What data structure would you mostly likely see in a non recursive implementation of a recursive algorithm? 3. How does one find a loop in a singly linked list in O(n) time using constant memory? You cannot modify the list in any way. 4. Implement an algorithm to insert a node into a circular linked list without traversing it. 5. I give you a singly linked Linked List. Write a function to swap every second node. [i.e. - 12345| becomes 21435|] 6. Split linked list into odd number list and even number list (now consider if it is a circular list). 7. Find the middle of a linked list. Now do it while only going through the list once. (Hint:- same solution as finding cycles) 8. Stack can be described as a pointer. Explain. 9. Delete nth node from the Last of a singly linked list in one traversal. 10. How would you find out if a machine's stack grows up or down in memory? Well, it's fairly simple to write a C program to test this. Obviously I'm assuming that a C compiler is available. The following program creates an integer (a) on the stack, then passes a pointer to a down to the function sub. sub creates another integer on the stack (b), then compares the address of a to the address of b. If b's address is greater than a's, then the stack is growing up, if it's less, then it's growing down.
#include <stdio .h> void sub(int *a) { int b; if (&b > a) { printf("Stack grows up."); } else { printf("Stack grows down."); }

main () {

int a; sub(&a);

That said, perhaps there's an easier way. 11. Imagine you have a string composed of just the chars '{([])} (curly braces, parens, square brackets). Now, assume that you have normal 'mathematical rules', and that sets of parens,braces,brackets have to close in the right order. For instance, (), ()[], 1) are all valid, (], ([)], {{{{ are not. Write a function that will take an input string and return true if the string is valid, false otherwise.

You might also like